com.metamatrix.common.actions
Class BasicModificationActionQueue

java.lang.Object
  extended by com.metamatrix.common.actions.BasicModificationActionQueue
All Implemented Interfaces:
ModificationActionQueue, java.io.Serializable

public class BasicModificationActionQueue
extends java.lang.Object
implements ModificationActionQueue, java.io.Serializable

This class is the basic and default implementation of the ModificationActionQueue interface. This implementation has no limit to the number of actions that can be put into the queue, and is fully synchronized for concurrent access.

See Also:
Serialized Form

Constructor Summary
BasicModificationActionQueue()
          Create an instance of the modification action queue.
 
Method Summary
 boolean addAction(ActionDefinition newAction)
          Add to the end of this queue a modification action.
 int addActions(java.util.List newActions)
          Moved to the end of this queue the list of modification actions.
 int addActions(ModificationActionQueue queue)
          Moved to the end of this queue the modification actions in the specified queue.
 void clear()
          Remove all of the actions that are currently in this queue.
 int getActionCount()
          Return the number of actions that are currently in this queue.
 java.util.List getActions()
          Return an unmodifiable copy of the list of actions in this queue, possibly empty but never null
 ActionDefinition getLast()
          Return a clone of the last modification action object that was added to this queue.
 boolean hasActions()
          Return whether this queue has at least one modification action.
 java.util.List popActions()
          Remove all of the modification objects that are in the queue and return them.
 java.util.List popActions(int count)
          Remove the specified number of modification objects that are in the queue and return them.
 ActionDefinition removeLast()
          Remove and return the last modification action object that was added to this queue.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicModificationActionQueue

public BasicModificationActionQueue()
Create an instance of the modification action queue.

Method Detail

popActions

public java.util.List popActions()
Remove all of the modification objects that are in the queue and return them. Immediately after this method is called, the queue will contain no actions.

Specified by:
popActions in interface ModificationActionQueue
Returns:
the list of actions, ordered by the time of their creation with the action created last at the end of the list; may be an empty List if there are no actions, but null will not be returned

popActions

public java.util.List popActions(int count)
Remove the specified number of modification objects that are in the queue and return them.

Specified by:
popActions in interface ModificationActionQueue
Parameters:
count - the number of modification action objects to remove from the queue; if greater than the number of actions in this queue, all of the actions are popped.
Returns:
the list of actions that was removed from the queue, ordered by the time of their creation with the action created last at the end of the list, or an empty List if there are no actions in the queue.

getLast

public ActionDefinition getLast()
                         throws java.util.NoSuchElementException
Return a clone of the last modification action object that was added to this queue. This method does not alter the queue in any way.

Specified by:
getLast in interface ModificationActionQueue
Returns:
a clone of the last modification action instance added to this queue.
Throws:
java.util.NoSuchElementException - if this queue is empty.

removeLast

public ActionDefinition removeLast()
                            throws java.util.NoSuchElementException
Remove and return the last modification action object that was added to this queue. This method reduces the number of actions in the queue by 1.

Specified by:
removeLast in interface ModificationActionQueue
Returns:
a clone of the last modification action instance added to this queue.
Throws:
java.util.NoSuchElementException - if this queue is empty.

addAction

public boolean addAction(ActionDefinition newAction)
Add to the end of this queue a modification action.

Specified by:
addAction in interface ModificationActionQueue
Parameters:
newAction - the new modification action that is to be added to this queue.
Returns:
true if the action could be added, or false otherwise.
Throws:
java.lang.IllegalArgumentException - if the new action is null.

addActions

public int addActions(java.util.List newActions)
Moved to the end of this queue the list of modification actions.

Specified by:
addActions in interface ModificationActionQueue
Parameters:
ordered - list of actions to be added to this queue.
Returns:
the number of actions added to this queue.
Throws:
java.lang.IllegalArgumentException - if the new action is null.

addActions

public int addActions(ModificationActionQueue queue)
Moved to the end of this queue the modification actions in the specified queue. The actions will be removed from the specified queue.

Specified by:
addActions in interface ModificationActionQueue
Parameters:
queue - the queue from with all actions are to be removed and added to this queue.
Returns:
the number of actions added to this queue.
Throws:
java.lang.IllegalArgumentException - if the new action is null.

getActions

public java.util.List getActions()
Return an unmodifiable copy of the list of actions in this queue, possibly empty but never null

Specified by:
getActions in interface ModificationActionQueue
Returns:
the unmodifiable list of actions in this queue, possibly empty but never null

getActionCount

public int getActionCount()
Return the number of actions that are currently in this queue.

Specified by:
getActionCount in interface ModificationActionQueue
Returns:
the number of actions in this queue.

hasActions

public boolean hasActions()
Return whether this queue has at least one modification action.

Specified by:
hasActions in interface ModificationActionQueue
Returns:
true if there is at least one modification action in this queue, or false if there are none.

clear

public void clear()
Remove all of the actions that are currently in this queue.

Specified by:
clear in interface ModificationActionQueue

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009. All Rights Reserved.