Class FilteredIterable<T>

java.lang.Object
org.apache.commons.functor.core.collection.FilteredIterable<T>
Type Parameters:
T - the Iterable generic type
All Implemented Interfaces:
Iterable<T>

public class FilteredIterable<T> extends Object implements Iterable<T>
Adds a fluent filtering API to any Iterable.
Version:
$Revision$ $Date$
  • Field Details

    • EMPTY

      private static final FilteredIterable EMPTY
      A default FilteredIterable static instance that iterates over an empty collection.
    • iterable

      private final Iterable<? extends T> iterable
      The Iterable has to be filtered.
    • predicate

      private UnaryAnd<T> predicate
      The predicate used to test input Iterable elements.
  • Constructor Details

    • FilteredIterable

      private FilteredIterable(Iterable<? extends T> iterable)
      Create a new FilteredIterable.
      Parameters:
      iterable - wrapped
  • Method Details

    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • retain

      public FilteredIterable<T> retain(UnaryPredicate<? super T> predicate)
      Retain only elements matching predicate.
      Parameters:
      predicate - filter, non-null
      Returns:
      this, fluently
    • retain

      public <U> FilteredIterable<U> retain(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(Class<?>... ofType)
      Retain elements of any of specified types.
      Parameters:
      ofType - filter, non-null
      Returns:
      this, fluently
    • of

      public static <T> FilteredIterable<T> of(Iterable<T> iterable)
      Get a FilteredIterable of iterable. If wrapped is null, result will also be null. A FilteredIterable argument will be passed back directly; any other argument will be wrapped in a new FilteredIterable object.
      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 expected Iterable generic type.
      Returns:
      FilteredIterable