java.lang.Object
org.litebridgedb.tracking.ChangedFields
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 Summary
ConstructorsConstructorDescriptionChangedFields(Map<String, ChangedField> changedFieldMap) Construct a newChangedFieldsinstance with the provided map of changed fields. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if the provided field name exists within the collection of changed fields.voidforEach(Consumer<ChangedField> action) Perform the given action for eachChangedFieldin the collection.Retrieve anOptionalcontaining theChangedFieldassociated with the specified field name.@Nullable ChangedFieldRetrieve theChangedFieldassociated with the specified field name, ornullif no such field exists.booleanisEmpty()Check if the collection of changed fields is empty.intsize()Return the number of changed fields in the collection.stream()Provides a stream of allChangedFieldinstances contained within the collection.
-
Constructor Details
-
ChangedFields
Construct a newChangedFieldsinstance with the provided map of changed fields.The map is expected to contain field names as keys and corresponding
ChangedFieldobjects representing the modified fields as values. The map is made immutable.- Parameters:
changedFieldMap- a map where keys represent field names and values representChangedFieldobjects; the map cannot benull- Throws:
IllegalArgumentException- ifchangedFieldMapisnull
-
-
Method Details
-
get
Retrieve anOptionalcontaining theChangedFieldassociated with the specified field name.If no such field exists, an empty
Optionalis returned.- Parameters:
fieldName- the name of the field to retrieve; must not benull- Returns:
- an
Optionalcontaining theChangedFieldif present, or an emptyOptionalif the field does not exist
-
getOrNull
Retrieve theChangedFieldassociated with the specified field name, ornullif no such field exists.- Parameters:
fieldName- the name of the field to retrieve; must not benull- Returns:
- the
ChangedFieldfor the specified field name, ornullif the field does not exist
-
stream
Provides a stream of allChangedFieldinstances contained within the collection.- Returns:
- a
StreamofChangedFieldobjects representing the modified fields in the collection
-
forEach
Perform the given action for eachChangedFieldin the collection.- Parameters:
action- the action to be performed for eachChangedField; must not benull- Throws:
NullPointerException- if the providedactionisnull
-
isEmpty
public boolean isEmpty()Check if the collection of changed fields is empty.- Returns:
trueif there are no changed fields,falseotherwise
-
contains
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
-