Class ChangedField

java.lang.Object
org.litebridge.tracking.ChangedField
Direct Known Subclasses:
ChangedCollectionField, ChangedMapField

public sealed class ChangedField extends Object permits ChangedCollectionField, ChangedMapField
A field which has undergone a change.

This is a sealed class that can be extended by specific implementations to handle particular types of field changes.

The class stores the name of the changed field and its value, and provides utilities for accessing and comparing these fields.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    The name of the field that has changed.
    protected final @Nullable Object
    The current value of the field that has changed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChangedField(String name, @Nullable Object value)
    Construct a new instance of ChangedField, representing a change in a specific field.
  • Method Summary

    Modifier and Type
    Method
    Description
    final <T extends ChangedField>
    Optional<T>
    cast(Class<T> changedFieldType)
    Attempts to cast this ChangedField instance to a specific subtype.
    boolean
    equals(@Nullable Object obj)
     
    int
     
    Retrieve the name of the field that has changed.
     
    @Nullable Object
    Retrieve the current value of the field that has changed.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      protected final String name
      The name of the field that has changed.
    • value

      protected final @Nullable Object value
      The current value of the field that has changed.
  • Constructor Details

    • ChangedField

      public ChangedField(String name, @Nullable Object value)
      Construct a new instance of ChangedField, representing a change in a specific field.
      Parameters:
      name - the name of the field that has changed; must not be null
      value - the current value of the field that has changed; may be null
  • Method Details

    • name

      public String name()
      Retrieve the name of the field that has changed.
      Returns:
      the name of the changed field
    • value

      public @Nullable Object value()
      Retrieve the current value of the field that has changed.
      Returns:
      the current value of the changed field, which may be null
    • cast

      public final <T extends ChangedField> Optional<T> cast(Class<T> changedFieldType)
      Attempts to cast this ChangedField instance to a specific subtype. This provides a convenient type-safe way to cast the field to a specific subtype if it known beforehand.

      If the cast is possible, the corresponding subtype instance is returned wrapped in an Optional. If the cast fails, an empty Optional is returned.

      Type Parameters:
      T - the type of the desired subtype of ChangedField
      Parameters:
      changedFieldType - the Class object representing the desired subtype
      Returns:
      an Optional containing the casted instance if the cast is successful, or an empty Optional if the cast fails
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object