Interface CompoundBinaryTag

All Superinterfaces:
BinaryTag, BinaryTagLike, CompoundTagSetter<CompoundBinaryTag>, Iterable<Map.Entry<String, ? extends BinaryTag>>

public sealed interface CompoundBinaryTag extends BinaryTag, CompoundTagSetter<CompoundBinaryTag>, Iterable<Map.Entry<String, ? extends BinaryTag>>
Binary tag holding a mapping of string keys to BinaryTag values.
Since:
4.0.0
  • Method Details

    • empty

      static CompoundBinaryTag empty()
      Gets an empty compound tag.
      Returns:
      an empty tag
      Since:
      4.0.0
    • from

      static CompoundBinaryTag from(Map<String, ? extends BinaryTag> tags)
      Creates a compound tag populated with tags.

      If tags is empty, empty() will be returned.

      Parameters:
      tags - the map of contents for the created tag
      Returns:
      a compound tag
      Since:
      4.4.0
    • toCompoundTag

      static Collector<Map.Entry<String, ? extends BinaryTag>, ?, CompoundBinaryTag> toCompoundTag()
      Create a Collector to consume streams of map entries.

      In the event of duplicate entries, the last seen entry will be preserved.

      Returns:
      a collector for map entries
      Since:
      4.21.0
    • toCompoundTag

      static <T> Collector<T, ?, CompoundBinaryTag> toCompoundTag(Function<T,String> keyLens, Function<T, ? extends BinaryTag> valueLens)
      Create a Collector to consume streams of a user-chosen type.

      In the event of duplicate keys, the last seen entry will be preserved.

      Type Parameters:
      T - the stream value type
      Parameters:
      keyLens - a function to extract a key from the target object
      valueLens - a function to extract a tag value from the target object
      Returns:
      a collector creating compound tags
      Since:
      4.21.0
    • toCompoundTag

      static Collector<Map.Entry<String, ? extends BinaryTag>, ?, CompoundBinaryTag> toCompoundTag(CompoundBinaryTag initial)
      Create a Collector to consume streams of map entries, with initial contents.

      In the event of duplicate entries, the last seen entry will be preserved.

      Parameters:
      initial - an existing tag that will initialize the builder
      Returns:
      a collector for map entries
      Since:
      4.21.0
    • toCompoundTag

      static <T> Collector<T, ?, CompoundBinaryTag> toCompoundTag(CompoundBinaryTag initial, Function<T,String> keyLens, Function<T, ? extends BinaryTag> valueLens)
      Create a Collector to consume streams of a user-chosen type, with initial contents.

      In the event of duplicate keys, the last seen entry will be preserved.

      Type Parameters:
      T - the stream value type
      Parameters:
      initial - an existing tag that will initialize the builder
      keyLens - a function to extract a key from the target object
      valueLens - a function to extract a tag value from the target object
      Returns:
      a collector creating compound tags
      Since:
      4.21.0
    • builder

      static CompoundBinaryTag.Builder builder()
      Creates a builder.
      Returns:
      a new builder
      Since:
      4.0.0
    • builder

      static CompoundBinaryTag.Builder builder(@Range(from=0L,to=2147483647L) int initialCapacity)
      Creates a builder with the specified initial capacity.
      Parameters:
      initialCapacity - the initial capacity
      Returns:
      a new builder
      Since:
      4.25.0
    • type

      Description copied from interface: BinaryTag
      Gets the tag type.
      Specified by:
      type in interface BinaryTag
      Returns:
      the tag type
    • contains

      boolean contains(String key)
      Returns whether the compound contains a specific key.
      Parameters:
      key - the key to check for
      Returns:
      whether the compound contains the key
      Since:
      4.25.0
    • contains

      boolean contains(String key, BinaryTagType<?> type)
      Returns whether the compound contains a tag of a specific type with a key.
      Parameters:
      key - the key to check for
      type - the type to check for
      Returns:
      whether there is a tag of type with key
      Since:
      4.25.0
    • keySet

      Set<String> keySet()
      Gets a set of all keys.
      Returns:
      the keys
      Since:
      4.0.0
    • get

      @Nullable BinaryTag get(String key)
      Gets a tag.
      Parameters:
      key - the key
      Returns:
      a tag
      Since:
      4.0.0
    • size

      int size()
      Gets the number of elements in the compound.
      Returns:
      the number of elements in the compound
      Since:
      4.15.0
    • isEmpty

      boolean isEmpty()
      Returns whether the compound has tags or not.
      Returns:
      false if the compound has tags
      Since:
      4.18.0
    • getBoolean

      default boolean getBoolean(String key)
      Gets a boolean.

      Booleans are stored as a ByteBinaryTag with a value of 0 for false and 1 for true.

      Parameters:
      key - the key
      Returns:
      the boolean value, or false if this compound does not contain a boolean tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getBoolean

      default boolean getBoolean(String key, boolean defaultValue)
      Gets a boolean.

      Booleans are stored as a ByteBinaryTag with a value of 0 for false and 1 for true.

      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the boolean value, or defaultValue if this compound does not contain a boolean tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getByte

      default byte getByte(String key)
      Gets a byte.
      Parameters:
      key - the key
      Returns:
      the byte value, or 0 if this compound does not contain a byte tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getByte

      byte getByte(String key, byte defaultValue)
      Gets a byte.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the byte value, or defaultValue if this compound does not contain a byte tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getShort

      default short getShort(String key)
      Gets a short.
      Parameters:
      key - the key
      Returns:
      the short value, or 0 if this compound does not contain a short tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getShort

      short getShort(String key, short defaultValue)
      Gets a short.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the short value, or defaultValue if this compound does not contain a short tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getInt

      default int getInt(String key)
      Gets an int.
      Parameters:
      key - the key
      Returns:
      the int value, or 0 if this compound does not contain an int tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getInt

      int getInt(String key, int defaultValue)
      Gets an int.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the int value, or defaultValue if this compound does not contain an int tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getLong

      default long getLong(String key)
      Gets a long.
      Parameters:
      key - the key
      Returns:
      the long value, or 0 if this compound does not contain a long tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getLong

      long getLong(String key, long defaultValue)
      Gets a long.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the long value, or defaultValue if this compound does not contain a long tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getFloat

      default float getFloat(String key)
      Gets a float.
      Parameters:
      key - the key
      Returns:
      the float value, or 0 if this compound does not contain a float tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getFloat

      float getFloat(String key, float defaultValue)
      Gets a float.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the float value, or defaultValue if this compound does not contain a float tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getDouble

      default double getDouble(String key)
      Gets a double.
      Parameters:
      key - the key
      Returns:
      the double value, or 0 if this compound does not contain a double tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getDouble

      double getDouble(String key, double defaultValue)
      Gets a double.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the double value, or defaultValue if this compound does not contain a double tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getByteArray

      byte[] getByteArray(String key)
      Gets an array of bytes.
      Parameters:
      key - the key
      Returns:
      the array of bytes, or a zero-length array if this compound does not contain a byte array tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getByteArray

      @Contract("_, !null -> !null") byte @Nullable [] getByteArray(String key, byte @Nullable [] defaultValue)
      Gets an array of bytes.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the array of bytes, or defaultValue
      Since:
      4.0.0
    • getString

      default String getString(String key)
      Gets a string.
      Parameters:
      key - the key
      Returns:
      the string value, or "" if this compound does not contain a string tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getString

      @Contract("_, !null -> !null") @Nullable String getString(String key, @Nullable String defaultValue)
      Gets a string.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the string value, or defaultValue if this compound does not contain a string tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getList

      default ListBinaryTag getList(String key)
      Gets a list.
      Parameters:
      key - the key
      Returns:
      the list, or a new list if this compound does not contain a list tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getList

      @Contract("_, !null -> !null") @Nullable ListBinaryTag getList(String key, @Nullable ListBinaryTag defaultValue)
      Gets a list.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the list, or defaultValue if this compound does not contain a list tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getList

      default ListBinaryTag getList(String key, BinaryTagType<? extends BinaryTag> expectedType)
      Gets a list, ensuring that the type is the same as type.
      Parameters:
      key - the key
      expectedType - the expected list type
      Returns:
      the list, or a new list if this compound does not contain a list tag with the specified key, has a tag with a different type, or the list type does not match expectedType
      Since:
      4.0.0
    • getList

      @Contract("_, _, !null -> !null") @Nullable ListBinaryTag getList(String key, BinaryTagType<? extends BinaryTag> expectedType, @Nullable ListBinaryTag defaultValue)
      Gets a list, ensuring that the type is the same as type.
      Parameters:
      key - the key
      expectedType - the expected list type
      defaultValue - the default value
      Returns:
      the list, or defaultValue if this compound does not contain a list tag with the specified key, has a tag with a different type, or the list type does not match expectedType
      Since:
      4.0.0
    • getCompound

      default CompoundBinaryTag getCompound(String key)
      Gets a compound.
      Parameters:
      key - the key
      Returns:
      the compound, or a new compound if this compound does not contain a compound tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getCompound

      @Contract("_, !null -> !null") @Nullable CompoundBinaryTag getCompound(String key, @Nullable CompoundBinaryTag defaultValue)
      Gets a compound.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the compound, or defaultValue if this compound does not contain a compound tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getIntArray

      int[] getIntArray(String key)
      Gets an array of ints.
      Parameters:
      key - the key
      Returns:
      the array of ints, or a zero-length array if this compound does not contain a int array tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getIntArray

      @Contract("_, !null -> !null") int @Nullable [] getIntArray(String key, int @Nullable [] defaultValue)
      Gets an array of ints.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the array of ints, or defaultValue
      Since:
      4.0.0
    • getLongArray

      long[] getLongArray(String key)
      Gets an array of longs.
      Parameters:
      key - the key
      Returns:
      the array of longs, or a zero-length array if this compound does not contain a long array tag with the specified key, or has a tag with a different type
      Since:
      4.0.0
    • getLongArray

      @Contract("_, !null -> !null") long @Nullable [] getLongArray(String key, long @Nullable [] defaultValue)
      Gets an array of longs.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the array of longs, or defaultValue
      Since:
      4.0.0
    • stream

      Stream<Map.Entry<String, ? extends BinaryTag>> stream()
      Gets a stream of entries in this compound tag.
      Returns:
      a new entry stream
      Since:
      4.21.0