Class CmdToken

java.lang.Object
com.j3d.engine.interact.cmd.CmdToken

public class CmdToken extends Object
Represents a token parsed from a command string. Each token holds its original string input and, once parsed, its interpreted type and value.
Author:
Lehlogonolo Poole
See Also:
  • Field Details

  • Constructor Details

    • CmdToken

      public CmdToken(String input)
      Constructs a new CmdToken with the given input string.
      Parameters:
      input - The raw string input for this token.
  • Method Details

    • toStr

      public static String toStr(ArrayList<CmdToken> tokens)
      Converts a list of CmdToken objects back into a single space-separated string.
      Parameters:
      tokens - An ArrayList of CmdToken objects.
      Returns:
      A string representation of the tokens, joined by spaces.
    • toStr

      public static String toStr(Object[] arr)
      Converts a list of objects back into a single space-separated string.
      Parameters:
      arr - An array objects.
      Returns:
      A string representation of the objects, joined by spaces.
    • parsedAs

      public void parsedAs(Object o, CmdToken.Type t)
      Sets the parsed value and type of this token. This method is typically called after the token's input string has been successfully interpreted into a specific data type.
      Parameters:
      o - The parsed object value.
      t - The type of the parsed value.
    • getParsedValue

      public Object getParsedValue()
      Returns the parsed value of this token. The caller is responsible for casting this Object to the correct type based on getType().
      Returns:
      The parsed value as an Object, or null if not yet parsed.
    • getInput

      public String getInput()
      Returns the original raw string input of this token.
      Returns:
      The original input string.
    • getType

      public CmdToken.Type getType()
      Returns the interpreted type of this token.
      Returns:
      The CmdToken.Type enum constant representing the token's type, or null if not yet parsed.
    • toString

      public String toString()
      Returns the original input string of this token. This is a convenience method, equivalent to getInput().
      Overrides:
      toString in class Object
      Returns:
      The original input string.