Class ImmutableOrdinalSet<E extends OrdinalValue<E>>

java.lang.Object
com.google.common.collect.ForwardingObject
com.google.common.collect.ForwardingCollection<E>
com.google.common.collect.ForwardingSet<E>
org.immutables.ordinal.ImmutableOrdinalSet<E>
Type Parameters:
E - element type
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
ImmutableOrdinalSet.EmptyImmutableOrdinalSet, ImmutableOrdinalSet.RegularImmutableOrdinalSet, ImmutableOrdinalSet.SingletonImmutableOrdinalSet

public abstract class ImmutableOrdinalSet<E extends OrdinalValue<E>> extends com.google.common.collect.ForwardingSet<E>
Immutable set that take advantage of elements being an OrdinalValues to provide compact storage and efficient Set.contains(Object) and Set.containsAll(Collection) operations.
See Also:
  • Field Details

  • Constructor Details

    • ImmutableOrdinalSet

      ImmutableOrdinalSet()
  • Method Details

    • of

      public static <E extends OrdinalValue<E>> ImmutableOrdinalSet<E> of()
      Returns singleton empty immutable ordinal set
      Type Parameters:
      E - element type
      Returns:
      empty set
    • of

      @SafeVarargs public static <E extends OrdinalValue<E>> ImmutableOrdinalSet<E> of(E first, E... rest)
      Creates immutable ordinal set from 1 or more elements. All elements expected to have same OrdinalValue.domain() as the first element, otherwise exception will be thrown.
      Type Parameters:
      E - element type
      Parameters:
      first - first element
      rest - the rest of elements
      Returns:
      empty set
    • copyOf

      public static <E extends OrdinalValue<E>> ImmutableOrdinalSet<E> copyOf(Iterable<? extends E> elements)
      Creates immutable ordinal set from iterable of elements. All elements expected to have same OrdinalValue.domain() as the first element, otherwise exception will be thrown.
      Type Parameters:
      E - the element type
      Parameters:
      elements - the elements, no nulls allowed
      Returns:
      the immutable ordinal set
    • copyOf

      public static <E extends OrdinalValue<E>> ImmutableOrdinalSet<E> copyOf(E[] elements)
      Creates immutable ordinal set from array of elements. All elements expected to have same OrdinalValue.domain() as the first element, otherwise exception will be thrown.
      Type Parameters:
      E - the element type
      Parameters:
      elements - the elements, no nulls allowed
      Returns:
      the immutable ordinal set
    • constructFromArray

      private static <E extends OrdinalValue<E>> ImmutableOrdinalSet<E> constructFromArray(OrdinalValue<?>[] array)
    • add

      @Deprecated public final boolean add(E e)
      Deprecated.
      Modification operation are not supported.
      Will throw an exception and leave the collection unmodified.
      Specified by:
      add in interface Collection<E extends OrdinalValue<E>>
      Specified by:
      add in interface Set<E extends OrdinalValue<E>>
      Overrides:
      add in class com.google.common.collect.ForwardingCollection<E extends OrdinalValue<E>>
      Throws:
      UnsupportedOperationException - always
    • remove

      @Deprecated public final boolean remove(Object object)
      Deprecated.
      Modification operation are not supported.
      Will throw an exception and leave the collection unmodified.
      Specified by:
      remove in interface Collection<E extends OrdinalValue<E>>
      Specified by:
      remove in interface Set<E extends OrdinalValue<E>>
      Overrides:
      remove in class com.google.common.collect.ForwardingCollection<E extends OrdinalValue<E>>
      Throws:
      UnsupportedOperationException - always
    • addAll

      @Deprecated public final boolean addAll(Collection<? extends E> newElements)
      Deprecated.
      Modification operation are not supported.
      Will throw an exception and leave the collection unmodified.
      Specified by:
      addAll in interface Collection<E extends OrdinalValue<E>>
      Specified by:
      addAll in interface Set<E extends OrdinalValue<E>>
      Overrides:
      addAll in class com.google.common.collect.ForwardingCollection<E extends OrdinalValue<E>>
      Throws:
      UnsupportedOperationException - always
    • removeAll

      @Deprecated public final boolean removeAll(Collection<?> oldElements)
      Deprecated.
      Modification operation are not supported.
      Will throw an exception and leave the collection unmodified.
      Specified by:
      removeAll in interface Collection<E extends OrdinalValue<E>>
      Specified by:
      removeAll in interface Set<E extends OrdinalValue<E>>
      Overrides:
      removeAll in class com.google.common.collect.ForwardingCollection<E extends OrdinalValue<E>>
      Throws:
      UnsupportedOperationException - always
    • retainAll

      @Deprecated public final boolean retainAll(Collection<?> elementsToKeep)
      Deprecated.
      Modification operation are not supported.
      Will throw an exception and leave the collection unmodified.
      Specified by:
      retainAll in interface Collection<E extends OrdinalValue<E>>
      Specified by:
      retainAll in interface Set<E extends OrdinalValue<E>>
      Overrides:
      retainAll in class com.google.common.collect.ForwardingCollection<E extends OrdinalValue<E>>
      Throws:
      UnsupportedOperationException - always
    • clear

      @Deprecated public final void clear()
      Deprecated.
      Modification operation are not supported.
      Will throw an exception and leave the collection unmodified.
      Specified by:
      clear in interface Collection<E extends OrdinalValue<E>>
      Specified by:
      clear in interface Set<E extends OrdinalValue<E>>
      Overrides:
      clear in class com.google.common.collect.ForwardingCollection<E extends OrdinalValue<E>>
      Throws:
      UnsupportedOperationException - always
    • incrementCounters

      public abstract void incrementCounters(int[] counters)
      Coarse grained method to effectively collect containment information without re-packing internal structures to temporary collections.

      For any contained element, corresponding value in array by ordinal index will be incremented.

      Parameters:
      counters - array of counters where indexes corresponds to ordinal values
      Throws:
      RuntimeException - if counters array length do not correspond to ordinal indexes of contained values
    • containsAny

      public boolean containsAny(Collection<?> collection)
    • builder

      public static <E extends OrdinalValue<E>> ImmutableOrdinalSet.Builder<E> builder()
      Build instances of ImmutableOrdinalSet.
      Type Parameters:
      E - element type
      Returns:
      builder