com.virtuosotechnologies.lib.container
Class PseudoModifiableObjectSet

java.lang.Object
  extended bycom.virtuosotechnologies.lib.container.PseudoModifiableObjectSet
All Implemented Interfaces:
ObjectContainer, ObjectSet
Direct Known Subclasses:
BasicModifiableObjectSet

public class PseudoModifiableObjectSet
extends Object
implements ObjectSet

An ObjectSet that implements methods of ModifiableObjectSet without implementing the ModifiableObjectSet interface. This is useful for implementations that don't want to export objects that appear to be modifiable.

This implementation is fully synchronized and thread-safe. However, note that it may be used in larger implementations that are not thread-safe.


Constructor Summary
PseudoModifiableObjectSet()
          Constructor with no constraints.
PseudoModifiableObjectSet(ConstrainedKey constraints)
          Constructor
 
Method Summary
 boolean addObject(Object obj)
          Add an object to the set
 void addObjectSetListener(ObjectSetListener listener)
          Add an ObjectSetListener.
 boolean contains(Object obj)
          Ask whether an object is present in the set.
 ConstrainedKey getConstraints()
          Get the constraints for the container contents.
 Object[] getContentsAsArray(Class cls)
          Atomically get the current contents of the container as an array.
 int getSize()
          Get the size of the container.
 boolean removeObject(Object obj)
          Remove an object from the set
 void removeObjectSetListener(ObjectSetListener listener)
          Remove an ObjectSetListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PseudoModifiableObjectSet

public PseudoModifiableObjectSet()
Constructor with no constraints.


PseudoModifiableObjectSet

public PseudoModifiableObjectSet(ConstrainedKey constraints)
Constructor

Parameters:
constraints - constraints for the set, or null for no constraints.
Method Detail

getConstraints

public final ConstrainedKey getConstraints()
Get the constraints for the container contents. May return null if there are no constraints.

Specified by:
getConstraints in interface ObjectContainer
Returns:
the constraints expressed by a ConstrainedKey

getSize

public int getSize()
Get the size of the container.

Specified by:
getSize in interface ObjectContainer
Returns:
the size

getContentsAsArray

public Object[] getContentsAsArray(Class cls)
Atomically get the current contents of the container as an array. The element type of the array returned is given by the passed class.

Specified by:
getContentsAsArray in interface ObjectContainer
Parameters:
cls - a class representing the element type
Returns:
an array containing the container contents

contains

public boolean contains(Object obj)
Ask whether an object is present in the set.

Specified by:
contains in interface ObjectSet
Parameters:
obj - object to test
Returns:
true if the set contains this object

addObjectSetListener

public final void addObjectSetListener(ObjectSetListener listener)
Add an ObjectSetListener. Listeners should be added via weak references.

Specified by:
addObjectSetListener in interface ObjectSet
Parameters:
listener - new listener

removeObjectSetListener

public final void removeObjectSetListener(ObjectSetListener listener)
Remove an ObjectSetListener. Does nothing if the listener is not already present.

Specified by:
removeObjectSetListener in interface ObjectSet
Parameters:
listener - listener to remove

addObject

public boolean addObject(Object obj)
Add an object to the set

Parameters:
obj - object to add
Returns:
true if the object was added, or false if the set already contained the object

removeObject

public boolean removeObject(Object obj)
Remove an object from the set

Parameters:
obj - object to remove
Returns:
true if the object was removed, or false if the set didn't contain the object