Module hw06

Class ATokVisitor

java.lang.Object
provided.tokenFW.ATokVisitor
All Implemented Interfaces:
ITokVisitor

public abstract class ATokVisitor extends Object implements ITokVisitor
A visitor to an Token that implements ITokVisitor using a dictionary of commands.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The dictionary mapping token id's (names) to associated commands.
    The default command to use if there are no command associated with the given host id.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor that sets the default cmd to one that throws and IllegalArgumentException" for any unknown tokens.
    ATokVisitor​(ITokVisitorCmd defaultCmd)
    Constructor that sets the default cmd to the given command.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add a new cmd or replace an existing cmd associated with the given host id.
    caseAt​(String id, Token host, Object... params)
    Delegates to the ITokVisitorCmd associated with the given host id (name), or if nothing is associated with the id, use the default cmd.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • defaultCmd

      private ITokVisitorCmd defaultCmd
      The default command to use if there are no command associated with the given host id.
    • cmds

      private Map<String,​ITokVisitorCmd> cmds
      The dictionary mapping token id's (names) to associated commands. Implemented using a hast table.
  • Constructor Details

    • ATokVisitor

      public ATokVisitor()
      Constructor that sets the default cmd to one that throws and IllegalArgumentException" for any unknown tokens.
    • ATokVisitor

      public ATokVisitor(ITokVisitorCmd defaultCmd)
      Constructor that sets the default cmd to the given command.
      Parameters:
      defaultCmd - the default cmd to use.
  • Method Details

    • caseAt

      public Object caseAt(String id, Token host, Object... params)
      Delegates to the ITokVisitorCmd associated with the given host id (name), or if nothing is associated with the id, use the default cmd.
      Specified by:
      caseAt in interface ITokVisitor
      Parameters:
      id - the name of the host Token
      host - the host token itself.
      params - vararg list of input parameters that the processing might need.
      Returns:
      the result of the delegation to the associated cmd.
    • addCmd

      public void addCmd(String id, ITokVisitorCmd cmd)
      Add a new cmd or replace an existing cmd associated with the given host id.
      Parameters:
      id - the id of the host to associate with this visitor.
      cmd - The command to associate with the given key value.