org.jjoost.util
Class Filters

java.lang.Object
  extended by org.jjoost.util.Filters

public class Filters
extends java.lang.Object

A class providing methods acting on filters, and default filter implementations

Author:
b.elliottsmith

Constructor Summary
Filters()
           
 
Method Summary
static
<E> AcceptAll<E>
acceptAll()
          Return a filter that accepts everything (i.e.
static
<E> AcceptNone<E>
acceptNone()
          Return a filter that accepts nothing (i.e.
static
<E,F extends Filter<? super E> & FilterPartialOrder<E>>
BothFilter<E>
and(F... filters)
          Returns the conjunction (i.e.
static
<E,F extends Filter<? super E> & FilterPartialOrder<E>>
BothFilter<E>
and(F a, F b)
          Returns the conjunction (i.e.
static
<E> Filter<E>
and(Filter<? super E>... filters)
          Returns the conjunction (i.e.
static
<E> Filter<E>
and(Filter<? super E> a, Filter<? super E> b)
          Returns the conjunction (i.e.
static
<E> FilterPartialOrder<E>
and(FilterPartialOrder<E>... filters)
          Returns the conjunction (i.e.
static
<E> FilterPartialOrder<E>
and(FilterPartialOrder<E> a, FilterPartialOrder<E> b)
          Returns the conjunction (i.e.
static
<E,F extends Filter<? super E> & FilterPartialOrder<E>>
BothFilter<E>
and(java.lang.Iterable<? extends F> filters)
          Returns the conjunction (i.e.
static
<E> FilterPartialOrder<E>
and(java.lang.Iterable<? extends FilterPartialOrder<E>> filters)
          Returns the conjunction (i.e.
static
<E> Filter<E>
and(java.lang.Iterable<Filter<? super E>> filters)
          Returns the conjunction (i.e.
static
<E> FilteredClosableIterator<E>
apply(ClosableIterator<E> iter, Filter<? super E> filter)
          Returns a ClosableIterator wrapping the one provided and lazily filtering its contents by the provided filter
static
<E> java.util.List<E>
apply(java.util.Collection<E> coll, Filter<? super E> filter)
          Returns a new ArrayList representing the items from the provided Collection that when passed to the provided filter's accept() method, returned true.
static
<E> FilteredClosableIterator<E>
apply(Filter<? super E> filter, ClosableIterator<E> iter)
          Returns an ClosableIterator wrapping the one provided and lazily filtering its contents by the provided filter.
static
<E> java.util.List<E>
apply(Filter<? super E> filter, java.util.Collection<E> coll)
          Returns a new ArrayList representing the items from the provided Collection that when passed to the provided filter's accept() method, returned true.
static
<E> FilteredIterable<E>
apply(Filter<? super E> filter, java.lang.Iterable<E> iter)
          Returns an Iterable whose iterator() method will yield a lazily filtered Iterator wrapping the one returned by the Iterable provided to this method, filtered by the provided filter.
static
<E> FilteredIterator<E>
apply(Filter<? super E> filter, java.util.Iterator<E> iter)
          Returns an Iterator wrapping the one provided and lazily filtering its contents by the provided filter.
static
<E> FilteredIterable<E>
apply(java.lang.Iterable<E> iter, Filter<? super E> filter)
          Returns an Iterable whose iterator() method will yield a lazily filtered Iterator wrapping the one returned by the Iterable provided to this method, filtered by the provided filter.
static
<E> FilteredIterator<E>
apply(java.util.Iterator<E> iter, Filter<? super E> filter)
          Returns an Iterator wrapping the one provided and lazily filtering its contents by the provided filter.
static
<E> FilterPartialOrder<E>
forceComparator(FilterPartialOrder<E> filter, java.util.Comparator<? super E> cmp)
          Returns a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead.
static
<S,T> FilterPartialOrder<T>
forceComparator(FilterPartialOrder<S> filter, java.util.Comparator<? super S> cmp, Function<? super T,? extends S> f)
          Returns a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead.
static
<E> FilterPartialOrder<E>
isBetween(E lb, boolean lbIsInclusive, E ub, boolean ubIsInclusive)
          Returns a filter that accepts everything between the provided lower and upper bounds, as determined by the Comparator provided to its methods.
static
<E extends java.lang.Comparable<? super E>>
BothFilter<E>
isBetween(E lb, boolean lbIsInclusive, E ub, boolean ubIsInclusive)
          Returns a filter that accepts everything between the provided lower and upper bounds, as determined by the Comparator provided to its methods.
static
<E> FilterPartialOrder<E>
isBetween(E lb, E ub)
          Returns a partial order filter that accepts everything greater than or equal to the provided lower bound (first argument) and everything strictly less than the provided upper bound (second argument), as determined by the Comparator provided to its methods by utilising classes.
static
<E extends java.lang.Comparable<? super E>>
BothFilter<E>
isBetween(E lb, E ub)
          Returns a filter that accepts everything greater than or equal to the provided lower bound (first argument) and everything strictly less than the provided upper bound (second argument), as determined by the Comparator provided to its methods by utilising classes.
static
<E> BothFilter<E>
isEqualTo(E val)
          Returns a filter accepting only values equal to the one provided, using default object equality.
static
<E> BothFilter<E>
isEqualTo(E val, Equality<? super E> equality)
          Returns a filter accepting only values equal to the one provided, using the provided equality.
static
<E> FilterPartialOrder<E>
isGreater(E val)
          Returns a partial order filter that accepts everything greater than the provided value as determined by the Comparator provided to its methods by utilising classes
static
<E extends java.lang.Comparable<? super E>>
BothFilter<E>
isGreater(E val)
          Returns a partial order filter that accepts everything greater than the provided value as determined by the Comparator provided to its methods by utilising classes.
static
<E> FilterPartialOrder<E>
isGreaterEq(E val)
          Returns a partial order filter that accepts everything greater than or equal to the provided value, as determined by the Comparator provided to its methods by utilising classes
static
<E extends java.lang.Comparable<? super E>>
BothFilter<E>
isGreaterEq(E val)
          Returns a partial order filter that accepts everything greater than or equal to the provided value as determined by the Comparator provided to its methods by utilising classes.
static
<E> FilterPartialOrder<E>
isLess(E val)
          Returns a partial order filter that accepts everything less than the provided value as determined by the Comparator provided to its methods by utilising classes
static
<E extends java.lang.Comparable<? super E>>
BothFilter<E>
isLess(E val)
          Returns a partial order filter that accepts everything less than the provided value as determined by the Comparator provided to its methods by utilising classes.
static
<E> FilterPartialOrder<E>
isLessEq(E val)
          Returns a partial order filter that accepts everything less than or equal to the provided value, as determined by the Comparator provided to its methods by utilising classes
static
<E extends java.lang.Comparable<? super E>>
BothFilter<E>
isLessEq(E val)
          Returns a partial order filter that accepts everything less than or equal to the provided value as determined by the Comparator provided to its methods by utilising classes.
static
<E> Filter<E>
isMemberOf(AnySet<E> set)
          Returns a filter accepting values that are members of the provided set
static
<E> Filter<E>
isMemberOf(java.lang.Iterable<E> set)
          Returns a filter accepting values that occur in the provided Iterable.
static
<E> Filter<E>
isNull()
          Returns a filter accepting only values that are null
static
<X,Y> MappedFilter<X,Y>
mapped(Function<X,Y> mapping, Filter<Y> filter)
          Returns a filter that applies the provided function to its input before delegating to the provided filter
static Filter<java.lang.String> matches(java.util.regex.Pattern pattern)
          Returns a filter accepting strings that match the provided pattern
static Filter<java.lang.String> matches(java.lang.String pattern)
          Returns a filter accepting strings that match the supplied pattern
static
<E,F extends Filter<? super E> & FilterPartialOrder<E>>
BothFilter<E>
not(F filter)
          Returns the negation of the supplied filter implementing both Filter and PartialOrder.
static
<E> Filter<E>
not(Filter<E> filter)
          Returns the negation of the supplied filter
static
<E> FilterPartialOrder<E>
not(FilterPartialOrder<E> filter)
          Returns the negation of the supplied partial order filter.
static
<E> Filter<E>
notNull()
          Returns a filter accepting everything that is not null *
static
<E,F extends Filter<? super E> & FilterPartialOrder<E>>
BothFilter<E>
or(F... filters)
          Returns the disjunction (i.e.
static
<E,F extends Filter<? super E> & FilterPartialOrder<E>>
BothFilter<E>
or(F a, F b)
          Returns the disjunction (i.e.
static
<E> Filter<E>
or(Filter<? super E>... filters)
          Returns the disjunction (i.e.
static
<E> Filter<E>
or(Filter<? super E> a, Filter<? super E> b)
          Returns the disjunction (i.e.
static
<E> FilterPartialOrder<E>
or(FilterPartialOrder<E>... filters)
          Returns the disjunction (i.e.
static
<E> FilterPartialOrder<E>
or(FilterPartialOrder<E> a, FilterPartialOrder<E> b)
          Returns the disjunction (i.e.
static
<E,F extends Filter<? super E> & FilterPartialOrder<E>>
BothFilter<E>
or(java.lang.Iterable<? extends F> filters)
          Returns the disjunction (i.e.
static
<E> Filter<E>
or(java.lang.Iterable<? extends Filter<? super E>> filters)
          Returns the disjunction (i.e.
static
<E> FilterPartialOrder<E>
or(java.lang.Iterable<? extends FilterPartialOrder<E>> filters)
          Returns the disjunction (i.e.
static
<V> int
remove(Filter<? super V> removeMatches, int removeAtMost, java.util.Iterator<V> iter)
          Visits the elements in the provided Iterator, executing remove() on any that match the provided filter (i.e.
static
<V> java.util.Iterator<V>
removeAndReturn(Filter<? super V> removeMatches, int removeAtMost, java.util.Iterator<V> iter)
          Returns a new Iterator which visits the first removeAtMost items from the provided Iterator matching the provided Filter, removing them from the provided Filter as they are visited.
static
<V> V
removeAndReturnFirst(Filter<? super V> removeMatches, int removeAtMost, java.util.Iterator<V> iter)
          Visits the elements in the provided Iterator, executing remove() on any that match the provided filter (i.e.
static
<E> Filter<E>
unique()
          Returns a Filter which returns true if and only if it has never seen the value being tested before, using regular object equality.
static
<E> Filter<E>
unique(Equality<? super E> eq)
          Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided equality.
static
<E> Filter<E>
unique(Set<E> set)
          Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided set to maintain all visited values, and hence the set's definition of equality.
static
<E> FilterPartialOrder<E>
uniqueAsc()
          Returns a partial order filter which will accept a value only if it has never previously seen a value greater than or equal to the value being tested; in an ordered set this results in unique values being efficiently obtained if applied in an ascending order visit of some kind; it is a one shot filter, however, given the state stored.
static
<E> FilterPartialOrder<E>
uniqueDesc()
          Returns a partial order filter which will accept a value only if it has never previously seen a value less than or equal to the value being tested; in an ordered set this results in unique values being efficiently obtained if applied in an descending order visit of some kind; it is a one shot filter, however, given the state stored.
static
<E> Filter<E>
uniqueSeq()
          Returns a Filter which returns true if and only if the previously tested value is not equal to the value being tested, using regular object equality.
static
<E> Filter<E>
uniqueSeq(Equality<? super E> eq)
          Returns a Filter which returns true if and only if the previously tested value is not equal to the value being tested, using the provided definition of equality.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Filters

public Filters()
Method Detail

acceptAll

public static <E> AcceptAll<E> acceptAll()
Return a filter that accepts everything (i.e. returns true for all input)

Returns:
a filter that accepts everything (i.e. returns true for all input)

acceptNone

public static <E> AcceptNone<E> acceptNone()
Return a filter that accepts nothing (i.e. returns false for all input)

Returns:
a filter that accepts nothing (i.e. returns false for all input)

not

public static <E> Filter<E> not(Filter<E> filter)
Returns the negation of the supplied filter

Parameters:
filter - filter to negate
Returns:
negation of the supplied filter

not

public static <E> FilterPartialOrder<E> not(FilterPartialOrder<E> filter)
Returns the negation of the supplied partial order filter. Users should be aware that filters that do not accurately implement mayAcceptBetween may break on negation.

Parameters:
filter - filter to negate
Returns:
negation of the supplied partial order filter

not

public static <E,F extends Filter<? super E> & FilterPartialOrder<E>> BothFilter<E> not(F filter)
Returns the negation of the supplied filter implementing both Filter and PartialOrder. Users should be aware that filters that do not accurately implement mayAcceptBetween may break on negation.

Parameters:
filter - filter to negate
Returns:
negation of the supplied filter implementing both Filter and PartialOrder

and

public static <E> Filter<E> and(Filter<? super E> a,
                                Filter<? super E> b)
Returns the conjunction (i.e. "and") of the supplied filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
a - filter to apply first
b - filter to apply second
Returns:
conjunction (i.e. "and") of a and b

and

public static <E> Filter<E> and(Filter<? super E>... filters)
Returns the conjunction (i.e. "and") of the supplied filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
conjunction (i.e. "and") of provided filters

and

public static <E> Filter<E> and(java.lang.Iterable<Filter<? super E>> filters)
Returns the conjunction (i.e. "and") of the supplied filters. The filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
conjunction (i.e. "and") of provided filters

and

public static <E> FilterPartialOrder<E> and(FilterPartialOrder<E> a,
                                            FilterPartialOrder<E> b)
Returns the conjunction (i.e. "and") of the supplied partial order filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
a - filter to apply first
b - filter to apply second
Returns:
conjunction (i.e. "and") of a and b

and

public static <E> FilterPartialOrder<E> and(FilterPartialOrder<E>... filters)
Returns the conjunction (i.e. "and") of the supplied partial order filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
conjunction (i.e. "and") of provided filters

and

public static <E> FilterPartialOrder<E> and(java.lang.Iterable<? extends FilterPartialOrder<E>> filters)
Returns the conjunction (i.e. "and") of the supplied partial order filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
conjunction (i.e. "and") of provided filters

and

public static <E,F extends Filter<? super E> & FilterPartialOrder<E>> BothFilter<E> and(F a,
                                                                                       F b)
Returns the conjunction (i.e. "and") of the supplied filters implementing both Filter and FilterPartialOrder; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
a - filter to apply first
b - filter to apply second
Returns:
conjunction (i.e. "and") of a and b

and

public static <E,F extends Filter<? super E> & FilterPartialOrder<E>> BothFilter<E> and(F... filters)
Returns the conjunction (i.e. "and") of the supplied filters implementing both Filter and FilterPartialOrder; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
conjunction (i.e. "and") of provided filters

and

public static <E,F extends Filter<? super E> & FilterPartialOrder<E>> BothFilter<E> and(java.lang.Iterable<? extends F> filters)
Returns the conjunction (i.e. "and") of the supplied filters implementing both Filter and FilterPartialOrder; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
conjunction (i.e. "and") of provided filters

or

public static <E> Filter<E> or(Filter<? super E> a,
                               Filter<? super E> b)
Returns the disjunction (i.e. "or") of the supplied filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
a - filter to apply first
b - filter to apply second
Returns:
disjunction (i.e. "or") of a and b

or

public static <E> Filter<E> or(Filter<? super E>... filters)
Returns the disjunction (i.e. "or") of the supplied filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
disjunction (i.e. "or") of provided filters

or

public static <E> Filter<E> or(java.lang.Iterable<? extends Filter<? super E>> filters)
Returns the disjunction (i.e. "or") of the supplied filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
disjunction (i.e. "or") of provided filters

or

public static <E> FilterPartialOrder<E> or(FilterPartialOrder<E> a,
                                           FilterPartialOrder<E> b)
Returns the disjunction (i.e. "or") of the supplied partial order filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
a - filter to apply first
b - filter to apply second
Returns:
disjunction (i.e. "or") of a and b

or

public static <E> FilterPartialOrder<E> or(FilterPartialOrder<E>... filters)
Returns the disjunction (i.e. "or") of the supplied partial order filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
disjunction (i.e. "or") of provided filters

or

public static <E> FilterPartialOrder<E> or(java.lang.Iterable<? extends FilterPartialOrder<E>> filters)
Returns the disjunction (i.e. "or") of the supplied partial order filters; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
disjunction (i.e. "or") of provided filters

or

public static <E,F extends Filter<? super E> & FilterPartialOrder<E>> BothFilter<E> or(F a,
                                                                                      F b)
Returns the disjunction (i.e. "or") of the supplied filters that implement Filter and FilterPartialOrder; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
a - filter to apply first
b - filter to apply second
Returns:
disjunction (i.e. "or") of a and b

or

public static <E,F extends Filter<? super E> & FilterPartialOrder<E>> BothFilter<E> or(F... filters)
Returns the disjunction (i.e. "or") of the supplied filters that implement Filter and FilterPartialOrder; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
disjunction (i.e. "or") of provided filters

or

public static <E,F extends Filter<? super E> & FilterPartialOrder<E>> BothFilter<E> or(java.lang.Iterable<? extends F> filters)
Returns the disjunction (i.e. "or") of the supplied filters that implement Filter and FilterPartialOrder; filters are evaluated in the order they are provided (left-to-right) and are evaluated if and only if previous filters passed

Parameters:
filters - filters to apply
Returns:
disjunction (i.e. "or") of provided filters

isEqualTo

public static <E> BothFilter<E> isEqualTo(E val)
Returns a filter accepting only values equal to the one provided, using default object equality. The filter implements both Filter and FilterPartialOrder.

Parameters:
val - value to accept
Returns:
a filter accepting only values equal to the one provided, using default object equality.

isEqualTo

public static <E> BothFilter<E> isEqualTo(E val,
                                          Equality<? super E> equality)
Returns a filter accepting only values equal to the one provided, using the provided equality. The filter implements both Filter and FilterPartialOrder.

Parameters:
val - value to accept
Returns:
a filter accepting only values equal to the one provided, using the provided equality

isLess

public static <E> FilterPartialOrder<E> isLess(E val)
Returns a partial order filter that accepts everything less than the provided value as determined by the Comparator provided to its methods by utilising classes

Parameters:
val - exclusive upper limit of acceptable values
Returns:
a partial order filter that accepts everything less than the provided value

isLess

public static <E extends java.lang.Comparable<? super E>> BothFilter<E> isLess(E val)
Returns a partial order filter that accepts everything less than the provided value as determined by the Comparator provided to its methods by utilising classes.

Returns an object implementing both Filter and FilterPartialOrder; the Filter accept()method delegates to the object's compareTo() method, whereas the FilterPartialOrder methods utilise the provided comparators

Parameters:
val - exclusive upper limit of acceptable values
Returns:
a filter that accepts everything less than the provided value

isLessEq

public static <E> FilterPartialOrder<E> isLessEq(E val)
Returns a partial order filter that accepts everything less than or equal to the provided value, as determined by the Comparator provided to its methods by utilising classes

Parameters:
val - inclusive upper limit of acceptable values
Returns:
a partial order filter that accepts everything less than or equal to the provided value

isLessEq

public static <E extends java.lang.Comparable<? super E>> BothFilter<E> isLessEq(E val)
Returns a partial order filter that accepts everything less than or equal to the provided value as determined by the Comparator provided to its methods by utilising classes.

Returns an object implementing both Filter and FilterPartialOrder; the Filter accept()method delegates to the object's compareTo() method, whereas the FilterPartialOrder methods utilise the provided comparators

Parameters:
val - exclusive upper limit of acceptable values
Returns:
a filter that accepts everything less than or equal to the provided value

isGreater

public static <E> FilterPartialOrder<E> isGreater(E val)
Returns a partial order filter that accepts everything greater than the provided value as determined by the Comparator provided to its methods by utilising classes

Parameters:
val - exclusive lower limit of acceptable values
Returns:
a partial order filter that accepts everything greater than the provided value

isGreater

public static <E extends java.lang.Comparable<? super E>> BothFilter<E> isGreater(E val)
Returns a partial order filter that accepts everything greater than the provided value as determined by the Comparator provided to its methods by utilising classes.

Returns an object implementing both Filter and FilterPartialOrder; the Filter accept()method delegates to the object's compareTo() method, whereas the FilterPartialOrder methods utilise the provided comparators

Parameters:
val - exclusive lower limit of acceptable values
Returns:
a filter that accepts everything greater than the provided value

isGreaterEq

public static <E> FilterPartialOrder<E> isGreaterEq(E val)
Returns a partial order filter that accepts everything greater than or equal to the provided value, as determined by the Comparator provided to its methods by utilising classes

Parameters:
val - inclusive lower limit of acceptable values
Returns:
a partial order filter that accepts everything greater than or equal to the provided value

isGreaterEq

public static <E extends java.lang.Comparable<? super E>> BothFilter<E> isGreaterEq(E val)
Returns a partial order filter that accepts everything greater than or equal to the provided value as determined by the Comparator provided to its methods by utilising classes.

Returns an object implementing both Filter and FilterPartialOrder; the Filter accept()method delegates to the object's compareTo() method, whereas the FilterPartialOrder methods utilise the provided comparators

Parameters:
val - inclusive lower limit of acceptable values
Returns:
a filter that accepts everything greater than or equal to the provided value

isBetween

public static <E> FilterPartialOrder<E> isBetween(E lb,
                                                  E ub)
Returns a partial order filter that accepts everything greater than or equal to the provided lower bound (first argument) and everything strictly less than the provided upper bound (second argument), as determined by the Comparator provided to its methods by utilising classes.

Parameters:
lb - inclusive lower limit of acceptable values
ub - exclusive upper limit of acceptable values
Returns:
a filter that accepts everything in the range [lb...ub)

isBetween

public static <E> FilterPartialOrder<E> isBetween(E lb,
                                                  boolean lbIsInclusive,
                                                  E ub,
                                                  boolean ubIsInclusive)
Returns a filter that accepts everything between the provided lower and upper bounds, as determined by the Comparator provided to its methods. Each bound can be specified as inclusive or exclusive

Parameters:
lb - lower limit of acceptable values
lbIsInclusive - true if lb should be inclusive, false if exclusive
ub - exclusive upper limit of acceptable values
ubIsInclusive - true if ub should be inclusive, false if exclusive
Returns:
a filter that accepts everything in the range [lb...ub)

isBetween

public static <E extends java.lang.Comparable<? super E>> BothFilter<E> isBetween(E lb,
                                                                                  E ub)
Returns a filter that accepts everything greater than or equal to the provided lower bound (first argument) and everything strictly less than the provided upper bound (second argument), as determined by the Comparator provided to its methods by utilising classes.

Returns an object implementing both Filter and FilterPartialOrder; the Filter accept()method delegates to the object's compareTo() method, whereas the FilterPartialOrder methods utilise the provided comparators

Parameters:
lb - inclusive lower limit of acceptable values
ub - exclusive upper limit of acceptable values
Returns:
a filter that accepts everything in the range [lb...ub)

isBetween

public static <E extends java.lang.Comparable<? super E>> BothFilter<E> isBetween(E lb,
                                                                                  boolean lbIsInclusive,
                                                                                  E ub,
                                                                                  boolean ubIsInclusive)
Returns a filter that accepts everything between the provided lower and upper bounds, as determined by the Comparator provided to its methods. Each bound can be specified as inclusive or exclusive

Returns an object implementing both Filter and FilterPartialOrder; the Filter accept()method delegates to the object's compareTo() method, whereas the FilterPartialOrder methods utilise the provided comparators

Parameters:
lb - lower limit of acceptable values
lbIsInclusive - true if lb should be inclusive, false if exclusive
ub - exclusive upper limit of acceptable values
ubIsInclusive - true if ub should be inclusive, false if exclusive
Returns:
a filter that accepts everything in the range [lb...ub)

forceComparator

public static <E> FilterPartialOrder<E> forceComparator(FilterPartialOrder<E> filter,
                                                        java.util.Comparator<? super E> cmp)
Returns a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead. That is, this forces the comparator used by the provided filter to always be the one provided here.

Parameters:
filter - the partial order filter to wrap
cmp - the comparator to pass to its accepts() methods, overriding the one provided by utilising classes
Returns:
a FilterPartialOrder which always uses the provided comparator

forceComparator

public static <S,T> FilterPartialOrder<T> forceComparator(FilterPartialOrder<S> filter,
                                                          java.util.Comparator<? super S> cmp,
                                                          Function<? super T,? extends S> f)
Returns a FilterPartialOrder which delegates to the provided filter, but ignores the comparator provided to it, always using the one provided here instead. That is, this forces the comparator used by the provided filter to always be the one provided here. It also transforms the type of the FilterPartialOrder by accepting a method from a new type to the type accepted by the provided filter, thereby providing a filter over the domain type of the function. The function should be stable with regards to the comparator, i.e. a < b <==> f.f(a) < f.f(b)

Parameters:
filter - the partial order filter to wrap
cmp - the comparator to pass to its accepts() methods, overriding the one provided by utilising classes
f - a function whose range is the input type of the provided filter, and whose domain will be the input type of the filter returned
Returns:
a FilterPartialOrder which always uses the provided comparator

uniqueSeq

public static final <E> Filter<E> uniqueSeq()
Returns a Filter which returns true if and only if the previously tested value is not equal to the value being tested, using regular object equality.

Returns:
a filter rejecting any values equal to their predecessor

uniqueSeq

public static final <E> Filter<E> uniqueSeq(Equality<? super E> eq)
Returns a Filter which returns true if and only if the previously tested value is not equal to the value being tested, using the provided definition of equality.

Returns:
a filter rejecting any values equal to their predecessor

unique

public static final <E> Filter<E> unique()
Returns a Filter which returns true if and only if it has never seen the value being tested before, using regular object equality. It maintains a set of all visited values and therefore can be expensive with respect to memory utilisation.

Returns:
a filter accepting only unique values

unique

public static final <E> Filter<E> unique(Equality<? super E> eq)
Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided equality. It maintains a set of all visited values and therefore can be expensive with respect to memory utilisation.

Parameters:
eq - the equality determining uniqueness
Returns:
a filter accepting only unique values

unique

public static final <E> Filter<E> unique(Set<E> set)
Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided set to maintain all visited values, and hence the set's definition of equality. This can be expensive with respect to memory utilisation.

Parameters:
set - the set to store visited values in
Returns:
a filter accepting only unique values

uniqueAsc

public static final <E> FilterPartialOrder<E> uniqueAsc()
Returns a partial order filter which will accept a value only if it has never previously seen a value greater than or equal to the value being tested; in an ordered set this results in unique values being efficiently obtained if applied in an ascending order visit of some kind; it is a one shot filter, however, given the state stored.

Returns:
a filter accepting a unique sequence if applied in ascending order

uniqueDesc

public static final <E> FilterPartialOrder<E> uniqueDesc()
Returns a partial order filter which will accept a value only if it has never previously seen a value less than or equal to the value being tested; in an ordered set this results in unique values being efficiently obtained if applied in an descending order visit of some kind; it is a one shot filter, however, given the state stored.

Returns:
a filter accepting a unique sequence if applied in descending order

notNull

public static <E> Filter<E> notNull()
Returns a filter accepting everything that is not null *

Returns:
a filter accepting everything that is not null

isNull

public static <E> Filter<E> isNull()
Returns a filter accepting only values that are null

Returns:
a filter accepting only values that are null

mapped

public static <X,Y> MappedFilter<X,Y> mapped(Function<X,Y> mapping,
                                             Filter<Y> filter)
Returns a filter that applies the provided function to its input before delegating to the provided filter

Parameters:
mapping - the function to transform the input variables
filter - the delegate filter
Returns:
a filter that applies the provided function to its input before delegating to the provided filter

matches

public static Filter<java.lang.String> matches(java.util.regex.Pattern pattern)
Returns a filter accepting strings that match the provided pattern

Parameters:
pattern - the pattern to filter by
Returns:
a filter accepting strings that match the provided pattern

matches

public static Filter<java.lang.String> matches(java.lang.String pattern)
Returns a filter accepting strings that match the supplied pattern

Parameters:
pattern - the pattern to filter by
Returns:
a filter accepting strings that match the supplied pattern

isMemberOf

public static <E> Filter<E> isMemberOf(AnySet<E> set)
Returns a filter accepting values that are members of the provided set

Parameters:
set - set of values to accept
Returns:
a filter accepting values that are members of the provided set

isMemberOf

public static <E> Filter<E> isMemberOf(java.lang.Iterable<E> set)
Returns a filter accepting values that occur in the provided Iterable. A set is constructed containing these values, so this can be expensive with respect to memory utilisation.

Parameters:
set - Iterable of values to accept
Returns:
a filter accepting values that occur in the provided Iterable

apply

public static <E> java.util.List<E> apply(java.util.Collection<E> coll,
                                          Filter<? super E> filter)
Returns a new ArrayList representing the items from the provided Collection that when passed to the provided filter's accept() method, returned true. Equivalent to apply(filter, coll).

Parameters:
coll - the collection to be filtered
filter - the filter to apply
Returns:
an eagerly filtered copy of the provided collection

apply

public static <E> FilteredIterable<E> apply(java.lang.Iterable<E> iter,
                                            Filter<? super E> filter)
Returns an Iterable whose iterator() method will yield a lazily filtered Iterator wrapping the one returned by the Iterable provided to this method, filtered by the provided filter. Equivalent to apply(filter, iter).

Parameters:
iter - Iterable to filter
filter - the filter to apply
Returns:
a filtering Iterable

apply

public static <E> FilteredIterator<E> apply(java.util.Iterator<E> iter,
                                            Filter<? super E> filter)
Returns an Iterator wrapping the one provided and lazily filtering its contents by the provided filter. Equivalent to apply(filter, iter).

Parameters:
iter - the Iterator to filter
filter - the filter to apply
Returns:
a filtered Iterator

apply

public static <E> FilteredClosableIterator<E> apply(ClosableIterator<E> iter,
                                                    Filter<? super E> filter)
Returns a ClosableIterator wrapping the one provided and lazily filtering its contents by the provided filter

Parameters:
iter - the ClosableIterator to filter
filter - the filter to apply
Returns:
a filtered ClosableIterator

apply

public static <E> java.util.List<E> apply(Filter<? super E> filter,
                                          java.util.Collection<E> coll)
Returns a new ArrayList representing the items from the provided Collection that when passed to the provided filter's accept() method, returned true. Equivalent to apply(coll, filter).

Parameters:
coll - the collection to be filtered
filter - the filter to apply
Returns:
an eagerly filtered copy of the provided collection

apply

public static <E> FilteredIterable<E> apply(Filter<? super E> filter,
                                            java.lang.Iterable<E> iter)
Returns an Iterable whose iterator() method will yield a lazily filtered Iterator wrapping the one returned by the Iterable provided to this method, filtered by the provided filter. Equivalent to apply(iter, filter).

Parameters:
iter - Iterable to filter
filter - the filter to apply
Returns:
a filtering Iterable

apply

public static <E> FilteredIterator<E> apply(Filter<? super E> filter,
                                            java.util.Iterator<E> iter)
Returns an Iterator wrapping the one provided and lazily filtering its contents by the provided filter. Equivalent to apply(filter, iter).

Parameters:
iter - the Iterator to filter
filter - the filter to apply
Returns:
a filtered Iterator

apply

public static <E> FilteredClosableIterator<E> apply(Filter<? super E> filter,
                                                    ClosableIterator<E> iter)
Returns an ClosableIterator wrapping the one provided and lazily filtering its contents by the provided filter. Equivalent to apply(filter, iter).

Parameters:
iter - the ClosableIterator to filter
filter - the filter to apply
Returns:
a filtered ClosableIterator

remove

public static <V> int remove(Filter<? super V> removeMatches,
                             int removeAtMost,
                             java.util.Iterator<V> iter)
Visits the elements in the provided Iterator, executing remove() on any that match the provided filter (i.e. where the accept() method returns true). Once removeAtMost matches have been encountered and removed, or the end of the Iterator is reached, the method returns the number of items removed.

Parameters:
removeMatches - filter to apply as removals
removeAtMost - maximum number of removals to perform
iter - iterator to remove from
Returns:
the number of matching values found and removed

removeAndReturnFirst

public static <V> V removeAndReturnFirst(Filter<? super V> removeMatches,
                                         int removeAtMost,
                                         java.util.Iterator<V> iter)
Visits the elements in the provided Iterator, executing remove() on any that match the provided filter (i.e. where the accept() method returns true). Once removeAtMost matches have been encountered and removed, or the end of the Iterator is reached, the method returns the first value it encountered and removed.

Parameters:
removeMatches - filter to apply as removals
removeAtMost - maximum number of removals to perform
iter - iterator to remove from
Returns:
the first matching value found and removed

removeAndReturn

public static <V> java.util.Iterator<V> removeAndReturn(Filter<? super V> removeMatches,
                                                        int removeAtMost,
                                                        java.util.Iterator<V> iter)
Returns a new Iterator which visits the first removeAtMost items from the provided Iterator matching the provided Filter, removing them from the provided Filter as they are visited.

Parameters:
removeMatches - filter to apply as removals
removeAtMost - maximum number of removals to perform
iter - iterator to remove from
Returns:
the values matching the provided filter, which are removed as they are visited