public class F extends Object
Flow
to
which operations
and transformations
(in terms of Predicate
s, Mapper
s and Reducer
s) to create new Flows. Flows
are initially
created
using flow(Collection)
and flow(Object...)
.
F will be used a bit, thus it has a short name (for those who don't like static imports). It provides a base set of
Predicate, Mapper and Reducer factories. A good development pattern for applications is to provide a similar,
application-specific, set of such factories.Modifier and Type | Field and Description |
---|---|
static Mapper2<Integer,Integer,Integer> |
ADD_INTS
A two-input Mapper used to add the values from two Flows of Integers into a Flow of Integer
sums.
|
static Predicate<String> |
IS_BLANK
Predicate that returns true if the provided string is blank (null or all whitespace).
|
static Reducer<Integer,Integer> |
SUM_INTS
A Reducer that operates on a Flow of Integers and is used to sum the values.
|
Constructor and Description |
---|
F() |
Modifier and Type | Method and Description |
---|---|
static <T> Worker<T> |
addToCollection(Collection<T> coll)
A Worker factory; the returnedWorker adds the values to a provided collection.
|
static <S,T> Mapper<S,T> |
always(T fixedResult)
A Mapper factory; the returned Mapper ignores its input value and always returns a
predetermined result.
|
static <T> Predicate<T> |
and(Predicate<? super T>... delegates)
Combines any number of delegates as a logical and operation.
|
static <A,B,C> Mapper<A,C> |
combine(Mapper<A,B> abMapper,
Mapper<B,C> bcMapper)
Combines two mappers into a composite mapping from type A to type C via type B.
|
static <T> Worker<T> |
combine(Worker<? super T>... delegates)
Combines several compatible workers together into a composite.
|
static Predicate<String> |
endsWith(String suffix)
A Predicate factory for matching String elements with a given suffix.
|
static Predicate<String> |
endsWithIgnoringCase(String suffix)
As with
endsWith(String) but ignores case. |
static <T extends Comparable<T>> |
eq(T value)
A Predicate factory for comparison of a Comparable element from a flow against a fixed value.
|
static <T> Predicate<T> |
eql(T value)
A Predicate factory for equality of an element from a flow against a specified
value.
|
static <T> Flow<T> |
flow(Collection<T> values)
Extracts the values from the collection to form a
Flow . |
static <T> Flow<T> |
flow(Iterable<T> iterable)
Creates a lazy Flow from the
Iterator obtained from the iterable. |
static <T> Flow<T> |
flow(Iterator<T> iterator)
Creates a lazy Flow from the
Iterator . |
static <T> Flow<T> |
flow(T... values)
Creates a new Flow from the values.
|
static <T extends Comparable<T>> |
gt(T value)
A Predicate factory for comparison of a Comparable against a fixed value; true
if the flow element is greater than the provided value.
|
static <T extends Comparable<T>> |
gteq(T value)
A Predicate factory for comparison of a Comparable against a fixed value; true
if the flow element is greater than or equal to the value.
|
static <S> Mapper<S,S> |
identity()
A Mapper factory; the Mapper returns the the flow value unchanged.
|
static <T> Predicate<T> |
isNull()
A Predicate factory; returns true if the value from the Flow is null.
|
static <T> Flow<T> |
iterate(T initial,
Mapper<T,T> function)
Creates an infinite lazy flow from an initial value and a function to map from the current value to the
next value.
|
static <T> Flow<T> |
lazy(LazyFunction<T> function)
Creates a
Flow from a lazy function. |
static <T extends Comparable<T>> |
lt(T value)
A Predicate factory for comparison of a Comparable against a fixed value; true
if the element is less than the value.
|
static <T extends Comparable<T>> |
lteq(T value)
A Predicate factory for comparison of a Comprable element against a fixed value; true
if the element is less than or equal to the value.
|
static <T extends Comparable<T>> |
neq(T value)
A Predicate factory for comparison of a Comparable element against a fixed value.
|
static <T> Predicate<T> |
not(Predicate<? super T> delegate)
Inverts a predicate.
|
static <T> Predicate<T> |
notNull()
A Predicate factory; returns true if the value from the Flow is not null.
|
static <T> Predicate<T> |
or(Predicate<? super T>... delegates)
Combines any number of delegates as a logical or operation.
|
static <A extends Comparable<A>,B> |
orderByFirst()
Creates a Comparator for the Tuples of a
ZippedFlow that sorts the Tuple elements based on the first
value in the Tuple. |
static <A,B extends Comparable<B>> |
orderBySecond()
Creates a Comparator for the Tuples of a
ZippedFlow that sorts the Tuple elements based on the first
value in the Tuple. |
static Flow<Integer> |
range(int lower,
int upper)
Creates a lazy Flow that returns integers in the given range.
|
static <S,T> Mapper<S,T> |
select(Predicate<? super S> predicate,
Mapper<S,T> ifAccepted)
Override of
select(Predicate, Mapper, Mapper) where rejected values are replaced
with null. |
static <S,T> Mapper<S,T> |
select(Predicate<? super S> predicate,
Mapper<S,T> ifAccepted,
Mapper<S,T> ifRejected)
A Mapper factory that combines a Predicate with two
Mapper s; evaluating the predicate
selects one of the two mappers. |
static <S,T> Mapper<S,T> |
select(Predicate<? super S> predicate,
Mapper<S,T> ifAccepted,
T ifRejectedValue)
Override of
select(Predicate, Mapper) where rejected values are replaced with a
fixed value. |
static Flow<Integer> |
series(int start,
int delta)
Creates an infinite series of numbers.
|
static Predicate<String> |
startsWith(String prefix)
A Predicate factory for matching String elements with a given prefix.
|
static Predicate<String> |
startsWithIgnoringCase(String prefix)
As
startsWith(String) , but ignores case. |
static <T> Mapper<T,String> |
stringValueOf()
A Mapper factory that gets the string value of the flow value using
String.valueOf(Object) . |
static <S> Predicate<S> |
toPredicate(Mapper<S,Boolean> mapper)
Allows a Mapper that maps to boolean to be used as a Predicate.
|
static <A,B> ZippedFlow<A,B> |
zippedFlow(Map<A,B> map)
Creates a ZippedFlow from the provided map; the order of the tuples in the ZippedFlow is defined
by the iteration order of the map entries.
|
public static Predicate<String> IS_BLANK
public static Reducer<Integer,Integer> SUM_INTS
public F()
public static <T> Predicate<T> eql(T value)
public static <T extends Comparable<T>> Predicate<T> eq(T value)
public static <T extends Comparable<T>> Predicate<T> neq(T value)
public static <T extends Comparable<T>> Predicate<T> gt(T value)
public static <T extends Comparable<T>> Predicate<T> gteq(T value)
public static <T extends Comparable<T>> Predicate<T> lt(T value)
public static <T extends Comparable<T>> Predicate<T> lteq(T value)
public static <T> Predicate<T> isNull()
public static <T> Predicate<T> notNull()
public static <T> Mapper<T,String> stringValueOf()
String.valueOf(Object)
.public static <S,T> Mapper<S,T> always(T fixedResult)
public static <S,T> Mapper<S,T> select(Predicate<? super S> predicate, Mapper<S,T> ifAccepted, Mapper<S,T> ifRejected)
Mapper
s; evaluating the predicate
selects one of the two mappers.predicate
- evaluated to selected a coercionifAccepted
- used when predicate evaluates to trueifRejected
- used when predicate evaluates to falsepublic static <S,T> Mapper<S,T> select(Predicate<? super S> predicate, Mapper<S,T> ifAccepted)
select(Predicate, Mapper, Mapper)
where rejected values are replaced
with null.public static <S,T> Mapper<S,T> select(Predicate<? super S> predicate, Mapper<S,T> ifAccepted, T ifRejectedValue)
select(Predicate, Mapper)
where rejected values are replaced with a
fixed value.public static <S> Mapper<S,S> identity()
public static <S> Predicate<S> toPredicate(Mapper<S,Boolean> mapper)
public static <T> Flow<T> flow(Collection<T> values)
Flow
. The Collection
may change after the Flow is created without affecting the Flow.public static <T> Flow<T> flow(T... values)
public static <T> Flow<T> flow(Iterable<T> iterable)
Iterator
obtained from the iterable. The Flow
will be threadsafe as long as the iterable yields a new Iterator on each invocation and the underlying
iterable object is not modified while the Flow is evaluating.
In other words, not extremely threadsafe.public static <T> Flow<T> flow(Iterator<T> iterator)
Iterator
. The Flow will be threadsafe as long as the underlying iterable
object is not modified while the Flow is evaluating. In other words, not extremely threadsafe.public static <A,B> ZippedFlow<A,B> zippedFlow(Map<A,B> map)
A
- type of key and first tuple valueB
- type of value and second tuple valuemap
- source of tuplespublic static Flow<Integer> range(int lower, int upper)
lower
- start of range (inclusive)upper
- end of range (exclusive)public static <T> Flow<T> lazy(LazyFunction<T> function)
Flow
from a lazy function.public static <T> Flow<T> iterate(T initial, Mapper<T,T> function)
initial
- initial value in flowfunction
- maps from current value in flow to next value in flowpublic static Flow<Integer> series(int start, int delta)
public static <T> Worker<T> addToCollection(Collection<T> coll)
public static Predicate<String> startsWith(String prefix)
public static Predicate<String> startsWithIgnoringCase(String prefix)
startsWith(String)
, but ignores case.public static Predicate<String> endsWith(String suffix)
public static Predicate<String> endsWithIgnoringCase(String suffix)
endsWith(String)
but ignores case.public static <A extends Comparable<A>,B> Comparator<Tuple<A,B>> orderByFirst()
ZippedFlow
that sorts the Tuple elements based on the first
value in the Tuple.public static <A,B extends Comparable<B>> Comparator<Tuple<A,B>> orderBySecond()
ZippedFlow
that sorts the Tuple elements based on the first
value in the Tuple.public static <T> Predicate<T> not(Predicate<? super T> delegate)
delegate
- the predicate to invertpublic static <A,B,C> Mapper<A,C> combine(Mapper<A,B> abMapper, Mapper<B,C> bcMapper)
abMapper
- maps from A to BbcMapper
- maps from B to Cpublic static <T> Predicate<T> and(Predicate<? super T>... delegates)
delegates
- to evaluatepublic static <T> Predicate<T> or(Predicate<? super T>... delegates)
delegates
- to evaluate${project.version} - Copyright © 2003-2015 The Apache Software Foundation.