com.virtuosotechnologies.lib.container
Class PseudoModifiableObjectDeque

java.lang.Object
  extended bycom.virtuosotechnologies.lib.container.PseudoModifiableObjectDeque
All Implemented Interfaces:
ObjectContainer, ObjectDeque
Direct Known Subclasses:
BasicModifiableObjectDeque

public class PseudoModifiableObjectDeque
extends Object
implements ObjectDeque

An ObjectDeque that implements methods of ModifiableObjectDeque without implementing the ModifiableObjectDeque 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
PseudoModifiableObjectDeque()
          Constructor with no constraints
PseudoModifiableObjectDeque(ConstrainedKey constraints)
          Constructor
 
Method Summary
 void addObjectDequeListener(ObjectDequeListener listener)
          Add an ObjectDequeListener.
 Object getBack()
          Get the object in back of the deque.
 ConstrainedKey getConstraints()
          Get the constraints for the container contents.
 Object[] getContentsAsArray(Class cls)
          Atomically get the current contents of the container as an array.
 Object getFront()
          Get the object in front of the deque.
 Object getNthObject(int n)
          Get the indexed object.
 int getSize()
          Get the size of the container.
 void insertObject(int n, Object obj)
          Insert an object in the deque at a particular index.
 Object popObjectBack()
          Pop an object from the back of the deque.
 Object popObjectFront()
          Pop an object from the front of the deque.
 void pushObjectBack(Object obj)
          Push an object on the back of the deque.
 void pushObjectFront(Object obj)
          Push an object on the front of the deque.
 Object removeObject(int n)
          Remove an object from the middle of the deque.
 void removeObjectDequeListener(ObjectDequeListener listener)
          Remove an ObjectDequeListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PseudoModifiableObjectDeque

public PseudoModifiableObjectDeque()
Constructor with no constraints


PseudoModifiableObjectDeque

public PseudoModifiableObjectDeque(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

getFront

public Object getFront()
Get the object in front of the deque. This is an atomic shorthand for getNthObject(0).

Specified by:
getFront in interface ObjectDeque
Returns:
the front object, or null if the deque is empty.

getBack

public Object getBack()
Get the object in back of the deque. This is an atomic shorthand for getNthObject(getSize()-1).

Specified by:
getBack in interface ObjectDeque
Returns:
the back object, or null if the deque is empty.

getNthObject

public Object getNthObject(int n)
Get the indexed object.

Specified by:
getNthObject in interface ObjectDeque
Parameters:
n - index.
Returns:
the nth object.
Throws:
IndexOutOfBoundsException - index out of bounds

addObjectDequeListener

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

Specified by:
addObjectDequeListener in interface ObjectDeque
Parameters:
listener - new listener

removeObjectDequeListener

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

Specified by:
removeObjectDequeListener in interface ObjectDeque
Parameters:
listener - listener to remove

pushObjectFront

public void pushObjectFront(Object obj)
Push an object on the front of the deque.

Parameters:
obj - object to push
Throws:
ConstraintsMismatchException - obj doesn't obey the constraints

pushObjectBack

public void pushObjectBack(Object obj)
Push an object on the back of the deque.

Parameters:
obj - object to push
Throws:
ConstraintsMismatchException - obj doesn't obey the constraints

insertObject

public void insertObject(int n,
                         Object obj)
Insert an object in the deque at a particular index.

Parameters:
n - index to insert at
obj - object to insert
Throws:
ConstraintsMismatchException - obj doesn't obey the constraints
IndexOutOfBoundsException - index out of bounds

popObjectFront

public Object popObjectFront()
Pop an object from the front of the deque. Returns the object, or null if the deque is empty.

Returns:
the object popped, or null if deque is empty

popObjectBack

public Object popObjectBack()
Pop an object from the back of the deque. Returns the object, or null if the deque is empty.

Returns:
the object popped, or null if deque is empty

removeObject

public Object removeObject(int n)
Remove an object from the middle of the deque. Returns the object.

Parameters:
n - index to remove
Returns:
the object remove
Throws:
IndexOutOfBoundsException - index out of bounds