Created
July 18, 2014 21:25
-
-
Save okram/45ee50518ebc97d00426 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IfThenElseStep<S, E> extends FlatMapStep<S, E> { | |
public final SPredicate<S> ifPredicate; | |
public final Traversal<S, E> thenTraversal; | |
public final Traversal<S, E> elseTraversal; | |
public IfThenElseStep(final Traversal traversal, final SPredicate<S> ifPredicate, final Traversal<S, E> thenTraversal, final Traversal<S, E> elseTraversal) { | |
super(traversal); | |
this.ifPredicate = ifPredicate; | |
this.thenTraversal = thenTraversal; | |
this.elseTraversal = elseTraversal; | |
this.setFunction(traverser -> { | |
if (this.ifPredicate.test(traverser.get())) { | |
this.thenTraversal.addStarts(new SingleIterator<>(traverser)); | |
return this.thenTraversal; | |
} else { | |
this.elseTraversal.addStarts(new SingleIterator<>(traverser)); | |
return this.elseTraversal; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment