Class APhraseVisitor

java.lang.Object
provided.music.APhraseVisitor
All Implemented Interfaces:
IPhraseVisitor

public abstract class APhraseVisitor
extends java.lang.Object
implements IPhraseVisitor
Command-based implementation of IPhraseVisitor that uses IPhraseVisitorCmds stored in a hash table.
Author:
swong
  • Constructor Summary

    Constructors 
    Constructor Description
    APhraseVisitor()
    Constructor that installs a default cmd that throws an IllegalArgumentException on any unknown host.
    APhraseVisitor​(IPhraseVisitorCmd defaultCmd)
    Constructor that sets the default cmd to the supplied cmd.
  • Method Summary

    Modifier and Type Method Description
    void addCmd​(java.lang.String id, IPhraseVisitorCmd cmd)
    Add the given command to the dictionary, associated with the given id value.
    java.lang.Object caseAt​(java.lang.String id, IPhrase host, java.lang.Object... params)
    Runs the command associated with the given id, passing along the given host and vararg parameters.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • APhraseVisitor

      public APhraseVisitor()
      Constructor that installs a default cmd that throws an IllegalArgumentException on any unknown host. * ---------------------------------------------- Abstract extended visitor implementation that uses a dictionary of commands to associate commands with host IDs.
    • APhraseVisitor

      public APhraseVisitor​(IPhraseVisitorCmd defaultCmd)
      Constructor that sets the default cmd to the supplied cmd.
      Parameters:
      defaultCmd - the default cmd to use.
  • Method Details

    • caseAt

      public java.lang.Object caseAt​(java.lang.String id, IPhrase host, java.lang.Object... params)
      Runs the command associated with the given id, passing along the given host and vararg parameters. If there is no cmd associated with the given id in the dictionary, then use the default cmd.
      Specified by:
      caseAt in interface IPhraseVisitor
      Parameters:
      id - The ID value that identifies the host
      host - The host IPhrase object
      params - vararg list of parameters that might be used. Can be called with no input params.
      Returns:
      the result of executing the associated cmd.
    • addCmd

      public void addCmd​(java.lang.String id, IPhraseVisitorCmd cmd)
      Add the given command to the dictionary, associated with the given id value.
      Parameters:
      id - The id of the host that will use this command
      cmd - The command that will be run when the host calls for it.