Interface OrderedSet<E>

Type Parameters:
E - value type
All Superinterfaces:
Collection<E>, Iterable<E>, SequencedCollection<E>, SequencedSet<E>, Set<E>

public sealed interface OrderedSet<E> extends SequencedSet<E>
A Set with consistent order of entries. All static factory methods produce unmodifiable sets.
  • Method Details

    • values

      List<E> values()
      A List containing all the values of this OrderedSet.

      Because Set equality ignores order, code needing to verify whether an OrderedSet contains the same values in the same order should also check for equality of the values list.

      Returns:
      values as list
    • reversed

      OrderedSet<E> reversed()
      Specified by:
      reversed in interface SequencedCollection<E>
      Specified by:
      reversed in interface SequencedSet<E>
    • equals

      boolean equals(Object obj)
      Compares the provided object with this map for equality in accordance with the specification of
      invalid reference
      Map#equals(java.lang.Object)
      .

      Because Map equality does not depends on order, code needing to verify whether an OrderedMap contains the same mappings in the same order should also check for equality of the

      invalid reference
      #keys()
      list.
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface Set<E>
      Overrides:
      equals in class Object
      Parameters:
      obj - object to compare
      Returns:
      true if the object is a map containing the same mappings, not necessarily in the same order
    • of

      static <E> OrderedSet<E> of()
      Returns an empty OrderedSet.
      Type Parameters:
      E - value type
      Returns:
      empty OrderedSet
    • of

      static <E> OrderedSet<E> of(E element)
      Returns an OrderedSet with a single element.
      Type Parameters:
      E - element type
      Parameters:
      element - element
      Returns:
      an OrderedSet of the provided element
      Throws:
      NullPointerException - if element is null
    • of

      static <E> OrderedSet<E> of(E e1, E e2)
      Returns an OrderedSet with two elements.
      Type Parameters:
      E - element type
      Parameters:
      e1 - first element
      e2 - second element
      Returns:
      an OrderedSet of the provided elements
      Throws:
      NullPointerException - if any elements are null
      IllegalArgumentException - if any elements are duplicated
    • of

      static <E> OrderedSet<E> of(E e1, E e2, E e3)
      Returns an OrderedSet with three elements.
      Type Parameters:
      E - element type
      Parameters:
      e1 - first element
      e2 - second element
      e3 - third element
      Returns:
      an OrderedSet of the provided elements
      Throws:
      NullPointerException - if any elements are null
      IllegalArgumentException - if any elements are duplicated
    • of

      static <E> OrderedSet<E> of(E e1, E e2, E e3, E e4)
      Returns an OrderedSet with four elements.
      Type Parameters:
      E - element type
      Parameters:
      e1 - first element
      e2 - second element
      e3 - third element
      e4 - fourth element
      Returns:
      an OrderedSet of the provided elements
      Throws:
      NullPointerException - if any elements are null
      IllegalArgumentException - if any elements are duplicated
    • of

      static <E> OrderedSet<E> of(E e1, E e2, E e3, E e4, E e5)
      Returns an OrderedSet with five elements.
      Type Parameters:
      E - element type
      Parameters:
      e1 - first element
      e2 - second element
      e3 - third element
      e4 - fourth element
      e5 - fifth element
      Returns:
      an OrderedSet of the provided elements
      Throws:
      NullPointerException - if any elements are null
      IllegalArgumentException - if any elements are duplicated
    • of

      @SafeVarargs static <E> OrderedSet<E> of(E... elements)
      Returns an OrderedSet of the provided elements.
      Type Parameters:
      E - element type
      Parameters:
      elements - elements
      Returns:
      an OrderedSet of the provided elements
    • copyOf

      static <E> OrderedSet<E> copyOf(Set<? extends E> set)
      Returns an unmodifiable OrderedSet that contains a copy of the provided Set. The order will be the same as the iteration order of the set.

      If the set is already an unmodifiable OrderedSet it may be returned as is.

      Type Parameters:
      E - element type
      Parameters:
      set - set to copy
      Returns:
      an ordered set copy of the provided set
      Throws:
      NullPointerException - if any element is null or the set is null