Record Class DataTypeField.OptionalField<C,T>

java.lang.Object
java.lang.Record
dev.latvian.mods.klib.data.DataTypeField.OptionalField<C,T>
All Implemented Interfaces:
DataTypeField<C,Optional<T>>
Enclosing interface:
DataTypeField<C,T>

public static record DataTypeField.OptionalField<C,T>(DataType<T> type, String name, Function<C,Optional<T>> getter) extends Record implements DataTypeField<C,Optional<T>>
  • Constructor Details

    • OptionalField

      public OptionalField(DataType<T> type, String name, Function<C,Optional<T>> getter)
      Creates an instance of a OptionalField record class.
      Parameters:
      type - the value for the type record component
      name - the value for the name record component
      getter - the value for the getter record component
  • Method Details

    • typeClass

      public Class<Optional<T>> typeClass()
      Specified by:
      typeClass in interface DataTypeField<C,T>
    • get

      @Nullable public @Nullable Optional<T> get(C input)
      Specified by:
      get in interface DataTypeField<C,T>
    • canBeOptional

      public boolean canBeOptional()
      Specified by:
      canBeOptional in interface DataTypeField<C,T>
    • shouldEncode

      public boolean shouldEncode(Optional<T> value)
      Specified by:
      shouldEncode in interface DataTypeField<C,T>
    • encode

      public <O> void encode(com.mojang.serialization.DynamicOps<O> ops, com.mojang.serialization.RecordBuilder<O> builder, Optional<T> value)
      Specified by:
      encode in interface DataTypeField<C,T>
    • decode

      public <O> com.mojang.serialization.DataResult<Optional<T>> decode(com.mojang.serialization.DynamicOps<O> ops, @Nullable O value)
      Specified by:
      decode in interface DataTypeField<C,T>
    • encode

      public void encode(io.netty.buffer.ByteBuf buf, Optional<T> value)
      Specified by:
      encode in interface DataTypeField<C,T>
    • decode

      public Optional<T> decode(io.netty.buffer.ByteBuf buf, boolean present)
      Specified by:
      decode in interface DataTypeField<C,T>
    • 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.
    • type

      public DataType<T> type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • name

      public String name()
      Returns the value of the name record component.
      Specified by:
      name in interface DataTypeField<C,T>
      Returns:
      the value of the name record component
    • getter

      public Function<C,Optional<T>> getter()
      Returns the value of the getter record component.
      Returns:
      the value of the getter record component