Package org.optaplanner.core.impl.util
Class FieldBasedScalingSet<E>
- java.lang.Object
-
- org.optaplanner.core.impl.util.FieldBasedScalingSet<E>
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
public final class FieldBasedScalingSet<E> extends Object implements Set<E>
Uses a givenSet
as storage unless it is the first and only value, in which case it uses a field. This helps avoid the overhead of creating and accessing the set if we only have 1 value. This implementation is not thread-safe, regardless of the underlyingSet
. Iteration order of elements is specified by the underlyingSet
.
-
-
Constructor Summary
Constructors Constructor Description FieldBasedScalingSet(Supplier<Set<E>> setSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E value)
boolean
addAll(Collection<? extends E> c)
void
clear()
boolean
contains(Object value)
boolean
containsAll(Collection<?> c)
void
forEach(Consumer<? super E> action)
boolean
isEmpty()
Iterator<E>
iterator()
As defined bySet.iterator()
.boolean
remove(Object value)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
-
-
-
Method Detail
-
add
public boolean add(E value)
-
clear
public void clear()
-
remove
public boolean remove(Object value)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
-
retainAll
public boolean retainAll(Collection<?> c)
-
removeAll
public boolean removeAll(Collection<?> c)
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(Object value)
-
iterator
public Iterator<E> iterator()
As defined bySet.iterator()
. May throw an exception if the iterator is used to remove an element while the set is based on a field.
-
toArray
public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
-