Skip to content

Commit

Permalink
fixing bug :issue #7 Values given by iterator have duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
mifmif committed Jul 4, 2015
1 parent f17db80 commit 718e377
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/main/java/com/mifmif/common/regex/GenerexIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import dk.brics.automaton.State;

/**
* An implementation of {@code Iterator} class that iterate over the list of
* Strings that matches a given Regex.
* An implementation of {@code Iterator} class that iterate over the list of Strings that matches a given Regex.
*
* @author y.mifrah
*
Expand All @@ -44,21 +43,33 @@ public boolean hasNext() {
return !transitionsPath.isEmpty();
}

private boolean ignoreLastChar = false;

public String next() {
while (!transitionsPath.isEmpty()) {
TransitionLevel currentLevel = transitionsPath.peek();
State state = currentLevel.getState();
if (!state.isAccept()) {
addNextTransitionLevel(currentLevel);
ignoreLastChar = true;
continue;
} else {
currentValue = "";
for (int i = 0; i < transitionsPath.size() - 1; ++i) {
TransitionLevel transitionLevel = transitionsPath.get(i);
currentValue += transitionLevel.getCurrentChar();
}
jumpToNextPath();
break;
currentValue = "";
for (int i = 0; i < transitionsPath.size()-1; ++i) {
TransitionLevel transitionLevel = transitionsPath.get(i);
currentValue += transitionLevel.getCurrentChar();
}
TransitionLevel transitionLevel = transitionsPath.lastElement();
char nextChar = transitionLevel.getCurrentChar();
if (nextChar != 0) {
if (ignoreLastChar) {
ignoreLastChar = false;
} else {
currentValue += nextChar;
}
}
jumpToNextPath();
break;
}
}
return currentValue;
Expand Down

0 comments on commit 718e377

Please sign in to comment.