Package com.tangosol.util
Class MapSet
java.lang.Object
java.util.AbstractCollection
java.util.AbstractSet
com.tangosol.util.MapSet
- All Implemented Interfaces:
 ExternalizableLite,Externalizable,Serializable,Cloneable,Iterable,Collection,Set
- Direct Known Subclasses:
 SafeHashSet,SegmentedHashSet
An ExternalizableLite implementation of java.util.Set that uses an
 underlying Map object to store its data in, just as the Java HashSet
 implementation uses an underlying HashMap for its element storage.
- Since:
 - Coherence 3.2
 - Author:
 - cp 09/16/05 Originally SafeHashSet (gg)
 - See Also:
 
- 
Field Summary
Fields - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionbooleanEnsures that this Set contains the specified element.booleanaddAll(Collection coll) Adds all of the elements in the specified Collection to this Set if they're not already present.voidclear()Removes all of the elements from this Set.clone()Create a clone of this MapSet.booleanReturns true if this Set contains the specified element.booleancontainsAll(Collection coll) Returns true if this Set contains all of the elements in the specified Collection.getMap()Obtain the underlying Map for purposes of synchronization or read-only access; the caller must never directly modify the returned Map.protected MapFactory pattern: Provide an underlying Map for this Set implementation to store its contents in.iterator()Returns an iterator over the elements in this Set.voidRestore the contents of this object by loading the object's state from the passed DataInput object.voidInitialize this object from the contents of the passed object stream.booleanRemoves the specified element from this Set if it is present.booleanremoveAll(Collection coll) Removes from this Set all of its elements that are contained in the specified Collection.booleanretainAll(Collection coll) Retains only the elements in this Set that are contained in the specified Collection.intsize()Returns the number of elements in this Set.Object[]toArray()Returns an array containing all of the elements in this Set.Object[]Returns an array containing all of the elements in this set whose runtime type is that of the specified array.voidwriteExternal(DataOutput out) Save the contents of this object by storing the object's state into the passed DataOutput object.voidWrite the contents of this object into the passed object stream.Methods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.util.AbstractCollection
isEmpty, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
isEmpty, spliterator 
- 
Field Details
- 
NO_VALUE
A no-value object. - 
m_map
The underlying Map. 
 - 
 - 
Constructor Details
- 
MapSet
public MapSet()Default constructor. By default, HashMap is the underlying Map. If that is not the desired behavior, then pass an explicit Map to theMapSet(Map)constructor. To change the default Map implementation, sub-class the MapSet and override theinstantiateMap()method. - 
MapSet
Construct a MapSet that uses the given Map for its underlying storage.- Parameters:
 map- the underlying Map object
 
 - 
 - 
Method Details
- 
size
public int size()Returns the number of elements in this Set.- Specified by:
 sizein interfaceCollection- Specified by:
 sizein interfaceSet- Specified by:
 sizein classAbstractCollection- Returns:
 - the number of elements in this Set.
 
 - 
contains
Returns true if this Set contains the specified element.- Specified by:
 containsin interfaceCollection- Specified by:
 containsin interfaceSet- Overrides:
 containsin classAbstractCollection- Returns:
 - true if this Set contains the specified element
 
 - 
iterator
Returns an iterator over the elements in this Set. The elements are returned in no particular order.- Specified by:
 iteratorin interfaceCollection- Specified by:
 iteratorin interfaceIterable- Specified by:
 iteratorin interfaceSet- Specified by:
 iteratorin classAbstractCollection- Returns:
 - an iterator over the elements in this Set
 
 - 
toArray
Returns an array containing all of the elements in this Set. Obeys the general contract of theCollection.toArray()method.- Specified by:
 toArrayin interfaceCollection- Specified by:
 toArrayin interfaceSet- Overrides:
 toArrayin classAbstractCollection- Returns:
 - an array containing all of the elements in this Set
 
 - 
toArray
Returns an array containing all of the elements in this set whose runtime type is that of the specified array. Obeys the general contract of theCollection.toArray(Object[])method.- Specified by:
 toArrayin interfaceCollection- Specified by:
 toArrayin interfaceSet- Overrides:
 toArrayin classAbstractCollection- Parameters:
 ao- the array into which the elements of this Set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose- Returns:
 - an array containing the elements of this Set
 - Throws:
 ArrayStoreException- the runtime type of a is not a supertype of the runtime type of every element in this Set
 - 
add
Ensures that this Set contains the specified element. Returns true if the Set changed as a result of the call. Returns false if this Set already contains the specified element.- Specified by:
 addin interfaceCollection- Specified by:
 addin interfaceSet- Overrides:
 addin classAbstractCollection- Parameters:
 o- element to be added to this Set- Returns:
 - true if this Set did not already contain the specified element
 
 - 
remove
Removes the specified element from this Set if it is present. Returns true if the Set contained the specified element (or equivalently, if the Set changed as a result of the call). The Set will not contain the specified element once the call returns.- Specified by:
 removein interfaceCollection- Specified by:
 removein interfaceSet- Overrides:
 removein classAbstractCollection- Parameters:
 o- object to be removed from this Set, if present- Returns:
 - true if the Set contained the specified element
 
 - 
containsAll
Returns true if this Set contains all of the elements in the specified Collection.- Specified by:
 containsAllin interfaceCollection- Specified by:
 containsAllin interfaceSet- Overrides:
 containsAllin classAbstractCollection- Parameters:
 coll- Collection to be checked for containment in this Set- Returns:
 - true if this Set contains all of the elements in the specified Collection
 - See Also:
 
 - 
addAll
Adds all of the elements in the specified Collection to this Set if they're not already present.- Specified by:
 addAllin interfaceCollection- Specified by:
 addAllin interfaceSet- Overrides:
 addAllin classAbstractCollection- Parameters:
 coll- Collection whose elements are to be added to this Set- Returns:
 - true if this Set changed as a result of the call
 - See Also:
 
 - 
retainAll
Retains only the elements in this Set that are contained in the specified Collection.- Specified by:
 retainAllin interfaceCollection- Specified by:
 retainAllin interfaceSet- Overrides:
 retainAllin classAbstractCollection- Parameters:
 coll- Collection that defines which elements this Set will retain- Returns:
 - true if this Set changed as a result of the call
 
 - 
removeAll
Removes from this Set all of its elements that are contained in the specified Collection.- Specified by:
 removeAllin interfaceCollection- Specified by:
 removeAllin interfaceSet- Overrides:
 removeAllin classAbstractSet- Parameters:
 coll- Collection that defines which elements will be removed from this Set- Returns:
 - true if this Set changed as a result of the call
 - See Also:
 
 - 
clear
public void clear()Removes all of the elements from this Set.- Specified by:
 clearin interfaceCollection- Specified by:
 clearin interfaceSet- Overrides:
 clearin classAbstractCollection
 - 
getMap
Obtain the underlying Map for purposes of synchronization or read-only access; the caller must never directly modify the returned Map.- Returns:
 - the underlying Map
 
 - 
clone
Create a clone of this MapSet. - 
readExternal
Initialize this object from the contents of the passed object stream.- Specified by:
 readExternalin interfaceExternalizable- Parameters:
 in- the stream to read data from in order to restore the object- Throws:
 IOException- if an I/O exception occursClassNotFoundException
 - 
writeExternal
Write the contents of this object into the passed object stream.- Specified by:
 writeExternalin interfaceExternalizable- Parameters:
 out- the stream to write the object to- Throws:
 IOException- if an I/O exception occurs
 - 
readExternal
Restore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
 readExternalin interfaceExternalizableLite- Parameters:
 in- the DataInput stream to read data from in order to restore the state of this object- Throws:
 IOException- if an I/O exception occurs
 - 
writeExternal
Save the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
 writeExternalin interfaceExternalizableLite- Parameters:
 out- the DataOutput stream to write the state of this object to- Throws:
 IOException- if an I/O exception occurs
 - 
instantiateMap
Factory pattern: Provide an underlying Map for this Set implementation to store its contents in.- Returns:
 - a new Map instance
 
 
 -