Class Tag<T>

java.lang.Object
de.pauleff.core.Tag<T>
Type Parameters:
T - the data type stored within this tag
All Implemented Interfaces:
ITag<T>
Direct Known Subclasses:
Basic_Tag, Collection_Tag

public abstract class Tag<T> extends Object implements ITag<T>
Foundation class for all NBT tags, providing core functionality for data storage, identification, and manipulation within the NBT hierarchy.

Each tag maintains a unique identifier, optional name, and typed data payload. Tags support fluent operations, equality checking, and custom transformations.

Author:
Paul Ferlitz
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected T
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tag(int id)
    Creates a new tag with the specified NBT type identifier.
    Tag(int id, String name)
    Creates a new named tag with the specified NBT type identifier.
    Tag(int id, String name, T data)
    Creates a new tag with complete initialization.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Applies a custom transformation or operation to this tag.
    void
    editTag(ITag<?> newTag)
    Replaces this tag's content with data from another compatible tag.
    boolean
    Determines equality based on tag ID, name, and data content.
    Returns the data payload stored within this tag.
    int
    Returns the NBT type identifier for this tag.
    Returns the name assigned to this tag.
    int
     
    void
    setData(T data)
    Updates the data payload with type validation.
    void
    Updates the name assigned to this tag.
    Generates a human-readable representation showing tag type, name, and data.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • data

      protected T data
  • Constructor Details

    • Tag

      public Tag(int id)
      Creates a new tag with the specified NBT type identifier.
      Parameters:
      id - the NBT type identifier
      Throws:
      IllegalArgumentException - if the ID is not a valid NBT tag type
    • Tag

      public Tag(int id, String name)
      Creates a new named tag with the specified NBT type identifier.
      Parameters:
      id - the NBT type identifier
      name - the tag name (null or empty becomes "null")
      Throws:
      IllegalArgumentException - if the ID is not a valid NBT tag type
    • Tag

      public Tag(int id, String name, T data)
      Creates a new tag with complete initialization.
      Parameters:
      id - the NBT type identifier
      name - the tag name (null or empty becomes "null")
      data - the initial payload for this tag
      Throws:
      IllegalArgumentException - if the ID is not a valid NBT tag type
  • Method Details

    • getId

      public int getId()
      Returns the NBT type identifier for this tag.
      Specified by:
      getId in interface ITag<T>
      Returns:
      the NBT type ID
    • getName

      public String getName()
      Returns the name assigned to this tag.
      Specified by:
      getName in interface ITag<T>
      Returns:
      the tag name (never null)
    • setName

      public void setName(String name)
      Updates the name assigned to this tag.
      Specified by:
      setName in interface ITag<T>
      Parameters:
      name - the new tag name (null or empty becomes "null")
    • getData

      public T getData()
      Returns the data payload stored within this tag.
      Specified by:
      getData in interface ITag<T>
      Returns:
      the tag's data content
    • setData

      public void setData(T data)
      Updates the data payload with type validation.
      Specified by:
      setData in interface ITag<T>
      Parameters:
      data - the new data content
      Throws:
      IllegalArgumentException - if the data type doesn't match the existing type
    • editTag

      public void editTag(ITag<?> newTag)
      Replaces this tag's content with data from another compatible tag.
      Specified by:
      editTag in interface ITag<T>
      Parameters:
      newTag - the source tag to copy from
      Throws:
      IllegalArgumentException - if tag types don't match
      See Also:
    • applyOperation

      public void applyOperation(Consumer<ITag<T>> operation)
      Applies a custom transformation or operation to this tag.

      Enables functional-style tag manipulation and processing.

      Specified by:
      applyOperation in interface ITag<T>
      Parameters:
      operation - the operation to execute on this tag
    • equals

      public boolean equals(Object obj)
      Determines equality based on tag ID, name, and data content.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare against
      Returns:
      true if tags are equivalent in all aspects
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Generates a human-readable representation showing tag type, name, and data.
      Specified by:
      toString in interface ITag<T>
      Overrides:
      toString in class Object
      Returns:
      formatted string representation