Record Class DispatchedMapCodec<K,V>

java.lang.Object
java.lang.Record
com.mojang.serialization.codecs.DispatchedMapCodec<K,V>
All Implemented Interfaces:
Codec<Map<K,V>>, Decoder<Map<K,V>>, Encoder<Map<K,V>>

public record DispatchedMapCodec<K,V>(Codec<K> keyCodec, Function<K, Codec<? extends V>> valueCodecFunction) extends Record implements Codec<Map<K,V>>
  • Field Details

    • keyCodec

      private final Codec<K> keyCodec
      The field for the keyCodec record component.
    • valueCodecFunction

      private final Function<K, Codec<? extends V>> valueCodecFunction
      The field for the valueCodecFunction record component.
  • Constructor Details

    • DispatchedMapCodec

      public DispatchedMapCodec(Codec<K> keyCodec, Function<K, Codec<? extends V>> valueCodecFunction)
      Creates an instance of a DispatchedMapCodec record class.
      Parameters:
      keyCodec - the value for the keyCodec record component
      valueCodecFunction - the value for the valueCodecFunction record component
  • Method Details

    • encode

      public <T> DataResult<T> encode(Map<K,V> input, DynamicOps<T> ops, T prefix)
      Specified by:
      encode in interface Encoder<K>
    • encodeValue

      private <T, V2 extends V> DataResult<T> encodeValue(Codec<V2> codec, V input, DynamicOps<T> ops)
    • decode

      public <T> DataResult<Pair<Map<K,V>,T>> decode(DynamicOps<T> ops, T input)
      Specified by:
      decode in interface Decoder<K>
    • parseEntry

      private <T> DataResult<Unit> parseEntry(DataResult<Unit> result, DynamicOps<T> ops, Pair<T,T> input, Map<K,V> entries, Stream.Builder<Pair<T,T>> failed)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • keyCodec

      public Codec<K> keyCodec()
      Returns the value of the keyCodec record component.
      Returns:
      the value of the keyCodec record component
    • valueCodecFunction

      public Function<K, Codec<? extends V>> valueCodecFunction()
      Returns the value of the valueCodecFunction record component.
      Returns:
      the value of the valueCodecFunction record component