org.progeeks.cmd
Class CommandMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by org.progeeks.cmd.CommandMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class CommandMap
extends java.util.HashMap

A Map implementation that matches objects to commands and provides a convenient way to execute those commands targeted to a certain object. This is useful for setting up custom event frameworks and such. Keys can be associated with single commands or collections of commands. Configuration options can be specified to allow the command map to accumulate commands when put() is called for the same key.

Version:
$Revision: 1.3 $
Author:
Paul Speed
See Also:
Serialized Form

Constructor Summary
CommandMap()
           
 
Method Summary
 boolean getConcatenate()
          Returns true if the command map will accumulate commands for the same key.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Adds the specified key and command to the map.
 Result runCommand(java.lang.Object key, java.lang.Object target)
          Runs the command associated with the specified key object using the specified target.
 Result runCommand(java.lang.Object key, java.lang.Object target, boolean mustRun)
          Runs the command associated with the specified key object using the specified target.
 void setConcatenate(boolean flag)
          Set to true if the command map should accumulate commands for the same key.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CommandMap

public CommandMap()
Method Detail

setConcatenate

public void setConcatenate(boolean flag)
Set to true if the command map should accumulate commands for the same key. False if existing commands should be replaced. Defaults to true.


getConcatenate

public boolean getConcatenate()
Returns true if the command map will accumulate commands for the same key. False if existing commands will be replaced.


runCommand

public Result runCommand(java.lang.Object key,
                         java.lang.Object target,
                         boolean mustRun)
Runs the command associated with the specified key object using the specified target. If the key doesn't exist and the mustRun flag is true then this method will throw an exception. Otherwise, this operation is a no-op.


runCommand

public Result runCommand(java.lang.Object key,
                         java.lang.Object target)
Runs the command associated with the specified key object using the specified target. If the key doesn't exist, this operation is a no-op.


put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Adds the specified key and command to the map. If the key already exists and the concatenate property is true, then the command will be added to a list of commands associated with the key.

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.HashMap


Copyright © 2002-2003 Paul Speed. All Rights Reserved.