Package org.wildfly.common.flags
Class Flags<E extends java.lang.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:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.Set<E>,java.util.SortedSet<E>
public abstract class Flags<E extends java.lang.Enum<E>,This extends Flags<E,This>> extends java.util.AbstractSet<E> implements java.util.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 protectedFlags(int bits)Construct a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract EcastItemOrNull(java.lang.Object obj)Get the item (cast to the correctenumtype), ornullif it is not of the correct type.protected abstract ThiscastThis(java.lang.Object obj)Cast the given object to this class, throwing an exception if the cast fails.java.util.Comparator<? super E>comparator()Get thenullcomparator, indicating that this set is always sorted in natural order.Thiscomplement()Get the complement of this set.booleancontains(E flag)Determine if this flag set contains the given flag.booleancontains(java.lang.Object o)Determine if this flag set contains the given object.booleancontainsAll(E flag1, E flag2)Determine if this flag set contains all of the given flags.booleancontainsAll(E flag1, E flag2, E flag3)Determine if this flag set contains all of the given flags.booleancontainsAll(java.util.Collection<?> c)Determine if this flag set contains all of the objects in the given collection.booleancontainsAll(This other)Determine if this flag set contains all of the flags in the given flag set.booleancontainsAny(E flag1, E flag2)Determine if this flag set contains any of the given flags.booleancontainsAny(E flag1, E flag2, E flag3)Determine if this flag set contains any of the given flags.booleancontainsAny(This other)Determine if this flag set contains any of the flags in the given flag set.java.util.Iterator<E>descendingIterator()Iterate this set in order from last to first flag.booleanequals(java.lang.Object o)Determine if this flag set is equal to the given object.booleanequals(java.util.Set<?> o)Determine if this flag set is equal to the given set.booleanequals(This o)Determine if this flag set is equal to the given flag set.Efirst()Get the first flag in the set.voidforEach(java.util.function.Consumer<? super E> action)Apply the given action for every flag in this set.inthashCode()Get the hash code of this flag set.ThisheadSet(E toElement)Get the subset of flags from this set, up to (but not including) the given element.booleanisEmpty()Determine if this flag set is empty.protected abstract EitemOf(int index)Get the flag item with the given index.java.util.Iterator<E>iterator()Iterate this set in order from first to last flag.Elast()Get the last flag in the set.intsize()Get the size of the flag set.ThissubSet(E fromElement, E toElement)Get the subset of flags, starting fromfromElementup to (but not including)toElement.ThistailSet(E fromElement)Get the subset of flags from this set, starting from the given element.protected abstract Thisthis_()Returnthis.java.lang.Object[]toArray()Get anObjectarray containing all the flag values of this set.<T> T[]toArray(T[] array)Get a typed array containing all the flag values of this set.java.lang.StringtoString()Get a string representation of this flag set.protected abstract Thisvalue(int bits)Get the set value of the given bit combination.Thiswith(E flag)Return a set which includes all of the flags in this set and the given additional flag.Thiswith(E... flags)Return a set which includes all of the flags in this set and the given additional flags.Thiswith(E flag1, E flag2)Return a set which includes all of the flags in this set and the given additional flags.Thiswith(E flag1, E flag2, E flag3)Return a set which includes all of the flags in this set and the given additional flags.Thiswith(This other)Return a set which includes all of the flags in this set and the given additional flags.Thiswithout(E flag)Return a set which includes all of the flags except for the given flag.Thiswithout(This other)Return a set which includes all of the flags except for the given flags.
-
-
-
Method Detail
-
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_()
Returnthis.- 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(java.lang.Object obj)
Get the item (cast to the correctenumtype), ornullif it is not of the correct type.- Parameters:
obj- the object to cast- Returns:
- the cast object, or
null
-
castThis
protected abstract This castThis(java.lang.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.
-
first
public final E first()
Get the first flag in the set.
-
last
public final E last()
Get the last flag in the set.
-
comparator
public final java.util.Comparator<? super E> comparator()
Get thenullcomparator, indicating that this set is always sorted in natural order.
-
isEmpty
public boolean isEmpty()
Determine if this flag set is empty.- Specified by:
isEmptyin interfacejava.util.Collection<E extends java.lang.Enum<E>>- Specified by:
isEmptyin interfacejava.util.Set<E extends java.lang.Enum<E>>- Overrides:
isEmptyin classjava.util.AbstractCollection<E extends java.lang.Enum<E>>- Returns:
trueif the flag set is empty,falseotherwise
-
headSet
public final This headSet(E toElement)
Get the subset of flags from this set, up to (but not including) the given element.
-
tailSet
public final This tailSet(E fromElement)
Get the subset of flags from this set, starting from the given element.
-
subSet
public final This subSet(E fromElement, E toElement)
Get the subset of flags, starting fromfromElementup to (but not including)toElement.
-
toArray
public final java.lang.Object[] toArray()
Get anObjectarray containing all the flag values of this set.
-
toArray
public final <T> T[] toArray(T[] array)
Get a typed array containing all the flag values of this set.- Specified by:
toArrayin interfacejava.util.Collection<E extends java.lang.Enum<E>>- Specified by:
toArrayin interfacejava.util.Set<E extends java.lang.Enum<E>>- Overrides:
toArrayin classjava.util.AbstractCollection<E extends java.lang.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:
trueif the flag is contained by this set
-
contains
public final boolean contains(java.lang.Object o)
Determine if this flag set contains the given object.- Specified by:
containsin interfacejava.util.Collection<E extends java.lang.Enum<E>>- Specified by:
containsin interfacejava.util.Set<E extends java.lang.Enum<E>>- Overrides:
containsin classjava.util.AbstractCollection<E extends java.lang.Enum<E>>- Parameters:
o- the object- Returns:
trueif the object is contained by this set
-
containsAll
public final boolean containsAll(java.util.Collection<?> c)
Determine if this flag set contains all of the objects in the given collection.- Specified by:
containsAllin interfacejava.util.Collection<E extends java.lang.Enum<E>>- Specified by:
containsAllin interfacejava.util.Set<E extends java.lang.Enum<E>>- Overrides:
containsAllin classjava.util.AbstractCollection<E extends java.lang.Enum<E>>- Parameters:
c- the collection- Returns:
trueif 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:
trueif 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 flagflag2- the second flag- Returns:
trueif 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 flagflag2- the second flagflag3- the third flag- Returns:
trueif 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:
trueif 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 flagflag2- the second flag- Returns:
trueif 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 flagflag2- the second flagflag3- the third flag- Returns:
trueif 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 flagflag2- 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 flagflag2- the second flagflag3- 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(java.lang.Object o)
Determine if this flag set is equal to the given object.- Specified by:
equalsin interfacejava.util.Collection<E extends java.lang.Enum<E>>- Specified by:
equalsin interfacejava.util.Set<E extends java.lang.Enum<E>>- Overrides:
equalsin classjava.util.AbstractSet<E extends java.lang.Enum<E>>- Parameters:
o- the other object- Returns:
trueif the object is equal to this set,falseotherwise
-
equals
public final boolean equals(java.util.Set<?> o)
Determine if this flag set is equal to the given set.- Parameters:
o- the other set- Returns:
trueif the set is equal to this set,falseotherwise
-
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:
trueif the flag set is equal to this set,falseotherwise
-
hashCode
public final int hashCode()
Get the hash code of this flag set.
-
iterator
public final java.util.Iterator<E> iterator()
Iterate this set in order from first to last flag.- Specified by:
iteratorin interfacejava.util.Collection<E extends java.lang.Enum<E>>- Specified by:
iteratorin interfacejava.lang.Iterable<E extends java.lang.Enum<E>>- Specified by:
iteratorin interfacejava.util.Set<E extends java.lang.Enum<E>>- Specified by:
iteratorin classjava.util.AbstractCollection<E extends java.lang.Enum<E>>- Returns:
- the iterator
-
descendingIterator
public final java.util.Iterator<E> descendingIterator()
Iterate this set in order from last to first flag.- Returns:
- the iterator
-
forEach
public void forEach(java.util.function.Consumer<? super E> action)
Apply the given action for every flag in this set.
-
-