Class TaggedArgUtil
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, theCommandParser 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- Coordinatesv: Vector3- e.g., (0, 0, 1)- ...and others for IDs, booleans, and comparisons.
- Author:
- Lehlogonolo Poole
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HashMap<String, TaggedArgValue<?>> A map defining all globally accepted tags and their corresponding typedTaggedArgValueshells. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TaggedArgValue<T> getTaggedArg(ArrayList<TaggedArgValue<?>> argValues, String name, Class<T> expected) static TaggedArgValue<?> parse(String accumulator, boolean errorToLabel, SafeJLabel label) Parses a single string segment to identify and create a tagged argument.
-
Field Details
-
acceptedTags
A map defining all globally accepted tags and their corresponding typedTaggedArgValueshells.
-
-
Constructor Details
-
TaggedArgUtil
public TaggedArgUtil()
-
-
Method Details
-
getTaggedArg
public static <T> TaggedArgValue<T> getTaggedArg(ArrayList<TaggedArgValue<?>> argValues, String name, Class<T> expected) -
parse
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
acceptedTagsmap 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 SafeJLabellabel- ASafeJLabelfor providing user feedback on parsing errors. IferrorToLabelis false, then this can have a null input.- Returns:
- A populated
TaggedArgValueinstance. If parsing fails, the instance will be marked as an error or empty.
-