FilteredList (JavaFX 28)
Description: declaration: module: javafx.base, package: javafx.collections.transformation, class: FilteredList

# Class FilteredList<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
javafx.collections.ObservableListBase<E>
javafx.collections.transformation.TransformationList<E,E>
javafx.collections.transformation.FilteredList<E>

Type Parameters:
  `E` - the list element type

All Implemented Interfaces:
  `Iterable<E>, Collection<E>, List<E>, SequencedCollection<E>, Observable, ObservableList<E>`

public final class FilteredList<E> extends TransformationList<E,E>
Wraps an ObservableList and filters its content using the provided Predicate. All changes in the ObservableList are propagated immediately to the FilteredList.

Since:
  JavaFX 8.0
See Also:
  - `TransformationList`

- ## Property Summary

  Properties
  Type
  Property
  Description
  `final ObjectProperty<Predicate<? super E>>`
  `predicate`
  The predicate that will match the elements that will be in this FilteredList.

- ## Field Summary

  ### Fields declared in class AbstractList

  `modCount`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FilteredList(ObservableList<E> source)`
  Constructs a new FilteredList wrapper around the source list.
  `FilteredList(ObservableList<E> source, Predicate<? super E> predicate)`
  Constructs a new FilteredList wrapper around the source list.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `E`
  `get(int index)`
  Returns the element at the specified position in this list.
  `final Predicate<? super E>`
  `getPredicate()`
  Gets the value of the `predicate` property.
  `int`
  `getSourceIndex(int index)`
  Maps the index of this list's element to an index in the direct source list.
  `int`
  `getViewIndex(int index)`
  Maps the index of the direct source list's element to an index in this list.
  `final ObjectProperty<Predicate<? super E>>`
  `predicateProperty()`
  The predicate that will match the elements that will be in this FilteredList.
  `final void`
  `setPredicate(Predicate<? super E> predicate)`
  Sets the value of the `predicate` property.
  `int`
  `size()`
  Returns the number of elements in this list.
  `protected void`
  `sourceChanged(ListChangeListener.Change<? extends E> c)`
  Called when a change from the source is triggered.

  ### Methods declared in class TransformationList

  `getSource, getSourceIndexFor, isInTransformationChain`

  ### Methods declared in class ObservableListBase

  `addAll, addListener, addListener, beginChange, endChange, fireChange, hasListeners, nextAdd, nextPermutation, nextRemove, nextRemove, nextReplace, nextSet, nextUpdate, remove, removeAll, removeListener, removeListener, retainAll, setAll, setAll`

  ### Methods declared in class AbstractList

  `add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList`

  ### Methods declared in class AbstractCollection

  `addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString`

  ### Methods declared in class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods declared in interface Collection

  `parallelStream, removeIf, stream, toArray`

  ### Methods declared in interface Iterable

  `forEach`

  ### Methods declared in interface List

  `add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, equals, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, set, sort, spliterator, subList, toArray, toArray`

  ### Methods declared in interface Observable

  `subscribe`

  ### Methods declared in interface ObservableList

  `filtered, replaceRange, sorted, sorted`

- ## Property Details

  - ### predicate

    public final ObjectProperty<Predicate<? super E>> predicateProperty
    The predicate that will match the elements that will be in this FilteredList. Elements not matching the predicate will be filtered-out. Null predicate means "always true" predicate, all elements will be matched.
    See Also:
      - `getPredicate()`
      - `setPredicate(Predicate)`
      - `predicateProperty()`

- ## Constructor Details

  - ### FilteredList

    public FilteredList(ObservableList<E> source, Predicate<? super E> predicate)
    Constructs a new FilteredList wrapper around the source list. The provided predicate will match the elements in the source list that will be visible. If the predicate is null, all elements will be matched and the list is equal to the source list.
    Parameters:
      `source` - the source list
      `predicate` - the predicate to match the elements or null to match all elements.

  - ### FilteredList

    public FilteredList(ObservableList<E> source)
    Constructs a new FilteredList wrapper around the source list. This list has an "always true" predicate, containing all the elements of the source list.

    This constructor might be useful if you want to bind `predicateProperty()` of this list.

    Parameters:
      `source` - the source list

- ## Method Details

  - ### predicateProperty

    public final ObjectProperty<Predicate<? super E>> predicateProperty()
    The predicate that will match the elements that will be in this FilteredList. Elements not matching the predicate will be filtered-out. Null predicate means "always true" predicate, all elements will be matched.
    Returns:
      the `predicate` property
    See Also:
      - `getPredicate()`
      - `setPredicate(Predicate)`

  - ### getPredicate

    public final Predicate<? super E> getPredicate()
    Gets the value of the `predicate` property.
    Property description:
      The predicate that will match the elements that will be in this FilteredList. Elements not matching the predicate will be filtered-out. Null predicate means "always true" predicate, all elements will be matched.
    Returns:
      the value of the `predicate` property
    See Also:
      - `setPredicate(Predicate)`
      - `predicateProperty()`

  - ### setPredicate

    public final void setPredicate(Predicate<? super E> predicate)
    Sets the value of the `predicate` property.
    Property description:
      The predicate that will match the elements that will be in this FilteredList. Elements not matching the predicate will be filtered-out. Null predicate means "always true" predicate, all elements will be matched.
    Parameters:
      `predicate` - the value for the `predicate` property
    See Also:
      - `getPredicate()`
      - `predicateProperty()`

  - ### sourceChanged

    protected void sourceChanged(ListChangeListener.Change<? extends E> c)
    Description copied from class: `TransformationList`
    Called when a change from the source is triggered.
    Specified by:
      `sourceChanged` in class `TransformationList<E,E>`
    Parameters:
      `c` - the change

  - ### size

    public int size()
    Returns the number of elements in this list.
    Specified by:
      `size` in interface `Collection<E>`
    Specified by:
      `size` in interface `List<E>`
    Specified by:
      `size` in class `AbstractCollection<E>`
    Returns:
      the number of elements in this list

  - ### get

    public E get(int index)
    Returns the element at the specified position in this list.
    Specified by:
      `get` in interface `List<E>`
    Specified by:
      `get` in class `AbstractList<E>`
    Parameters:
      `index` - index of the element to return
    Returns:
      the element at the specified position in this list

  - ### getSourceIndex

    public int getSourceIndex(int index)
    Description copied from class: `TransformationList`
    Maps the index of this list's element to an index in the direct source list.
    Specified by:
      `getSourceIndex` in class `TransformationList<E,E>`
    Parameters:
      `index` - the index in this list
    Returns:
      the index of the element's origin in the source list
    See Also:
      - `TransformationList.getSource()`

  - ### getViewIndex

    public int getViewIndex(int index)
    Description copied from class: `TransformationList`
    Maps the index of the direct source list's element to an index in this list.
    Specified by:
      `getViewIndex` in class `TransformationList<E,E>`
    Parameters:
      `index` - the index in the source list
    Returns:
      the index of the element in this list if it is contained in this list or negative value otherwise
    See Also:
      - `TransformationList.getSource()`
      - `TransformationList.getSourceIndex(int)`