Class Flags<E extends Enum<E>,This extends Flags<E,This>>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.wildfly.common.flags.Flags<E,This>
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>, SortedSet<E>

public abstract class Flags<E extends Enum<E>,This extends Flags<E,This>> extends AbstractSet<E> implements SortedSet<E>
A base class for implementing value-like flags and flag sets, where flags and flag sets may be used without allocation overhead.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Flags(int bits)
    Construct a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract E
    Get the item (cast to the correct enum type), or null if it is not of the correct type.
    protected abstract This
    Cast the given object to this class, throwing an exception if the cast fails.
    final Comparator<? super E>
    Get the null comparator, indicating that this set is always sorted in natural order.
    final This
    Get the complement of this set.
    final boolean
    contains(E flag)
    Determine if this flag set contains the given flag.
    final boolean
    Determine if this flag set contains the given object.
    final boolean
    containsAll(E flag1, E flag2)
    Determine if this flag set contains all of the given flags.
    final boolean
    containsAll(E flag1, E flag2, E flag3)
    Determine if this flag set contains all of the given flags.
    final boolean
    Determine if this flag set contains all of the objects in the given collection.
    final boolean
    Determine if this flag set contains all of the flags in the given flag set.
    final boolean
    containsAny(E flag1, E flag2)
    Determine if this flag set contains any of the given flags.
    final boolean
    containsAny(E flag1, E flag2, E flag3)
    Determine if this flag set contains any of the given flags.
    final boolean
    Determine if this flag set contains any of the flags in the given flag set.
    final Iterator<E>
    Iterate this set in order from last to first flag.
    final boolean
    Determine if this flag set is equal to the given object.
    final boolean
    equals(Set<?> o)
    Determine if this flag set is equal to the given set.
    final boolean
    Determine if this flag set is equal to the given flag set.
    final E
    Get the first flag in the set.
    void
    forEach(Consumer<? super E> action)
    Apply the given action for every flag in this set.
    final int
    Get the hash code of this flag set.
    final This
    headSet(E toElement)
    Get the subset of flags from this set, up to (but not including) the given element.
    boolean
    Determine if this flag set is empty.
    protected abstract E
    itemOf(int index)
    Get the flag item with the given index.
    final Iterator<E>
    Iterate this set in order from first to last flag.
    final E
    Get the last flag in the set.
    final int
    Get the size of the flag set.
    final This
    subSet(E fromElement, E toElement)
    Get the subset of flags, starting from fromElement up to (but not including) toElement.
    final This
    tailSet(E fromElement)
    Get the subset of flags from this set, starting from the given element.
    protected abstract This
    Return this.
    final Object[]
    Get an Object array containing all the flag values of this set.
    final <T> T[]
    toArray(T[] array)
    Get a typed array containing all the flag values of this set.
    final String
    Get a string representation of this flag set.
    protected abstract This
    value(int bits)
    Get the set value of the given bit combination.
    final This
    with(E flag)
    Return a set which includes all of the flags in this set and the given additional flag.
    final This
    with(E... flags)
    Return a set which includes all of the flags in this set and the given additional flags.
    final This
    with(E flag1, E flag2)
    Return a set which includes all of the flags in this set and the given additional flags.
    final This
    with(E flag1, E flag2, E flag3)
    Return a set which includes all of the flags in this set and the given additional flags.
    final This
    with(This other)
    Return a set which includes all of the flags in this set and the given additional flags.
    final This
    without(E flag)
    Return a set which includes all of the flags except for the given flag.
    final This
    without(This other)
    Return a set which includes all of the flags except for the given flags.

    Methods inherited from class java.util.AbstractSet

    removeAll

    Methods inherited from class java.util.AbstractCollection

    add, addAll, clear, remove, retainAll

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface java.util.Set

    add, addAll, clear, remove, removeAll, retainAll

    Methods inherited from interface java.util.SortedSet

    spliterator
  • Constructor Details

    • Flags

      protected Flags(int bits)
      Construct a new instance. This constructor should only be called during initial array construction.
      Parameters:
      bits - the bits of this set
  • Method Details

    • value

      protected abstract This value(int bits)
      Get the set value of the given bit combination. The bit combination may contain extraneous one-bits so any bits beyond the bit of the last flag should be masked off if an array is used for lookup.
      Parameters:
      bits - the bit combination (possibly with extra bits)
      Returns:
      the set instance
    • this_

      protected abstract This this_()
      Return this.
      Returns:
      this
    • itemOf

      protected abstract E itemOf(int index)
      Get the flag item with the given index.
      Parameters:
      index - the index
      Returns:
      the flag
    • castItemOrNull

      protected abstract E castItemOrNull(Object obj)
      Get the item (cast to the correct enum type), or null if it is not of the correct type.
      Parameters:
      obj - the object to cast
      Returns:
      the cast object, or null
    • castThis

      protected abstract This castThis(Object obj)
      Cast the given object to this class, throwing an exception if the cast fails.
      Parameters:
      obj - the object to cast
      Returns:
      the cast object
    • size

      public final int size()
      Get the size of the flag set.
      Specified by:
      size in interface Collection<E extends Enum<E>>
      Specified by:
      size in interface Set<E extends Enum<E>>
      Specified by:
      size in class AbstractCollection<E extends Enum<E>>
      Returns:
      the flag set size
    • first

      public final E first()
      Get the first flag in the set.
      Specified by:
      first in interface SortedSet<E extends Enum<E>>
      Returns:
      the first flag
    • last

      public final E last()
      Get the last flag in the set.
      Specified by:
      last in interface SortedSet<E extends Enum<E>>
      Returns:
      the last flag
    • comparator

      public final Comparator<? super E> comparator()
      Get the null comparator, indicating that this set is always sorted in natural order.
      Specified by:
      comparator in interface SortedSet<E extends Enum<E>>
      Returns:
      null
    • isEmpty

      public boolean isEmpty()
      Determine if this flag set is empty.
      Specified by:
      isEmpty in interface Collection<E extends Enum<E>>
      Specified by:
      isEmpty in interface Set<E extends Enum<E>>
      Overrides:
      isEmpty in class AbstractCollection<E extends Enum<E>>
      Returns:
      true if the flag set is empty, false otherwise
    • headSet

      public final This headSet(E toElement)
      Get the subset of flags from this set, up to (but not including) the given element.
      Specified by:
      headSet in interface SortedSet<E extends Enum<E>>
      Parameters:
      toElement - the "to" element (must not be null)
      Returns:
      the subset
    • tailSet

      public final This tailSet(E fromElement)
      Get the subset of flags from this set, starting from the given element.
      Specified by:
      tailSet in interface SortedSet<E extends Enum<E>>
      Parameters:
      fromElement - the "from" element (must not be null)
      Returns:
      the subset
    • subSet

      public final This subSet(E fromElement, E toElement)
      Get the subset of flags, starting from fromElement up to (but not including) toElement.
      Specified by:
      subSet in interface SortedSet<E extends Enum<E>>
      Parameters:
      fromElement - the "from" element (must not be null)
      toElement - the "to" element (must not be null)
      Returns:
      the subset
    • toArray

      public final Object[] toArray()
      Get an Object array containing all the flag values of this set.
      Specified by:
      toArray in interface Collection<E extends Enum<E>>
      Specified by:
      toArray in interface Set<E extends Enum<E>>
      Overrides:
      toArray in class AbstractCollection<E extends Enum<E>>
      Returns:
      the Object array
    • toArray

      public final <T> T[] toArray(T[] array)
      Get a typed array containing all the flag values of this set.
      Specified by:
      toArray in interface Collection<E extends Enum<E>>
      Specified by:
      toArray in interface Set<E extends Enum<E>>
      Overrides:
      toArray in class AbstractCollection<E extends Enum<E>>
      Type Parameters:
      T - the element type
      Parameters:
      array - the array to populate or clone
      Returns:
      the populated array
    • contains

      public final boolean contains(E flag)
      Determine if this flag set contains the given flag.
      Parameters:
      flag - the flag
      Returns:
      true if the flag is contained by this set
    • contains

      public final boolean contains(Object o)
      Determine if this flag set contains the given object.
      Specified by:
      contains in interface Collection<E extends Enum<E>>
      Specified by:
      contains in interface Set<E extends Enum<E>>
      Overrides:
      contains in class AbstractCollection<E extends Enum<E>>
      Parameters:
      o - the object
      Returns:
      true if the object is contained by this set
    • containsAll

      public final boolean containsAll(Collection<?> c)
      Determine if this flag set contains all of the objects in the given collection.
      Specified by:
      containsAll in interface Collection<E extends Enum<E>>
      Specified by:
      containsAll in interface Set<E extends Enum<E>>
      Overrides:
      containsAll in class AbstractCollection<E extends Enum<E>>
      Parameters:
      c - the collection
      Returns:
      true if all of the collection's objects are contained by this set
    • containsAll

      public final boolean containsAll(This other)
      Determine if this flag set contains all of the flags in the given flag set.
      Parameters:
      other - the flag set
      Returns:
      true if all of the given set's flags are contained by this set
    • containsAll

      public final boolean containsAll(E flag1, E flag2)
      Determine if this flag set contains all of the given flags.
      Parameters:
      flag1 - the first flag
      flag2 - the second flag
      Returns:
      true if all of the given flags are contained by this set
    • containsAll

      public final boolean containsAll(E flag1, E flag2, E flag3)
      Determine if this flag set contains all of the given flags.
      Parameters:
      flag1 - the first flag
      flag2 - the second flag
      flag3 - the third flag
      Returns:
      true if all of the given flags are contained by this set
    • containsAny

      public final boolean containsAny(This other)
      Determine if this flag set contains any of the flags in the given flag set.
      Parameters:
      other - the flag set
      Returns:
      true if all of the given set's flags are contained by this set
    • containsAny

      public final boolean containsAny(E flag1, E flag2)
      Determine if this flag set contains any of the given flags.
      Parameters:
      flag1 - the first flag
      flag2 - the second flag
      Returns:
      true if any of the given flags are contained by this set
    • containsAny

      public final boolean containsAny(E flag1, E flag2, E flag3)
      Determine if this flag set contains any of the given flags.
      Parameters:
      flag1 - the first flag
      flag2 - the second flag
      flag3 - the third flag
      Returns:
      true if any of the given flags are contained by this set
    • complement

      public final This complement()
      Get the complement of this set.
      Returns:
      the complement of this set
    • with

      public final This with(E flag)
      Return a set which includes all of the flags in this set and the given additional flag.
      Parameters:
      flag - the additional flag
      Returns:
      the combined set
    • with

      public final This with(E flag1, E flag2)
      Return a set which includes all of the flags in this set and the given additional flags.
      Parameters:
      flag1 - the first flag
      flag2 - the second flag
      Returns:
      the combined set
    • with

      public final This with(E flag1, E flag2, E flag3)
      Return a set which includes all of the flags in this set and the given additional flags.
      Parameters:
      flag1 - the first flag
      flag2 - the second flag
      flag3 - the third flag
      Returns:
      the combined set
    • with

      @SafeVarargs public final This with(E... flags)
      Return a set which includes all of the flags in this set and the given additional flags.
      Parameters:
      flags - the additional flags
      Returns:
      the combined set
    • with

      public final This with(This other)
      Return a set which includes all of the flags in this set and the given additional flags.
      Parameters:
      other - the additional flags
      Returns:
      the combined set
    • without

      public final This without(E flag)
      Return a set which includes all of the flags except for the given flag.
      Parameters:
      flag - the flag
      Returns:
      the reduced set
    • without

      public final This without(This other)
      Return a set which includes all of the flags except for the given flags.
      Parameters:
      other - the flags
      Returns:
      the reduced set
    • equals

      public final boolean equals(Object o)
      Determine if this flag set is equal to the given object.
      Specified by:
      equals in interface Collection<E extends Enum<E>>
      Specified by:
      equals in interface Set<E extends Enum<E>>
      Overrides:
      equals in class AbstractSet<E extends Enum<E>>
      Parameters:
      o - the other object
      Returns:
      true if the object is equal to this set, false otherwise
    • equals

      public final boolean equals(Set<?> o)
      Determine if this flag set is equal to the given set.
      Parameters:
      o - the other set
      Returns:
      true if the set is equal to this set, false otherwise
    • equals

      public final boolean equals(This o)
      Determine if this flag set is equal to the given flag set.
      Parameters:
      o - the other flag set
      Returns:
      true if the flag set is equal to this set, false otherwise
    • hashCode

      public final int hashCode()
      Get the hash code of this flag set.
      Specified by:
      hashCode in interface Collection<E extends Enum<E>>
      Specified by:
      hashCode in interface Set<E extends Enum<E>>
      Overrides:
      hashCode in class AbstractSet<E extends Enum<E>>
      Returns:
      the flag set hash code
    • iterator

      public final Iterator<E> iterator()
      Iterate this set in order from first to last flag.
      Specified by:
      iterator in interface Collection<E extends Enum<E>>
      Specified by:
      iterator in interface Iterable<E extends Enum<E>>
      Specified by:
      iterator in interface Set<E extends Enum<E>>
      Specified by:
      iterator in class AbstractCollection<E extends Enum<E>>
      Returns:
      the iterator
    • descendingIterator

      public final Iterator<E> descendingIterator()
      Iterate this set in order from last to first flag.
      Returns:
      the iterator
    • forEach

      public void forEach(Consumer<? super E> action)
      Apply the given action for every flag in this set.
      Specified by:
      forEach in interface Iterable<E extends Enum<E>>
      Parameters:
      action - the action to apply
    • toString

      public final String toString()
      Get a string representation of this flag set.
      Overrides:
      toString in class AbstractCollection<E extends Enum<E>>
      Returns:
      the string representation