Class TaggedArgUtil

java.lang.Object
com.j3d.engine.interact.cmd.args.TaggedArgUtil

public class TaggedArgUtil extends Object
A utility class for parsing and managing "tagged arguments" within the command system.

Tagged arguments are a special type of key-value pair (e.g., x:10.5, type:"point") that provide optional, out-of-order parameters to commands. This class defines the globally accepted tags and provides the logic to parse them from a raw string.

The Role of Tagged Arguments

Unlike standard positional arguments, tagged arguments are not defined as part of a command's formal argument list. Instead, the CommandParser identifies and extracts them from the user's input string, providing them to the command in a separate collection.

This means tagged arguments can appear anywhere in the command string after the command name, interspersed with normal arguments, without affecting the order of the normal arguments. For example, the following two inputs are parsed identically:


 > point at x:4 10 y:5
 > point y:5 at x:4 10

 // Both result in:
 Command: "point"
 Arguments: ["at", 10]
 TaggedArgs: [x:4, y:5]
 
By default, all commands can accept a variadic number of tagged arguments, though a command's specific run method determines which ones it actually uses.

Accepted Tags

This utility defines a static map of all valid tags and their expected data types:
  • type: String - e.g., "point", "line"
  • layer: String - e.g., "default", "background"
  • x, y, z: Double - Coordinates
  • v: Vector3 - e.g., (0, 0, 1)
  • ...and others for IDs, booleans, and comparisons.
Author:
Lehlogonolo Poole
See Also:
  • Field Details

  • Constructor Details

    • TaggedArgUtil

      public TaggedArgUtil()
  • Method Details

    • getTaggedArg

      public static <T> TaggedArgValue<T> getTaggedArg(ArrayList<TaggedArgValue<?>> argValues, String name, Class<T> expected)
    • parse

      public static TaggedArgValue<?> parse(String accumulator, boolean errorToLabel, SafeJLabel label)
      Parses a single string segment to identify and create a tagged argument.

      This method attempts to parse a string in the format "key:value" or "key=value". It validates the key against the acceptedTags map and attempts to parse the value into the expected type (e.g., number, boolean, quoted string, Vector3).

      Parameters:
      accumulator - The raw string segment to parse.
      errorToLabel - A boolean to log errors to the SafeJLabel
      label - A SafeJLabel for providing user feedback on parsing errors. If errorToLabel is false, then this can have a null input.
      Returns:
      A populated TaggedArgValue instance. If parsing fails, the instance will be marked as an error or empty.