Record Class ContextualListCodec<CONTEXT,E>

java.lang.Object
java.lang.Record
com.petrolpark.core.codec.ContextualListCodec<CONTEXT,E>
All Implemented Interfaces:
ContextualCodec<CONTEXT,List<E>>, ContextualDecoder<CONTEXT,List<E>>, ContextualEncoder<CONTEXT,List<E>>

public record ContextualListCodec<CONTEXT,E>(ContextualCodec<CONTEXT,E> elementCodec, int minSize, int maxSize) extends Record implements ContextualCodec<CONTEXT,List<E>>
Copy of ListCodec that accepts a context object when encoding and decoding
  • Constructor Details

    • ContextualListCodec

      public ContextualListCodec(ContextualCodec<CONTEXT,E> elementCodec, int minSize, int maxSize)
      Creates an instance of a ContextualListCodec record class.
      Parameters:
      elementCodec - the value for the elementCodec record component
      minSize - the value for the minSize record component
      maxSize - the value for the maxSize record component
  • Method Details

    • encode

      public <T> com.mojang.serialization.DataResult<T> encode(List<E> input, CONTEXT context, com.mojang.serialization.DynamicOps<T> ops, T prefix)
      Specified by:
      encode in interface ContextualEncoder<CONTEXT,E>
    • decode

      public <T> com.mojang.serialization.DataResult<com.mojang.datafixers.util.Pair<List<E>,T>> decode(com.mojang.serialization.DynamicOps<T> ops, CONTEXT context, T input)
      Specified by:
      decode in interface ContextualDecoder<CONTEXT,E>
    • toString

      public 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • elementCodec

      public ContextualCodec<CONTEXT,E> elementCodec()
      Returns the value of the elementCodec record component.
      Returns:
      the value of the elementCodec record component
    • minSize

      public int minSize()
      Returns the value of the minSize record component.
      Returns:
      the value of the minSize record component
    • maxSize

      public int maxSize()
      Returns the value of the maxSize record component.
      Returns:
      the value of the maxSize record component