Package com.forgerock.opendj.util
Class SmallSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- com.forgerock.opendj.util.SmallSet<E>
-
- Type Parameters:
E- The type of elements to be contained in this small set.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
public final class SmallSet<E> extends AbstractSet<E>
A small set of values. This set implementation is optimized to use as little memory as possible in the case where there zero or one elements.In addition, any normalization of elements is delayed until the second element is added (normalization may be triggered by invoking
Object.hashCode()orObject.equals(Object).
-
-
Constructor Summary
Constructors Constructor Description SmallSet()Creates a new small set which is initially empty.SmallSet(int initialCapacity)Creates a new small set with an initial capacity.SmallSet(Collection<? extends E> c)Creates a new small set from the provided collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanaddAll(Collection<? extends E> c)voidaddOrReplace(E element)Adds an element to this small set or replaces the existing element's value with the provided one.voidclear()booleancontains(Object o)Eget(Object o)Returns the element in this small set that is equal to the provided element.Iterator<E>iterator()booleanremove(Object o)intsize()-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, retainAll, toArray, toArray, toString
-
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
containsAll, isEmpty, retainAll, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
SmallSet
public SmallSet()
Creates a new small set which is initially empty.
-
SmallSet
public SmallSet(Collection<? extends E> c)
Creates a new small set from the provided collection.- Parameters:
c- the collection whose elements are to be placed into this set- Throws:
NullPointerException- if the specified collection is null
-
SmallSet
public SmallSet(int initialCapacity)
Creates a new small set with an initial capacity.- Parameters:
initialCapacity- The capacity of the set
-
-
Method Detail
-
add
public boolean add(E e)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>
-
addOrReplace
public void addOrReplace(E element)
Adds an element to this small set or replaces the existing element's value with the provided one.The replacement aspect is useful when the small set uses a "normalized" value to compare elements for equality but stores them as an "actual" value.
- Parameters:
element- the actual element to replace in this small set
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
get
public E get(Object o)
Returns the element in this small set that is equal to the provided element.- Parameters:
o- the element to look for- Returns:
- the element in this small set that is equal to the provided element,
or
nullif no such element exists
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
-