Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2014 y.mifrah Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package com.mifmif.common.regex;
An implementation of Iterator class that iterate over the list of Strings that matches a given Regex.

Author(s):
y.mifrah
public class GenerexIterator implements Iterator {
	public GenerexIterator(State initialState) {
		TransitionLevel initialLevel = new TransitionLevel(initialState);
		.add(initialLevel);
	}
	public boolean hasNext() {
	}
	public String next() {
		while (!.isEmpty()) {
			TransitionLevel currentLevel = .peek();
			State state = currentLevel.getState();
			if (!state.isAccept()) {
				addNextTransitionLevel(currentLevel);
				continue;
else {
    			 = "";
    			for (int i = 0; i < .size() - 1; ++i) {
    				TransitionLevel transitionLevel = .get(i);
    				 += transitionLevel.getCurrentChar();
    			}
    			jumpToNextPath();
    			break;
			}
		}
		return ;
	}
	private void jumpToNextPath() {
		while (!.isEmpty()) {
			TransitionLevel currentLevel = .peek();
			if (currentLevel.hasNextTransitionLevel()) {
				TransitionLevel nextTransitionLevel = currentLevel.nextTransitionLevel();
				.push(nextTransitionLevel);
				break;
			}
			if (currentLevel.hasCharacterTransition()) {
				char currChar = currentLevel.getCurrentChar();
				if (currChar < currentLevel.getMaxCharInCurrentTransition()) {
					++currChar;
					currentLevel.setCurrentChar(currChar);
					break;
				}
			}
			if (currentLevel.jumpToNextTransition()) {
				break;
else {
			}
		}
	}
	private void addNextTransitionLevel(TransitionLevel currentLevel) {
		State nextState = currentLevel.getCurrentTransition().getDest();
		TransitionLevel nextLevel = new TransitionLevel(nextState);
		.add(nextLevel);
	}
New to GrepCode? Check out our FAQ X