|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.myjavatools.lib.foundation.Function<T,java.lang.Boolean>
com.myjavatools.lib.foundation.Filter<T>
public abstract class Filter<T>
Filter is a Function that returns Boolean values; boolean accept() is an alias for Function.apply(). A good example of Filter is java.io.FileFilter, unfortunately not derived from Filter. To implement this class you should define accept().
Function
,
Iterator
Constructor Summary | |
---|---|
Filter()
|
Method Summary | ||
---|---|---|
abstract boolean |
accept(T x)
checks whether an object is accepted by the filter |
|
static
|
and(Filter<T>... filters)
Creates conjunction of filters. |
|
java.lang.Boolean |
apply(T x)
Filter.apply() is the same as accept(); |
|
java.lang.Iterable<T> |
filter(java.lang.Iterable<T> iterable)
filters an Iterable |
|
java.util.Iterator<T> |
filter(java.util.Iterator<T> source)
Returns filtered iterator |
|
static
|
not(Filter<T> filter)
Creates negation of a filter. |
|
static
|
or(Filter<T>... filters)
Creates disjunction of filters. |
|
static
|
toFilter(Function<T,java.lang.Double> f)
creates a filter that accepts only x such that f(x) > 0 |
Methods inherited from class com.myjavatools.lib.foundation.Function |
---|
apply, apply, apply, compose, compose, forMap, forMap, function, function, id, toMap, toMap |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Filter()
Method Detail |
---|
public abstract boolean accept(T x)
x
- T an element to check for acceptance
public java.lang.Boolean apply(T x)
apply
in class Function<T,java.lang.Boolean>
x
- T an element to which this filter is applied
public static <T> Filter<T> toFilter(Function<T,java.lang.Double> f)
f
- Function<T,Double>
public java.util.Iterator<T> filter(java.util.Iterator<T> source)
source
- Iterator original iterator
Example:
new Filter<String>() { boolean accept(String s) { return s.startsWith("M"); }}.
filter(Arrays.asList(new String[] {"New", "Magic", "Logic"}).iterator());
returns an iterator returning just "Magic".public java.lang.Iterable<T> filter(java.lang.Iterable<T> iterable)
iterable
- Iterable
public static <T> Filter<T> and(Filter<T>... filters)
filters
- (vararg)
public static <T> Filter<T> or(Filter<T>... filters)
public static <T> Filter<T> not(Filter<T> filter)
filter
- Filter
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |