Class TaggedArgValue<T>

java.lang.Object
com.j3d.engine.interact.cmd.args.TaggedArgValue<T>
Type Parameters:
T - The expected type of the argument's value.

public class TaggedArgValue<T> extends Object
Represents an instance of a parsed tagged argument, holding its name, its value, and its expected type.

This class serves as the data container for a single key-value pair identified by the TaggedArgUtil. An ArrayList of these objects is passed to a command's run method for processing.

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • taggedArgName

      public String taggedArgName
    • value

      public T value
    • type

      public Class<?> type
    • isEmpty

      private boolean isEmpty
    • err

      private boolean err
  • Constructor Details

    • TaggedArgValue

      public TaggedArgValue(T v)
    • TaggedArgValue

      public TaggedArgValue(Class<?> type)
      Constructs a shell for a tagged argument, defining its expected type. This is used to populate the TaggedArgUtil.acceptedTags map.
      Parameters:
      type - The Class of the value this tag expects.
  • Method Details

    • setName

      public TaggedArgValue<T> setName(String name)
      Sets the name for this tagged argument.
      Parameters:
      name - The tag's name (the "key" in the key-value pair).
      Returns:
      This instance for method chaining.
    • error

      public TaggedArgValue<T> error()
      Marks this tagged argument instance as having a parsing error.
      Returns:
      This instance for method chaining.
    • setType

      public TaggedArgValue<T> setType(Class<?> clazz)
      Sets the expected type for this tagged argument.
      Parameters:
      clazz - The Class of the value.
      Returns:
      This instance for method chaining.
    • copy

      public TaggedArgValue<?> copy(Object val, boolean errorToLabel, SafeJLabel label)
      Creates a new, populated instance of a TaggedArgValue with a parsed value.

      This method validates that the provided value's type matches the expected type for this tag.

      Parameters:
      val - The parsed value object.
      errorToLabel - A boolean to log errors to the SafeJLabel
      label - A SafeJLabel for reporting type mismatch errors.
      Returns:
      A new, populated TaggedArgValue instance, or an error-marked instance if types are incompatible.
    • isEmpty

      public boolean isEmpty()
      Checks if this instance is an un-parsed shell.
      Returns:
      true if the instance is empty, false otherwise.
    • isErr

      public boolean isErr()
      Checks if a parsing error occurred while creating this instance.
      Returns:
      true if an error was flagged, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object