Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


com.tangosol.util
Class MapSet

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractSet
          extended by com.tangosol.util.MapSet

All Implemented Interfaces:
ExternalizableLite, java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.Set
Direct Known Subclasses:
SafeHashSet, SegmentedHashSet

public class MapSet
extends java.util.AbstractSet
implements java.lang.Cloneable, java.io.Externalizable, ExternalizableLite

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)

Field Summary
protected  java.util.Map m_map
          The underlying Map.
protected static java.lang.Object NO_VALUE
          A no-value object.

 

Constructor Summary
MapSet()
          Default constructor.
MapSet(java.util.Map map)
          Construct a MapSet that uses the given Map for its underlying storage.

 

Method Summary
 boolean add(java.lang.Object o)
          Ensures that this Set contains the specified element.
 boolean addAll(java.util.Collection coll)
          Adds all of the elements in the specified Collection to this Set if they're not already present.
 void clear()
          Removes all of the elements from this Set.
 java.lang.Object clone()
          Create a clone of this MapSet.
 boolean contains(java.lang.Object o)
          Returns true if this Set contains the specified element.
 boolean containsAll(java.util.Collection coll)
          Returns true if this Set contains all of the elements in the specified Collection.
 java.util.Map getMap()
          Obtain the underlying Map for purposes of synchronization or read-only access; the caller must never directly modify the returned Map.
protected  java.util.Map instantiateMap()
          Factory pattern: Provide an underlying Map for this Set implementation to store its contents in.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this Set.
 void readExternal(java.io.DataInput in)
          Restore the contents of this object by loading the object's state from the passed DataInput object.
 void readExternal(java.io.ObjectInput in)
          Initialize this object from the contents of the passed object stream.
 boolean remove(java.lang.Object o)
          Removes the specified element from this Set if it is present.
 boolean removeAll(java.util.Collection coll)
          Removes from this Set all of its elements that are contained in the specified Collection.
 boolean retainAll(java.util.Collection coll)
          Retains only the elements in this Set that are contained in the specified Collection.
 int size()
          Returns the number of elements in this Set.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this Set.
 java.lang.Object[] toArray(java.lang.Object[] ao)
          Returns an array containing all of the elements in this set whose runtime type is that of the specified array.
 void writeExternal(java.io.DataOutput out)
          Save the contents of this object by storing the object's state into the passed DataOutput object.
 void writeExternal(java.io.ObjectOutput out)
          Write the contents of this object into the passed object stream.

 

Methods inherited from class java.util.AbstractSet
equals, hashCode

 

Methods inherited from class java.util.AbstractCollection
isEmpty, toString

 

Methods inherited from interface java.util.Set
isEmpty

 

Field Detail

NO_VALUE

protected static final java.lang.Object NO_VALUE
A no-value object.

m_map

protected transient java.util.Map m_map
The underlying Map.

Constructor Detail

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 the MapSet(Map) constructor. To change the default Map implementation, sub-class the MapSet and override the instantiateMap() method.

MapSet

public MapSet(java.util.Map map)
Construct a MapSet that uses the given Map for its underlying storage.
Parameters:
map - the underlying Map object

Method Detail

size

public int size()
Returns the number of elements in this Set.
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection
Returns:
the number of elements in this Set.

contains

public boolean contains(java.lang.Object o)
Returns true if this Set contains the specified element.
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set
Overrides:
contains in class java.util.AbstractCollection
Parameters:
o - object to be checked for containment in this collection.
Returns:
true if this Set contains the specified element

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this Set. The elements are returned in no particular order.
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.Set
Specified by:
iterator in class java.util.AbstractCollection
Returns:
an iterator over the elements in this Set

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this Set. Obeys the general contract of the Collection.toArray() method.
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection
Returns:
an array containing all of the elements in this Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] ao)
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 the Collection.toArray(Object[]) method.
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection
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:
java.lang.ArrayStoreException - the runtime type of a is not a supertype of the runtime type of every element in this Set

add

public boolean add(java.lang.Object o)
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:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class java.util.AbstractCollection
Parameters:
o - element to be added to this Set
Returns:
true if this Set did not already contain the specified element

remove

public boolean remove(java.lang.Object o)
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:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Overrides:
remove in class java.util.AbstractCollection
Parameters:
o - object to be removed from this Set, if present
Returns:
true if the Set contained the specified element

containsAll

public boolean containsAll(java.util.Collection coll)
Returns true if this Set contains all of the elements in the specified Collection.
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.Set
Overrides:
containsAll in class java.util.AbstractCollection
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:
contains(Object)

addAll

public boolean addAll(java.util.Collection coll)
Adds all of the elements in the specified Collection to this Set if they're not already present.
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.Set
Overrides:
addAll in class java.util.AbstractCollection
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:
add(Object)

retainAll

public boolean retainAll(java.util.Collection coll)
Retains only the elements in this Set that are contained in the specified Collection.
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.Set
Overrides:
retainAll in class java.util.AbstractCollection
Parameters:
coll - Collection that defines which elements this Set will retain
Returns:
true if this Set changed as a result of the call
See Also:
AbstractCollection.remove(Object), AbstractCollection.contains(Object)

removeAll

public boolean removeAll(java.util.Collection coll)
Removes from this Set all of its elements that are contained in the specified Collection.
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.Set
Overrides:
removeAll in class java.util.AbstractSet
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:
remove(Object)

clear

public void clear()
Removes all of the elements from this Set.
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.Set
Overrides:
clear in class java.util.AbstractCollection

getMap

public java.util.Map 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

public java.lang.Object clone()
Create a clone of this MapSet.
Returns:
a clone of this MapSet

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Initialize this object from the contents of the passed object stream.
Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - the stream to read data from in order to restore the object
Throws:
java.io.IOException - if an I/O exception occurs
java.lang.ClassNotFoundException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Write the contents of this object into the passed object stream.
Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - the stream to write the object to
Throws:
java.io.IOException - if an I/O exception occurs

readExternal

public void readExternal(java.io.DataInput in)
                  throws java.io.IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.
Specified by:
readExternal in interface ExternalizableLite
Parameters:
in - the DataInput stream to read data from in order to restore the state of this object
Throws:
java.io.IOException - if an I/O exception occurs
java.io.NotActiveException - if the object is not in its initial state, and therefore cannot be deserialized into

writeExternal

public void writeExternal(java.io.DataOutput out)
                   throws java.io.IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.
Specified by:
writeExternal in interface ExternalizableLite
Parameters:
out - the DataOutput stream to write the state of this object to
Throws:
java.io.IOException - if an I/O exception occurs

instantiateMap

protected java.util.Map instantiateMap()
Factory pattern: Provide an underlying Map for this Set implementation to store its contents in.
Returns:
a new Map instance

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.