Permalink
Browse files

Fix for AssetAttribute getAddedOrModifiedAttributes (last change brok…

…e test)
  • Loading branch information...
richturner committed Aug 31, 2018
1 parent d16f05d commit 723a7e7653551c9afaa04e5a5015f234ae21bb4b
Showing with 18 additions and 3 deletions.
  1. +18 −3 model/src/main/java/org/openremote/model/asset/AssetAttribute.java
@@ -468,15 +468,30 @@ public boolean equals(Object obj) {
*/
public static Stream<AssetAttribute> getAddedOrModifiedAttributes(List<AssetAttribute> oldAttributes,
List<AssetAttribute> newAttributes,
Predicate<String> attributeNamesToEvaluate,
Predicate<String> ignoredAttributeNames,
Predicate<String> ignoredAttributeKeys) {
return getAddedOrModifiedAttributes(
oldAttributes,
newAttributes,
null,
ignoredAttributeNames,
ignoredAttributeKeys);
}
/**
* @return All attributes that exist only in the new list or are different than any attribute in the old list.
*/
public static Stream<AssetAttribute> getAddedOrModifiedAttributes(List<AssetAttribute> oldAttributes,
List<AssetAttribute> newAttributes,
Predicate<String> limitToAttributeNames,
Predicate<String> ignoredAttributeNames,
Predicate<String> ignoredAttributeKeys) {
return newAttributes.stream().filter(newAttribute -> oldAttributes.stream().noneMatch(
oldAttribute -> newAttribute.getObjectValue().equalsIgnoreKeys(oldAttribute.getObjectValue(), ignoredAttributeKeys))
).filter(addedOrModifiedAttribute ->
!addedOrModifiedAttribute.getName().isPresent() ||
(attributeNamesToEvaluate == null && ignoredAttributeNames == null) ||
(attributeNamesToEvaluate != null && attributeNamesToEvaluate.test(addedOrModifiedAttribute.getName().get())) ||
(limitToAttributeNames == null && ignoredAttributeNames == null) ||
(limitToAttributeNames != null && limitToAttributeNames.test(addedOrModifiedAttribute.getName().get())) ||
(ignoredAttributeNames != null && !ignoredAttributeNames.test(addedOrModifiedAttribute.getName().get()))
);
}

0 comments on commit 723a7e7

Please sign in to comment.