EnumSet<T extends Enum> class abstract

An binary based Set implementation for Enums.

A EnumSet can hold different values of one Enum. The implementation is based on binary operations and stores all information in one or more ints. Based on that some operations may be more efficient than in a regular Set since bit operations are suffient for adding/removing and other operations.

Internally two different implementations are used. The default implementation stores all values in one int and therefore can only contain a certain number of values. The specific number of values depends on the compilation of the code. If the total number of possible enum values is greater than the number of bits one int can hold another implementation is used where instead of one int a list of multiple ints is used which makes it possible to store more values. The functionallity of this implementation is the same as on the regular implementation.

The EnumSet provides the same method as an regular Set. In addition there are methods to copy an EnumSet, fill an EnumSet with all possible Enum values and a complement method, which returns a new EnumSet with all enum values which are not included in the original set.

For creation a few factory methods for useful usage exists.

Examples:

enum Numbers { one, two, three; }

EnumSet<Numbers>.of(Numbers.values, [Numbers.one]);
EnumSet<Numbers>.noneOf(Numbers.values);
EnumSet<Numbers>.allOf(Numbers.values);

See also:

  • Set is the general interface of collection where each object can occur only once.
Inheritance
Implemented types
Available Extensions
Annotations
  • @sealed

Constructors

EnumSet.allOf(List<T> all)
Creates a new EnumSet which holds all elements of a given Enum.
factory
EnumSet.complementOf(EnumSet<T> other)
Creates a new EnumSet which holds all elements which are not included in other.
factory
EnumSet.copy(EnumSet<T> other)
Creates a new copy of the current EnumSet and returns it. The newly created set holds exactly the same data as other.
factory
EnumSet.noneOf(List<T> all)
Creates a new EnumSet which holds no elements of a given Enum.
factory
EnumSet.of(List<T> all, Iterable<T> elements)
Creates a new EnumSet which holds the specified elements of a given Enum.
factory

Properties

first → T
The first element.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
iterator Iterator<T>
A new Iterator that allows iterating the elements of this Iterable.
no setterinherited
last → T
The last element.
no setterinherited
length int
The number of elements in this.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single → T
Checks that this iterable has only one element, and returns that element.
no setterinherited

Methods

add(T value) bool
Adds value to the set.
override
addAll(Iterable<T> elements) → void
Adds all elements to this set.
override
any(bool test(T element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Set<R>
A view of this iterable as an iterable of R instances.
override
clear() → void
Removes all elements from the set.
override
complement() EnumSet<T>
Returns a new EnumSet which holds all elements which are not included in the EnumSet on which the method is called.
contains(Object? value) bool
Whether value is in the set.
override
containsAll(Iterable<Object?> other) bool
Whether this set contains all the elements of other.
override
copy() EnumSet<T>
Creates a new copy of the current EnumSet and returns it. The newly created set holds exactly the same data as the one on which the method is called on.
difference(Set<Object?> other) EnumSet<T>
Creates a new EnumSet with the elements of this that are not in other.
override
elementAt(int index) → T
Returns the indexth element.
inherited
every(bool test(T element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(T element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
fill() → void
Fills the EnumSet with all values from the dependent Enum. This method is equivalent to addAll with a list of the enums universe. Example:
firstWhere(bool test(T element), {T orElse()?}) → T
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, T element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<T> other) Iterable<T>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(T element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
intersection(Set<Object?> other) EnumSet<T>
Creates a new EnumSet which is the intersection between this set and other.
override
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(T element), {T orElse()?}) → T
The last element that satisfies the given predicate test.
inherited
lookup(Object? object) → T?
If an object equal to object is in the set, return it.
override
map<T>(T toElement(T e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(T combine(T value, T element)) → T
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
remove(Object? value) bool
Removes value from the set.
override
removeAll(Iterable<Object?> elements) → void
Removes each element of elements from this set.
override
removeWhere(bool test(T element)) → void
Removes all elements of this set that satisfy test.
override
retainAll(Iterable<Object?> elements) → void
Removes all elements of this set that are not elements in elements.
override
retainWhere(bool test(T element)) → void
Removes all elements of this set that fail to satisfy test.
override
singleWhere(bool test(T element), {T orElse()?}) → T
The single element that satisfies test.
inherited
skip(int count) Iterable<T>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(T value)) Iterable<T>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) Iterable<T>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(T value)) Iterable<T>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<T>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<T>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
Returns a string representation of (some of) the elements of this.
inherited
union(Set<T> other) EnumSet<T>
Creates a new EnumSet which contains all the elements of this set and other.
override
where(bool test(T element)) Iterable<T>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited