Package epam.flipflop

Class FlipFlopPredicate<T>

java.lang.Object
epam.flipflop.FlipFlopPredicate<T>
Type Parameters:
T - The type of the input to the predicate
All Implemented Interfaces:
Predicate<T>

public class FlipFlopPredicate<T> extends Object implements Predicate<T>
A predicate that emulates flip-flop logic similar to the two-dots flip-flop in Perl or Ruby. The predicate takes two input predicates, a start condition, and an end condition. When the start condition is met, the predicate returns true for all subsequent inputs until the end condition is met, at which point it returns true and resets its internal state.
  • Constructor Details

    • FlipFlopPredicate

      public FlipFlopPredicate(Predicate<T> startCondition, Predicate<T> endCondition)
      Constructs a new FlipFlopPredicate with the given start and end conditions.
      Parameters:
      startCondition - The predicate that represents the start condition
      endCondition - The predicate that represents the end condition
  • Method Details

    • test

      public boolean test(T value)
      Evaluates this predicate on the given argument.
      Specified by:
      test in interface Predicate<T>
      Parameters:
      value - The input argument
      Returns:
      true if the input matches the flip-flop logic, otherwise false