Package org.apache.ignite.internal.util
Class GridListSet<V>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.apache.ignite.internal.util.GridSerializableSet<V>
-
- org.apache.ignite.internal.util.GridListSet<V>
-
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<V>,Collection<V>,Set<V>
public class GridListSet<V> extends GridSerializableSet<V> implements Cloneable
Implementation ofSetbased on internal list rather than hash table. The order of the internal list is either insertion order or defined by optionally providedComparator.Note that if
'strict'flag is false, then this set allows inconsistencies betweenObject.equals(Object)andComparator.compare(Object, Object)methods. Theequals(Object)method will always be used to determine final equality. This allows to have multiple elements for whichcompare(Object)method returns0, butequals(Object)method returnsfalse. The reverse is also true, whereequals(Object)may return true, butcompare(Object)method may return non-zero values.In
strictmode, which is default,Object.equals(Object)andComparator.compare(Object, Object)methods must be absolutely consistent with each other.This set does not allow
nullvalues.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GridListSet()Creates unsorted list set.GridListSet(@Nullable Comparator<V> comp)If comparator is notnull, then sorted list set will be created.GridListSet(@Nullable Comparator<V> comp, boolean strict)If comparator is notnull, then sorted list set will be created.GridListSet(GridListSet<V> copy)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(V val)Vaddx(V val)Either adds a value to set or does nothing if value is already present.protected Objectclone()Clones this set.@Nullable Comparator<V>comparator()Gets optional comparator for this set.booleancontains(Object val)GridListSet<V>copy()Creates a copy of this set.Vfirst()Gets first element of this list.Vget(int idx)Gets value at given index within internal list.Vget(V val)Gets instanceestored in this set for whiche.equals(val)returnstrue.Iterator<V>iterator()Vlast()Gets last element of this list.booleanremove(Object val)VremoveFirst()Removes the first element of this list.VremoveLast()Removes the last element of this list.Vremovex(V val)Removes given value from the set and returns the instance stored in the set ornullif value was not found.intsize()booleanstrict()Gets value ofstrictflag for this set.StringtoString()GridListSet<V>toSynchronized()Creates a synchronized instance of this set.List<V>values()Gets a copy of the internal list.-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray
-
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, clear, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
GridListSet
public GridListSet()
Creates unsorted list set. Values will be ordered in insertion order.
-
GridListSet
public GridListSet(@Nullable @Nullable Comparator<V> comp)If comparator is notnull, then sorted list set will be created. Values will be sorted according to provided comparator.- Parameters:
comp- Optional comparator to sort values.
-
GridListSet
public GridListSet(@Nullable @Nullable Comparator<V> comp, boolean strict)If comparator is notnull, then sorted list set will be created. Values will be sorted according to provided comparator.- Parameters:
comp- Optional comparator to sort values.strict- Strict flag.
-
GridListSet
public GridListSet(GridListSet<V> copy)
Copy constructor.- Parameters:
copy- Set to copy from.
-
-
Method Detail
-
strict
public boolean strict()
Gets value ofstrictflag for this set.- Returns:
- Value of
strictflag for this set.
-
comparator
@Nullable public @Nullable Comparator<V> comparator()
Gets optional comparator for this set.- Returns:
- Optional comparator for this set.
-
add
public boolean add(V val)
- Specified by:
addin interfaceCollection<V>- Specified by:
addin interfaceSet<V>- Overrides:
addin classAbstractCollection<V>
-
addx
@Nullable public V addx(V val)
Either adds a value to set or does nothing if value is already present.- Parameters:
val- Value to add.- Returns:
- The instance of value from this set or
nullif value was added.
-
removeFirst
@Nullable public V removeFirst()
Removes the first element of this list.- Returns:
- Removed element or
nullif list is empty.
-
removeLast
@Nullable public V removeLast()
Removes the last element of this list.- Returns:
- Removed element or
nullif list is empty.
-
first
@Nullable public V first()
Gets first element of this list.- Returns:
- First element or
nullif list is empty.
-
last
@Nullable public V last()
Gets last element of this list.- Returns:
- Last element or
nullif list is empty.
-
remove
public boolean remove(Object val)
- Specified by:
removein interfaceCollection<V>- Specified by:
removein interfaceSet<V>- Overrides:
removein classAbstractCollection<V>
-
removex
@Nullable public V removex(V val)
Removes given value from the set and returns the instance stored in the set ornullif value was not found.- Parameters:
val- Value to remove.- Returns:
- The instance that was stored in the set or
null.
-
get
@Nullable public V get(V val)
Gets instanceestored in this set for whiche.equals(val)returnstrue.- Parameters:
val- Value to check for equality.- Returns:
- Instance stored in this set for which
e.equals(val)returnstrue.
-
get
public V get(int idx)
Gets value at given index within internal list. Note that this method will iterate through the list to get a value at the specified index.- Parameters:
idx- Index to get value at (must be non-negative and less thansize()).- Returns:
- Value at give index.
-
contains
public boolean contains(Object val)
- Specified by:
containsin interfaceCollection<V>- Specified by:
containsin interfaceSet<V>- Overrides:
containsin classAbstractCollection<V>
-
copy
public GridListSet<V> copy()
Creates a copy of this set.- Returns:
- Copy of this set.
-
size
public int size()
- Specified by:
sizein interfaceCollection<V>- Specified by:
sizein interfaceSet<V>- Specified by:
sizein classAbstractCollection<V>
-
values
public List<V> values()
Gets a copy of the internal list.- Returns:
- Copy of the internal list.
-
clone
protected Object clone() throws CloneNotSupportedException
Clones this set.- Overrides:
clonein classObject- Returns:
- Clone of this set.
- Throws:
CloneNotSupportedException
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<V>
-
toSynchronized
public GridListSet<V> toSynchronized()
Creates a synchronized instance of this set.- Returns:
- Synchronized instance of this set.
-
-