protected UserAttribute modifyOrAddAttribute(UserAttribute attribute, String key, String value) { if (attribute == null) { return addInternal(new UserAttribute(key, value)); } attribute.setValue(value); return attribute; }
void clearAttribute(UserData user, UserAttribute a) { a.removeAllAttributes(); a.setParent(null); a.setUser(null); user.addOrphan(a); }
UserAttribute addInternal(UserAttribute a) { if (a.getParent() != null) { a.getParent().getAttributes().remove(a); } getAttributes().add(a); if (getUser() != null) { getUser().addChild(a); } a.setUser(getUser()); a.setParent(getChildParent()); return a; }
@Override public String transform(UserAttribute obj) { return obj.getKey(); } }, new HashSet<String>());
public String findAttributeValueRecursive(String key) { UserAttribute a = findAttributeRecursive(key); return a != null ? a.getValue() : null; }
public UserAttribute findAttributeRecursive(final String key) { UserAttribute found = findAttribute(key); if (found == null) { for (UserAttribute a : getAttributes()) { found = a.findAttributeRecursive(key); if (found != null) { break; } } } return found; }
@Override public boolean apply(UserAttribute input) { return input.getParent() == null; } }, new HashSet<UserAttribute>());
void addChild(UserAttribute a) { if (!getAttributes().contains(a)) { getAttributes().add(a); } if (!a.getAttributes().isEmpty()) { for (UserAttribute b : a.getAttributes()) { addChild(b); } } getOrphans().remove(a); }
@Override public boolean apply(UserAttribute b) { if (!predicate.apply(b)) { return false; } Map<String, UserAttribute> aMap = a.getAttributesMap(), bMap = b.getAttributesMap(); Set<String> aKeys = aMap.keySet(), bKeys = bMap.keySet(); if (!aKeys.containsAll(bKeys) || !bKeys.containsAll(aKeys)) { return false; } for (String key : aKeys) { if (!matchAttribute(aMap.get(key)).apply(bMap.get(key))) { return false; } } return true; } };
public static Predicate<UserAttribute> matchAttribute(final UserAttribute a) { return new Predicate<UserAttribute>() { Predicate<UserAttribute> predicate = matchKeyValue(a.getKey(), a.getValue()); @Override public boolean apply(UserAttribute b) { if (!predicate.apply(b)) { return false; } Map<String, UserAttribute> aMap = a.getAttributesMap(), bMap = b.getAttributesMap(); Set<String> aKeys = aMap.keySet(), bKeys = bMap.keySet(); if (!aKeys.containsAll(bKeys) || !bKeys.containsAll(aKeys)) { return false; } for (String key : aKeys) { if (!matchAttribute(aMap.get(key)).apply(bMap.get(key))) { return false; } } return true; } }; } }
@Override public String transform(UserAttribute obj) { return obj.getKey(); } });
@Override public boolean apply(UserAttribute input) { return Lang.equals(input.getValue(), value); } };
public UserAttribute findAttributeRecursive(final String key, final String value) { UserAttribute found = findAttribute(key, value); if (found == null) { for (UserAttribute a : getAttributes()) { found = a.findAttributeRecursive(key, value); if (found != null) { break; } } } return found; }
void addOrphan(UserAttribute a) { getAttributes().remove(a); if (a.getId() != null) { getOrphans().add(a); } }
@Override public boolean apply(UserAttribute input) { return matchEntity(a).apply(input.getParent()); } };