Class FilteredIterable<T>
- java.lang.Object
-
- org.apache.commons.functor.core.collection.FilteredIterable<T>
-
- Type Parameters:
T- the Iterable generic type
- All Implemented Interfaces:
java.lang.Iterable<T>
public class FilteredIterable<T> extends java.lang.Object implements java.lang.Iterable<T>Adds a fluent filtering API to anyIterable.- Version:
- $Revision$ $Date$
-
-
Field Summary
Fields Modifier and Type Field Description private static FilteredIterableEMPTYA defaultFilteredIterablestatic instance that iterates over an empty collection.private java.lang.Iterable<? extends T>iterableTheIterablehas to be filtered.private UnaryAnd<T>predicateThe predicate used to test inputIterableelements.
-
Constructor Summary
Constructors Modifier Constructor Description privateFilteredIterable(java.lang.Iterable<? extends T> iterable)Create a new FilteredIterable.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> FilteredIterable<T>empty()Get an empty FilteredIterable.java.util.Iterator<T>iterator()static <T> FilteredIterable<T>of(java.lang.Iterable<T> iterable)Get aFilteredIterableofiterable.FilteredIterable<T>retain(java.lang.Class<?>... ofType)Retain elements of any of specified types.<U> FilteredIterable<U>retain(java.lang.Class<U> type)Retain elements of a given type with type-safety.FilteredIterable<T>retain(UnaryPredicate<? super T> predicate)Retain only elements matchingpredicate.java.lang.StringtoString()
-
-
-
Field Detail
-
EMPTY
private static final FilteredIterable EMPTY
A defaultFilteredIterablestatic instance that iterates over an empty collection.
-
iterable
private final java.lang.Iterable<? extends T> iterable
TheIterablehas to be filtered.
-
-
Constructor Detail
-
FilteredIterable
private FilteredIterable(java.lang.Iterable<? extends T> iterable)
Create a new FilteredIterable.- Parameters:
iterable- wrapped
-
-
Method Detail
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<T>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
retain
public FilteredIterable<T> retain(UnaryPredicate<? super T> predicate)
Retain only elements matchingpredicate.- Parameters:
predicate- filter, non-null- Returns:
this, fluently
-
retain
public <U> FilteredIterable<U> retain(java.lang.Class<U> type)
Retain elements of a given type with type-safety.- Type Parameters:
U- the input Class generic type.- Parameters:
type- filter, non-null- Returns:
- new FilteredIterable instance that delegates to
this
-
retain
public FilteredIterable<T> retain(java.lang.Class<?>... ofType)
Retain elements of any of specified types.- Parameters:
ofType- filter, non-null- Returns:
this, fluently
-
of
public static <T> FilteredIterable<T> of(java.lang.Iterable<T> iterable)
Get aFilteredIterableofiterable. Ifwrappedisnull, result will also benull. AFilteredIterableargument will be passed back directly; any other argument will be wrapped in a newFilteredIterableobject.- Type Parameters:
T- the input iterable generic type- Parameters:
iterable- wrapped- Returns:
- FilteredIterable
-
empty
public static <T> FilteredIterable<T> empty()
Get an empty FilteredIterable.- Type Parameters:
T- the expectedIterablegeneric type.- Returns:
- FilteredIterable
-
-