Skip to content

Commit

Permalink
Reduce redundant calls to check for collection consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Sep 6, 2024
1 parent 8e9d051 commit 9414f6f
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ public void setIsInitializationCompleted(final boolean value) {
backedModel
.getBackingStore()
.setIsInitializationCompleted(value); // propagate initialization
} else {
// setIsInitializationCompleted() called above already checks for collection
// consistency for BackedModels
ensureCollectionPropertyIsConsistent(
entry.getKey(), this.store.get(entry.getKey()).getValue1());
}
ensureCollectionPropertyIsConsistent(
entry.getKey(), this.store.get(entry.getKey()).getValue1());
final Pair<Boolean, Object> updatedValue = wrapper.setValue0(!value);
entry.setValue(updatedValue);
}
Expand All @@ -89,10 +92,10 @@ public void clear() {
final Map<String, Object> result = new HashMap<>();
for (final Map.Entry<String, Pair<Boolean, Object>> entry : this.store.entrySet()) {
final Pair<Boolean, Object> wrapper = entry.getValue();
final Object value = this.getValueFromWrapper(entry.getKey(), wrapper);
final Object value = this.get(entry.getKey());

if (value != null) {
result.put(entry.getKey(), wrapper.getValue1());
result.put(entry.getKey(), value);
} else if (Boolean.TRUE.equals(wrapper.getValue0())) {
result.put(entry.getKey(), null);
}
Expand Down Expand Up @@ -242,9 +245,8 @@ private void touchNestedProperties(final Object nestedObject) {
// Call Get<>() on nested properties so that this method may be called recursively to
// ensure collections are consistent
final BackedModel backedModel = (BackedModel) nestedObject;
for (final String itemKey : backedModel.getBackingStore().enumerate().keySet()) {
backedModel.getBackingStore().get(itemKey);
}
// enumerate() calls get<>() on all properties
backedModel.getBackingStore().enumerate();
}
}
}

0 comments on commit 9414f6f

Please sign in to comment.