Class TreeSet<E>

All Implemented Interfaces:
Iterable<E>, Set<E>, SortedSet<E>, Traversable<E>, Iterable<E>

public class TreeSet<E> extends AbstractSortedSet<E>
TreeSet is an implementation of SortedSet backed by a TreeMap.
  • Field Details

    • tree

      private final Tree<E,E> tree
    • redBlackTree

      private final RedBlackTree<E,E> redBlackTree
    • EMPTY

      protected static final TreeSet EMPTY
  • Constructor Details

    • TreeSet

      public TreeSet()
    • TreeSet

      public TreeSet(Comparator<? super E> ordering)
    • TreeSet

      private TreeSet(Tree<E,E> tree, RedBlackTree<E,E> redBlackTree)
  • Method Details

    • factory

      @NotNull public static <E> @NotNull BuilderFactory<E,TreeSet<E>> factory(Comparator<? super E> ordering)
    • empty

      @NotNull public static <E> @NotNull TreeSet<E> empty()
    • comparator

      public Comparator<? super E> comparator()
      Description copied from interface: SortedSet
      Returns the comparator associated with this map, or null if the default ordering is used.
    • add

      @NotNull public @NotNull TreeSet<E> add(E value)
      Description copied from interface: Set
      Returns a set that adds the specified value if it doesn't already exist in this set.
    • remove

      @NotNull public @NotNull TreeSet<E> remove(E value)
      Description copied from interface: Set
      Removes the specified value from the set if it exists.
    • contains

      public boolean contains(E value)
      Description copied from interface: Set
      Returns true if the value exists in this set.
    • size

      public int size()
      Description copied from interface: Traversable
      Returns the size of the collection.

      Warning: infinite collections are possible, as are collections that require traversal to calculate the size.

      Specified by:
      size in interface Traversable<E>
      Overrides:
      size in class AbstractTraversable<E>
    • first

      @Nullable public E first()
      Description copied from interface: SortedSet
      Returns the first element in the set or null of the set is empty.
    • last

      @Nullable public E last()
      Description copied from interface: SortedSet
      Returns the last element in the set or null of the set is empty.
    • iterator

      @NotNull public @NotNull Iterator<E> iterator()
    • drop

      @NotNull public @NotNull SortedSet<E> drop(int number)
      Description copied from interface: SortedSet
      Returns a set containing all elements in this set, excluding the first number of elements.
    • take

      @NotNull public @NotNull SortedSet<E> take(int number)
      Description copied from interface: SortedSet
      Returns a set containing the first number of elements from this set.
    • from

      @NotNull public @NotNull SortedSet<E> from(@NotNull E value, boolean inclusive)
      Description copied from interface: SortedSet
      Returns the bottom of the set starting from the key specified.
      Specified by:
      from in interface SortedSet<E>
      Overrides:
      from in class AbstractSortedSet<E>
      Parameters:
      inclusive - if true, the key will be included in the result, otherwise it will be excluded
    • to

      @NotNull public @NotNull SortedSet<E> to(@NotNull E value, boolean inclusive)
      Description copied from interface: SortedSet
      Returns the top of the set up until the key specified.
      Specified by:
      to in interface SortedSet<E>
      Overrides:
      to in class AbstractSortedSet<E>
      Parameters:
      inclusive - if true, the key will be included in the result, otherwise it will be excluded
    • range

      @NotNull public @NotNull SortedSet<E> range(@NotNull E from, boolean fromInclusive, @NotNull E to, boolean toInclusive)
      Description copied from interface: SortedSet
      Returns a subset of the set between the from and to keys specified.
      Parameters:
      fromInclusive - if true, the key will be included in the result, otherwise it will be excluded
      toInclusive - if true, the key will be included in the result, otherwise it will be excluded