Class PredicatedConsumer<T>
java.lang.Object
com.norconex.commons.lang.function.PredicatedConsumer<T>
- Type Parameters:
T- type being predicated and consumed
- All Implemented Interfaces:
Consumer<T>
A Consumer that only gets triggered if a given predicate is
true.
A null predicate evaluates to true (before
applying negation if "negate" is true).
A null consumer is simply ignored.
Setting the "negate" constructor argument to true will
perform the same predicate evaluation, but will only trigger the
"then" consumer if the predicate returns false.
- Since:
- 2.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionPredicatedConsumer(Predicate<T> predicate, Consumer<T> consumer) Deprecated.PredicatedConsumer(Predicate<T> predicate, Consumer<T> consumer, boolean negate) Deprecated.Since 3.0.0, useifTrue(Predicate, Consumer, Consumer)instead.PredicatedConsumer(Predicate<T> predicate, Consumer<T> thenConsumer, Consumer<T> elseConsumer, boolean negate) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidprotected booleanbooleanDeprecated.UsegetThenConsumer()instead.inthashCode()static <T> PredicatedConsumer<T> If condition isfalse, then execute consumer.static <T> PredicatedConsumer<T> If condition isfalse, then execute the "then" consumer, else, execute the "else" consumer.static <T> PredicatedConsumer<T> If condition istrue, then execute consumer.static <T> PredicatedConsumer<T> If condition istrue, then execute the "then" consumer, else,execute the "else" consumer.booleanisNegate()toString()
-
Constructor Details
-
PredicatedConsumer
Deprecated.Since 3.0.0, useifTrue(Predicate, Consumer)instead.Constructor.- Parameters:
predicate- predicateconsumer- consumer
-
PredicatedConsumer
@Deprecated(since="3.0.0") public PredicatedConsumer(Predicate<T> predicate, Consumer<T> consumer, boolean negate) Deprecated.Since 3.0.0, useifTrue(Predicate, Consumer, Consumer)instead.Constructor.- Parameters:
predicate- predicateconsumer- consumernegate- whether to negate the condition
-
PredicatedConsumer
public PredicatedConsumer(Predicate<T> predicate, Consumer<T> thenConsumer, Consumer<T> elseConsumer, boolean negate) Constructor.- Parameters:
predicate- predicate conditionthenConsumer- consumer invoked when condition istrueelseConsumer- consumer invoked when condition isfalsenegate- whether to negate the condition
-
-
Method Details
-
getPredicate
-
getConsumer
Deprecated.UsegetThenConsumer()instead.Gets the "then" consumer.- Returns:
- consumer
-
accept
-
ifTrue
If condition istrue, then execute consumer.- Type Parameters:
T- type of object consumed- Parameters:
condition- the condition deciding whether to consumethenConsumer- the object consumer- Returns:
- a predicated consumer
- Since:
- 3.0.0
-
ifTrue
public static <T> PredicatedConsumer<T> ifTrue(Predicate<T> condition, Consumer<T> thenConsumer, Consumer<T> elseConsumer) If condition istrue, then execute the "then" consumer, else,execute the "else" consumer.- Type Parameters:
T- type of object consumed- Parameters:
condition- the condition deciding which consumer to usethenConsumer- the object consumer when condition istrueelseConsumer- the object consumer when condition isfalse- Returns:
- a predicated consumer
- Since:
- 3.0.0
-
ifFalse
If condition isfalse, then execute consumer.- Type Parameters:
T- type of object consumed- Parameters:
condition- the condition deciding whether to consumethenConsumer- the object consumer- Returns:
- a predicated consumer
- Since:
- 3.0.0
-
ifFalse
public static <T> PredicatedConsumer<T> ifFalse(Predicate<T> condition, Consumer<T> thenConsumer, Consumer<T> elseConsumer) If condition isfalse, then execute the "then" consumer, else, execute the "else" consumer.- Type Parameters:
T- type of object consumed- Parameters:
condition- the condition deciding which consumer to usethenConsumer- the object consumer when condition istrueelseConsumer- the object consumer when condition isfalse- Returns:
- a predicated consumer
- Since:
- 3.0.0
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-
getThenConsumer
-
getElseConsumer
-
isNegate
public boolean isNegate()
-
ifTrue(Predicate, Consumer)instead.