Class ChangedFields

java.lang.Object
org.litebridgedb.tracking.ChangedFields

public final class ChangedFields extends Object
A collection of modified fields in a DTO, since the last snapshot.

This class is designed to be immutable and provides various methods to query and operate on the collection of changed fields.

  • Constructor Details

    • ChangedFields

      public ChangedFields(Map<String,ChangedField> changedFieldMap)
      Construct a new ChangedFields instance with the provided map of changed fields.

      The map is expected to contain field names as keys and corresponding ChangedField objects representing the modified fields as values. The map is made immutable.

      Parameters:
      changedFieldMap - a map where keys represent field names and values represent ChangedField objects; the map cannot be null
      Throws:
      IllegalArgumentException - if changedFieldMap is null
  • Method Details

    • get

      public Optional<ChangedField> get(String fieldName)
      Retrieve an Optional containing the ChangedField associated with the specified field name.

      If no such field exists, an empty Optional is returned.

      Parameters:
      fieldName - the name of the field to retrieve; must not be null
      Returns:
      an Optional containing the ChangedField if present, or an empty Optional if the field does not exist
    • getOrNull

      public @Nullable ChangedField getOrNull(String fieldName)
      Retrieve the ChangedField associated with the specified field name, or null if no such field exists.
      Parameters:
      fieldName - the name of the field to retrieve; must not be null
      Returns:
      the ChangedField for the specified field name, or null if the field does not exist
    • stream

      public Stream<ChangedField> stream()
      Provides a stream of all ChangedField instances contained within the collection.
      Returns:
      a Stream of ChangedField objects representing the modified fields in the collection
    • forEach

      public void forEach(Consumer<ChangedField> action)
      Perform the given action for each ChangedField in the collection.
      Parameters:
      action - the action to be performed for each ChangedField; must not be null
      Throws:
      NullPointerException - if the provided action is null
    • isEmpty

      public boolean isEmpty()
      Check if the collection of changed fields is empty.
      Returns:
      true if there are no changed fields, false otherwise
    • contains

      public boolean contains(String fieldName)
      Check if the provided field name exists within the collection of changed fields.
      Parameters:
      fieldName - the name of the field to check for presence; must not be null
      Returns:
      true if the specified field name exists in the collection, false otherwise
    • size

      public int size()
      Return the number of changed fields in the collection.
      Returns:
      the size of the collection as an integer, representing the number of changed fields