Modifier and Type | Field and Description |
---|---|
static Fn<Object,Integer> |
hashCode
Yields the
hashCode for objects, or 0 if null . |
static Predicate<Object> |
isNull
Yields
true for null values. |
static Predicate<Object> |
notNull
Yields
true for all non-null values. |
static Fn<Object,String> |
toString
Yields the
string representation of
any object. |
Modifier and Type | Method and Description |
---|---|
static <E,I extends Iterable<E>> |
all(Predicate<? super E> predicate)
Evaluate if all elements satisfies a predicate, i.e.
|
static ConjunctionPremise |
allOf(Fn0<Boolean>... premises)
Compose an AND-expression of several
Fn0<Boolean>s . |
static <T> Conjunction<T> |
allOf(Predicate<? super T>... predicates)
Compose an AND-expression of several predicates.
|
static <T> Predicate<T> |
always(boolean bool)
Create a predicate which always yields the given
boolean value. |
static <I1,I2,V> Constant<I1,I2,V> |
always(V value)
Create a function which always yields the given value.
|
static <I1,I2,O> Throw<I1,I2,O> |
alwaysThrow(Exception ex)
Create a function which always throw the given exception.
|
static DisjunctionPremise |
anyOf(Fn0<Boolean>... premises)
Compose an OR-expression of several
Fn0<Boolean>s . |
static <T> Disjunction<T> |
anyOf(Predicate<? super T>... predicates)
Compose an OR-expression of several predicates.
|
static <T> Disjunction<T> |
anyOf(T... objects)
Shorthand for
anyOf( equalTo(o1), equalTo(o2), ..., equalTo(on)) |
static ConjunctionPremise |
both(Fn0<Boolean> premise)
Create a AND-expression of several
Fn0<Boolean>s , starting with the one
given to this method. |
static <T> Conjunction<T> |
both(Predicate<T> predicate)
Create a AND-expression of several predicates, starting with the one
given to this method.
|
static <T> Predicate<T> |
containedIn(Iterable<? extends T> iterable)
Evaluates if objects are contained in the given
Iterable . |
static DisjunctionPremise |
either(Fn0<Boolean> premise)
Create a OR-expression of several
Fn0<Boolean>s ,
starting with the one given to this method. |
static <T> Disjunction<T> |
either(Predicate<T> predicate)
Create a OR-expression of several predicates, starting with the one
given to this method.
|
static <T> Disjunction<T> |
either(T o)
Shorthand for
either( equalTo(o)) . |
static <T extends Comparable<? super T>> |
equalOrGreaterThan(T value)
Predicate evaluating if values are equal to or greater than a given value.
|
static <T extends Comparable<? super T>> |
equalOrLessThan(T value)
Predicate evaluating if values are equal to or less than a given value.
|
static <T> Predicate<T> |
equalTo(Fn0<? super T> value)
Equality predicate, checks if values are equal to the value computed from the given
Fn0 . |
static <T> Predicate<T> |
equalTo(T value)
Equality predicate, checks if values are equal to the given value.
|
static <E,I extends Iterable<E>> |
exists(E element)
Shorthand for
exists( equalTo(element)) |
static <E,I extends Iterable<E>> |
exists(Predicate<? super E> element)
Evaluate if an element exists, i.e.
|
static <T,E> Fn<T,Elements<E>> |
extract(Fn<? super T,? extends E>... extractors)
A function to extract/derive several values from one object.
|
static <V> DoChain<V> |
first(Do<V> action)
Chain several
Do s to be executed in sequence. |
static <I,O> FnChain<I,O> |
first(Fn<I,O> fn)
Compose a chain of several functions into one
Fn , where the result of
each function is passed to its successor, and the last will yield the
actual result of the chain. |
static <I1,I2,O> Fn2Chain<I1,I2,O,O> |
first(Fn2<I1,I2,O> fn2)
Compose a chain of several functions into one
Fn2 , where the result of
each function is passed to its successor, and the last will yield the
actual result of the chain. |
static RunnableChain |
first(Runnable runnable)
Compose several
Runnable s as a single Runnable which will
execute the given Runnables in sequence. |
static <T extends Comparable<? super T>> |
greaterThan(T value)
Predicate evaluating if values are greater than a given value.
|
static <T> Predicate<T> |
is(T value)
A synonym for
equalTo(Object) . |
static <T extends Comparable<? super T>> |
lessThan(T value)
Predicate evaluating if values are less than a given value.
|
static <T> Predicate<T> |
not(Predicate<T> p)
Negates a predicate.
|
static <T> Predicate<T> |
not(T o)
Shorthand for
not( equalTo(o)) . |
static <I,O> When<I,O> |
when(Predicate<? super I> condition,
Fn<? super I,? extends O> fn)
|
static <T,P> Predicate<T> |
where(Fn<T,P> fn,
Predicate<? super P> predicate)
Compose a predicate from taking the result of a function and apply it to
another predicate.
|
public static final Fn<Object,String> toString
string representation
of
any object.public static <T> Predicate<T> not(T o)
not(
equalTo(o))
.not(Predicate)
,
equalTo(Object)
public static <T> Predicate<T> not(Predicate<T> p)
p
- The predicate to negate.public static <T,P> Predicate<T> where(Fn<T,P> fn, Predicate<? super P> predicate)
fn(T) ∈ P p(P) ∈ {true, false} ƒ(T) = p(fn(T)) ∈ {true, false}
This simple composition enables one to focus on writing functions
for your particular domain, and reusing basic predicates provided by Motif.
P
- The type of the predicate evaluating the function result.T
- The type of the resulting predicate.fn
- The function which result will be evaluated by the predicate. Takes
an argument of T
predicate
- Evaluates the result from the function, i.e. a value of P
T
public static <T> Conjunction<T> both(Predicate<T> predicate)
predicate
- The first predicate.and(anotherPredicate)
method.Conjunction
,
allOf(Predicate...)
public static ConjunctionPremise both(Fn0<Boolean> premise)
Fn0<Boolean>s
, starting with the one
given to this method.premise
- The first Fn0<Boolean>
.Fn0<Boolean>
which may be used to build up an AND-expression by
chaining the and(anotherPremise)
method.ConjunctionPremise
@SafeVarargs public static <T> Conjunction<T> allOf(Predicate<? super T>... predicates)
predicates
- the predicates.Conjunction
@SafeVarargs public static ConjunctionPremise allOf(Fn0<Boolean>... premises)
Fn0<Boolean>s
.premises
- the Fn0<Boolean>s
.Fn0<Boolean>
which is the conjunction
(AND) of the given premises.ConjunctionPremise
public static <T> Disjunction<T> either(T o)
either(
equalTo(o))
.either(Predicate)
,
Disjunction
public static <T> Disjunction<T> either(Predicate<T> predicate)
predicate
- The first predicate.or(anotherPredicate)
method.Disjunction
,
anyOf(Predicate...)
public static DisjunctionPremise either(Fn0<Boolean> premise)
Fn0<Boolean>s
,
starting with the one given to this method.premise
- The first Fn0<Boolean>
.Fn0<Boolean>
which may be used to build up an OR-expression by
chaining the or(anotherPremise)
method.DisjunctionPremise
@SafeVarargs public static <T> Disjunction<T> anyOf(T... objects)
anyOf(
equalTo(o1), equalTo(o2), ..., equalTo(on))
objects
- the candidate objects for equivalence check.Disjunction
@SafeVarargs public static <T> Disjunction<T> anyOf(Predicate<? super T>... predicates)
predicates
- the predicates.Disjunction
@SafeVarargs public static DisjunctionPremise anyOf(Fn0<Boolean>... premises)
Fn0<Boolean>s
.premises
- the Fn0<Boolean>s
.Fn0<Boolean>s
which is the disjunction (OR) of the given premises.DisjunctionPremise
public static <E,I extends Iterable<E>> Predicate<I> all(Predicate<? super E> predicate)
predicate
- The predicate which will evaluate all elements.true
if all elements evaluates
to true by the given predicate, false if any evaluates to false
.public static <E,I extends Iterable<E>> Predicate<I> exists(E element)
exists(
equalTo(element))
element
- The element to look for in an Iterable
.true
if an element equal to the given
element is found, false
otherwise.public static <E,I extends Iterable<E>> Predicate<I> exists(Predicate<? super E> element)
element
- The existance-deciding predicate.true
if any element evaluates
to true by the given predicate, false
otherwise.public static <T> Predicate<T> is(T value)
equalTo(Object)
.public static <T> Predicate<T> equalTo(T value)
value
- the value the predicate should check for equality against.public static <T> Predicate<T> equalTo(Fn0<? super T> value)
Fn0
.value
- the Fn0
which will compute the value to check for equality against on each
application of the predicate.public static <T extends Comparable<? super T>> Predicate<T> lessThan(T value)
value
- the right operand, i.e. the predicate will evaluate
if values are less than this value.public static <T extends Comparable<? super T>> Predicate<T> equalOrLessThan(T value)
value
- the right operand, i.e. the predicate will evaluate
if values are equal to or less than this value.public static <T extends Comparable<? super T>> Predicate<T> greaterThan(T value)
value
- the right operand, i.e. the predicate will evaluate
if values are greater than this value.public static <T extends Comparable<? super T>> Predicate<T> equalOrGreaterThan(T value)
value
- the right operand, i.e. the predicate will evaluate
if values are equal to or greater than this value.@SafeVarargs public static <T,E> Fn<T,Elements<E>> extract(Fn<? super T,? extends E>... extractors)
Elements
s container of the least common supertype of
the extractor Fn
s' return types.extractors
- the Fn
s which will extract values from each object passed
to the function.public static <I,O> When<I,O> when(Predicate<? super I> condition, Fn<? super I,? extends O> fn)
Fn
using a Predicate
to evaluate if the
argument should be passed to the wrapped Fn
. The function created
by this method is essentially this ternary expression:
condition(v) ? f(v) : null;To fall back to another value than
null
, call either .orElse(Fn)
or .orElse(other)
on the returned object.public static final <I,O> FnChain<I,O> first(Fn<I,O> fn)
Fn
, where the result of
each function is passed to its successor, and the last will yield the
actual result of the chain. Use .then(Fn)
to append
functions to the chain.
Note: The chain does no internal inspection of the intermediate
results passed to the next function, which means that any function which may
return null
, must have a null
-safe successor
function.
fn
- The first function in the chain.public static final <I1,I2,O> Fn2Chain<I1,I2,O,O> first(Fn2<I1,I2,O> fn2)
Fn2
, where the result of
each function is passed to its successor, and the last will yield the
actual result of the chain. Use .then(Fn)
to append
functions to the chain.
Note: The chain does no inspection of the intermediate
results passed to the next function, which means that any function which may
return null
, must have a null
-safe successor
function.
fn2
- The first function in the chain.public static final RunnableChain first(Runnable runnable)
Runnable
s as a single Runnable which will
execute the given Runnables in sequence.runnable
- The first Runnable.public static <V> DoChain<V> first(Do<V> action)
Do
s to be executed in sequence.action
- The first Do
to execute.Do
as the first Do
in a sequence.public static <I1,I2,V> Constant<I1,I2,V> always(V value)
value
- The value to yield.public static <T> Predicate<T> always(boolean bool)
boolean
value.bool
- The boolean
value to yield.public static <I1,I2,O> Throw<I1,I2,O> alwaysThrow(Exception ex)
RuntimeException
it will be wrapped as such.ex
- The exception to throw.Copyright © 2016. All Rights Reserved.