Class ChangedField

java.lang.Object
org.litebridgedb.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 Details

    • name

      protected final String name
    • value

      protected final @Nullable Object value
  • 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