Module javafx.base

Class SortedList<E>

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


    public final class SortedList<E>
    extends TransformationList<E,E>
    Wraps an ObservableList and sorts its content. All changes in the ObservableList are propagated immediately to the SortedList. Note: invalid SortedList (as a result of broken comparison) doesn't send any notification to listeners on becoming valid again.
    Since:
    JavaFX 8.0
    See Also:
    TransformationList
    • Constructor Detail

      • SortedList

        public SortedList​(ObservableList<? extends E> source,
                          Comparator<? super E> comparator)
        Creates a new SortedList wrapped around the source list. The source list will be sorted using the comparator provided. If null is provided, the list stays unordered and is equal to the source list.
        Parameters:
        source - a list to wrap
        comparator - a comparator to use or null for unordered List
    • Method Detail

      • getComparator

        public final Comparator<? super E> getComparator​()
        Gets the value of the property comparator.
        Property description:
        The comparator that denotes the order of this SortedList. Null for unordered SortedList.
      • setComparator

        public final void setComparator​(Comparator<? super E> comparator)
        Sets the value of the property comparator.
        Property description:
        The comparator that denotes the order of this SortedList. Null for unordered SortedList.
      • 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
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • 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