Skip to content

Commit ed70f6b

Browse files
authored
Finite Automata refactor (eugenp#1445)
1 parent 3accbf8 commit ed70f6b

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

algorithms/src/main/java/com/baeldung/automata/RtState.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public RtState(final boolean isFinal) {
2121
}
2222

2323
public State transit(final CharSequence c) {
24-
for(final Transition t : this.transitions) {
25-
if(t.isPossible(c)) {
26-
return t.state();
27-
}
28-
}
29-
throw new IllegalArgumentException("Input not accepted: " + c);
24+
return transitions
25+
.stream()
26+
.filter(t -> t.isPossible(c))
27+
.map(Transition::state)
28+
.findAny()
29+
.orElseThrow(() -> new IllegalArgumentException("Input not accepted: " + c));
3030
}
3131

3232
public boolean isFinal() {

0 commit comments

Comments
 (0)