Class Collection_Tag

java.lang.Object
de.pauleff.core.Tag<ArrayList<Tag<?>>>
de.pauleff.core.Collection_Tag
All Implemented Interfaces:
ITag<ArrayList<Tag<?>>>
Direct Known Subclasses:
Tag_Compound, Tag_List

public class Collection_Tag extends Tag<ArrayList<Tag<?>>>
Abstract base class for NBT tags that contain collections of other tags.

Provides comprehensive functionality for managing child tags including addition, removal, and retrieval operations. Supports both name-based and object-based lookups with optional recursive searching.

Implements fluent API patterns for method chaining and offers specialized handling for different collection types (compounds vs. lists).

See Also:
  • Constructor Details

    • Collection_Tag

      public Collection_Tag(int id)
      Creates a collection tag with the specified NBT type identifier. Initializes with an empty ArrayList for child tags.
      Parameters:
      id - the NBT type identifier
    • Collection_Tag

      public Collection_Tag(int id, String name)
      Creates a named collection tag with the specified NBT type identifier. Initializes with an empty ArrayList for child tags.
      Parameters:
      id - the NBT type identifier
      name - the tag name
    • Collection_Tag

      public Collection_Tag(int id, String name, ArrayList<Tag<?>> data)
      Creates a collection tag pre-populated with child tags.
      Parameters:
      id - the NBT type identifier
      name - the tag name (null or empty becomes "null")
      data - the initial collection of child tags
  • Method Details

    • addTag

      public Collection_Tag addTag(ITag<?> tag)
      Adds a child tag to this collection with type validation.

      For lists, validates that the new tag matches the declared list type. Compounds accept any tag type.

      Parameters:
      tag - the tag to add
      Returns:
      this collection tag for method chaining
      Throws:
      IllegalArgumentException - if adding incompatible type to a list
      See Also:
    • addAllTags

      public Collection_Tag addAllTags(List<Tag<?>> tags)
      Adds multiple child tags to this collection with batch type validation.

      For lists, validates that all new tags match the declared list type before adding any elements.

      Parameters:
      tags - the collection of tags to add
      Returns:
      this collection tag for method chaining
      Throws:
      IllegalArgumentException - if any tag is incompatible with list type
      See Also:
    • getAllTagsByName

      public List<Tag<?>> getAllTagsByName(String name)
      Finds all tags with the specified name, including nested matches.

      Performs recursive search through all collection descendants.

      Parameters:
      name - the tag name to search for
      Returns:
      list of matching tags (empty if none found)
      See Also:
    • getTagByName

      public Tag<?> getTagByName(String name)
      Finds the first tag with the specified name, including nested search.

      Returns immediately upon finding the first match during traversal.

      Parameters:
      name - the tag name to search for
      Returns:
      the first matching tag, or null if not found
      See Also:
    • getAllTags

      public List<Tag<?>> getAllTags(Tag<?> targetTag)
      Finds all tags that are equal to the specified target tag.

      Uses Tag.equals(Object) for comparison and searches recursively.

      Parameters:
      targetTag - the tag to match against
      Returns:
      list of equal tags (empty if none found)
      See Also:
    • getTag

      public Tag<?> getTag(Tag<?> targetTag)
      Finds the first tag that equals the specified target tag.

      Returns immediately upon finding the first match during traversal.

      Parameters:
      targetTag - the tag to match against
      Returns:
      the first equal tag, or null if not found
      See Also:
    • removeAllTagsByName

      public void removeAllTagsByName(String name)
      Removes all tags with the specified name from this collection and descendants.

      Performs recursive removal through all nested collections.

      Parameters:
      name - the tag name to remove
      See Also:
    • removeTagByName

      public Collection_Tag removeTagByName(String name)
      Removes the first tag with the specified name and returns this collection.

      Stops after removing the first match found during traversal.

      Parameters:
      name - the tag name to remove
      Returns:
      this collection tag for method chaining
      See Also:
    • removeAllTags

      public void removeAllTags(Tag<?> targetTag)
      Removes all tags equal to the specified target from this collection and descendants.

      Uses Tag.equals(Object) for comparison and removes recursively.

      Parameters:
      targetTag - the tag to remove
      See Also:
    • removeTag

      public Collection_Tag removeTag(Tag<?> targetTag)
      Removes the first tag equal to the specified target and returns this collection.

      Stops after removing the first match found during traversal.

      Parameters:
      targetTag - the tag to remove
      Returns:
      this collection tag for method chaining
      See Also: