Package org.apache.ignite.internal.util
Class GridBoundedLinkedHashSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.apache.ignite.internal.util.GridSerializableSet<E>
-
- org.apache.ignite.internal.util.GridBoundedLinkedHashSet<E>
-
- Type Parameters:
E- Set element.
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,Set<E>
public class GridBoundedLinkedHashSet<E> extends GridSerializableSet<E> implements Cloneable
Hash table and linked list implementation of theSetinterface, with predictable iteration order. This implementation differs fromHashSetin that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order). Note that insertion order is not affected if an element is re-inserted into the set. (An elementeis reinserted into a setsifs.add(e)is invoked whens.contains(e)would returntrueimmediately prior to the invocation.)HashSet is also has maximum capacity. When it is reached the newest elements supersede eldest ones.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GridBoundedLinkedHashSet(int maxCap)Constructs a new, empty set; the backingLinkedHashMapinstance has default initial capacity (16) and load factor (0.75).GridBoundedLinkedHashSet(int initCap, int maxCap)Constructs a new, empty set; the backingLinkedHashHashMapinstance has the specified initial capacity and default load factor, which is0.75.GridBoundedLinkedHashSet(int initCap, int maxCap, float loadFactor)Constructs a new, empty set; the backingLinkedHashMapinstance has the specified initial capacity and the specified load factor.GridBoundedLinkedHashSet(int initCap, int maxCap, float loadFactor, boolean accessOrder)Constructs a new, empty set; the backingLinkedHashMapinstance has the specified initial capacity and the specified load factor.GridBoundedLinkedHashSet(Collection<? extends E> c, int maxCap)Constructs a new set containing the elements in the specified collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E o)Adds the specified element to this set if it is not already present.voidclear()Removes all of the elements from this set.Objectclone()Returns a shallow copy of thisGridBoundedLinkedHashSetinstance: the elements themselves are not cloned.booleancontains(Object o)Returnstrueif this set contains the specified element.booleanisEmpty()Returnstrueif this set contains no elements.Iterator<E>iterator()Returns an iterator over the elements in this set.booleanremove(Object o)Removes the specified element from this set if it is present.intsize()Returns the number of elements in this set (its cardinality).-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
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
addAll, containsAll, retainAll, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
GridBoundedLinkedHashSet
public GridBoundedLinkedHashSet(int maxCap)
Constructs a new, empty set; the backingLinkedHashMapinstance has default initial capacity (16) and load factor (0.75).- Parameters:
maxCap- Maximum set capacity.
-
GridBoundedLinkedHashSet
public GridBoundedLinkedHashSet(Collection<? extends E> c, int maxCap)
Constructs a new set containing the elements in the specified collection. TheLinkedHashMapis created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.- Parameters:
c- The collection whose elements are to be placed into this set.maxCap- Maximum set capacity.
-
GridBoundedLinkedHashSet
public GridBoundedLinkedHashSet(int initCap, int maxCap, float loadFactor)Constructs a new, empty set; the backingLinkedHashMapinstance has the specified initial capacity and the specified load factor.- Parameters:
initCap- The initial capacity of the hash map.maxCap- Maximum set capacity.loadFactor- the Load factor of the hash map.
-
GridBoundedLinkedHashSet
public GridBoundedLinkedHashSet(int initCap, int maxCap, float loadFactor, boolean accessOrder)Constructs a new, empty set; the backingLinkedHashMapinstance has the specified initial capacity and the specified load factor.- Parameters:
initCap- The initial capacity of the hash map.maxCap- Maximum set capacity.loadFactor- the Load factor of the hash map.accessOrder-Truefor access order,falsefor insertion order.
-
GridBoundedLinkedHashSet
public GridBoundedLinkedHashSet(int initCap, int maxCap)Constructs a new, empty set; the backingLinkedHashHashMapinstance has the specified initial capacity and default load factor, which is0.75.- Parameters:
initCap- The initial capacity of the hash table.maxCap- Maximum capacity.
-
-
Method Detail
-
iterator
public Iterator<E> iterator()
Returns an iterator over the elements in this set. The elements are returned in no particular order.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceSet<E>- Specified by:
iteratorin classAbstractCollection<E>- Returns:
- An iterator over the elements in this set.
- See Also:
ConcurrentModificationException
-
size
public int size()
Returns the number of elements in this set (its cardinality).- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- The number of elements in this set (its cardinality).
-
isEmpty
public boolean isEmpty()
Returnstrueif this set contains no elements.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
Trueif this set contains no elements.
-
contains
public boolean contains(Object o)
Returnstrueif this set contains the specified element.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
o- Element whose presence in this set is to be tested.- Returns:
trueif this set contains the specified element.
-
add
public boolean add(E o)
Adds the specified element to this set if it is not already present.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>- Parameters:
o- Element to be added to this set.- Returns:
Trueif the set did not already contain the specified element.
-
remove
public boolean remove(Object o)
Removes the specified element from this set if it is present.- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>- Parameters:
o- Object to be removed from this set, if present.- Returns:
Trueif the set contained the specified element.
-
clear
public void clear()
Removes all of the elements from this set.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
clone
public Object clone() throws CloneNotSupportedException
Returns a shallow copy of thisGridBoundedLinkedHashSetinstance: the elements themselves are not cloned.- Overrides:
clonein classObject- Returns:
- a shallow copy of this set.
- Throws:
CloneNotSupportedException- Thrown if cloning is not supported.
-
-