public static <V extends PrismValue> boolean contains(Collection<V> thisSet, V otherValue, EquivalenceStrategy strategy) { for (V thisValue: thisSet) { if (thisValue.equals(otherValue, strategy)) { return true; } } return false; }
public static <V extends PrismValue> boolean collectionContainsEquivalentValue(Collection<V> collection, V value) { if (collection == null) { return false; } for (V collectionVal: collection) { if (collectionVal.equals(value, EquivalenceStrategy.IGNORE_METADATA)) { return true; } } return false; }
private boolean isValueSet(V value, boolean ignoreMetadata, Collection<V> set) { if (set == null) { return false; } for (V myVal: set) { if (myVal.equals(value, ignoreMetadata ? EquivalenceStrategy.IGNORE_METADATA : EquivalenceStrategy.NOT_LITERAL)) { return true; } } return false; }
private boolean isIn(Collection<V> values, V val) { if (values == null) { return false; } for (V v : values) { if (v.equals(val, EquivalenceStrategy.REAL_VALUE)) { return true; } } return false; }
@Override public boolean equals(PrismValue first, PrismValue second) { return first == second || first != null && second != null && first.equals(second, this); }
protected boolean isValueEquivalent(V a, V b) { return a.equals(b, EquivalenceStrategy.REAL_VALUE); }
public static <X, V extends PrismValue> boolean containsRealValue(Collection<X> collection, V value, Function<X, V> valueExtractor) { if (collection == null) { return false; } for (X colVal: collection) { if (colVal == null) { return value == null; } if (valueExtractor.apply(colVal).equals(value, EquivalenceStrategy.REAL_VALUE)) { return true; } } return false; }
private V findValue(Collection<V> values, V value) { if (values == null) { return null; } return values.stream() .filter(v -> v.equals(value, EquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS)) .findFirst().orElse(null); }
@Override public V findValue(V value, @NotNull EquivalenceStrategy strategy) { for (V myVal : getValues()) { if (myVal.equals(value, strategy)) { return myVal; } } return null; }
public boolean equals(PrismValue thisValue, PrismValue otherValue) { if (thisValue == otherValue) { return true; } if (thisValue == null || otherValue == null) { return false; } return thisValue.equals(otherValue, getEqualsHashCodeStrategy()); }
public static <V extends PrismValue> boolean equalsRealValues(Collection<V> collection1, Collection<V> collection2) { return MiscUtil.unorderedCollectionEquals(collection1, collection2, (v1, v2) -> v1.equals(v2, EquivalenceStrategy.REAL_VALUE)); }
/** * Checks if the delta is redundant w.r.t. current state of the object. * I.e. if it changes the current object state. */ public boolean isRedundant(PrismObject<? extends Objectable> object) { Comparator<V> comparator = (o1, o2) -> { if (o1.equals(o2, EquivalenceStrategy.IGNORE_METADATA)) { return 0; } else { return 1; } }; return isRedundant(object, comparator); }
private boolean equivalentSetRealValue(Collection<V> thisValue, Collection<V> otherValues, boolean isDelete) { return MiscUtil.unorderedCollectionEquals(thisValue, otherValues, (v1, v2) -> { if (v1 != null && v2 != null) { if (!isDelete || !(v1 instanceof PrismContainerValue) || !(v2 instanceof PrismContainerValue)) { // Here it is questionable if we should consider adding "assignment id=1 (A)" and "assignment id=2 (A)" // - i.e. assignments with the same real value but different identifiers - the same delta. // Historically, we considered it as such. But the question is if it's correct. return v1.equals(v2, EquivalenceStrategy.REAL_VALUE); } else { // But for container values to be deleted, they can be referred to either using IDs or values. // If content is used - but no IDs - the content must be equal. // If IDs are used - and are the same - the content is irrelevant. // The problem is if one side has content with ID, and the other has the same content without ID. // This might have the same or different effect, depending on the content it is applied to. // See MID-3828 return v1.equals(v2, EquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS) || v1.representsSameValue(v2, false); } } else { return false; } }); }
private boolean removeValue(PrismValue valueToRemove, Collection<V> set, boolean toDelete) { checkMutability(); boolean removed = false; if (set == null) { return false; } Iterator<V> valuesIterator = set.iterator(); while (valuesIterator.hasNext()) { V existingValue = valuesIterator.next(); if (existingValue.equals(valueToRemove, EquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS) || toDelete && existingValue.representsSameValue(valueToRemove, false)) { // the same algorithm as when deleting the item value valuesIterator.remove(); removed = true; } } return removed; }
@Override public boolean remove(V value, @NotNull EquivalenceStrategy strategy) { checkMutability(); boolean changed = false; Iterator<V> iterator = values.iterator(); while (iterator.hasNext()) { V val = iterator.next(); if (val.representsSameValue(value, false) || val.equals(value, strategy)) { iterator.remove(); val.setParent(null); changed = true; } } return changed; }
public boolean remove(V newValue) { checkMutability(); boolean changed = false; Iterator<V> iterator = values.iterator(); while (iterator.hasNext()) { V val = iterator.next(); // the same algorithm as when deleting the item value from delete delta if (val.representsSameValue(newValue, false) || val.equals(newValue, EquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS)) { iterator.remove(); val.setParent(null); changed = true; } } return changed; }
public <T> boolean equalsRealValue(V pvalue, ValueMatcher<T> valueMatcher) throws SchemaException { if (itemValue == null) { return false; } if (valueMatcher == null) { return itemValue.equals(pvalue, EquivalenceStrategy.IGNORE_METADATA); } else { // this must be a property, otherwise there would be no matcher return valueMatcher.match(((PrismPropertyValue<T>)itemValue).getValue(), ((PrismPropertyValue<T>)pvalue).getValue()); } }
private static PrismEntityPair findMatch(Collection<PrismEntityPair<?>> collection, PrismEntityPair pair) { boolean isContainer = pair.getRepository() instanceof Container; Object pairObject = pair.getRepository(); for (PrismEntityPair item : collection) { if (isContainer) { Container c = (Container) item.getRepository(); Container pairContainer = (Container) pairObject; if (Objects.equals(c.getId(), pairContainer.getId()) || pair.getPrism().equals(item.getPrism(), EquivalenceStrategy.IGNORE_METADATA)) { //todo return item; } } else { // e.g. RObjectReference if (Objects.equals(item.getRepository(), pairObject)) { return item; } } } return null; }
} else if (thisValue.equals(otherValue, strategy)) { found = true;
protected void process(String desc, ParsingFunction<T> parser, SerializingFunction<T> serializer, String serId) throws Exception { PrismContext prismContext = getPrismContext(); System.out.println("================== Starting test for '" + desc + "' (serializer: " + serId + ") =================="); T value = parser.apply(prismContext.parserFor(getFile())); assertResolvableRawValues(value); // should be right here, before any getValue is called (TODO reconsider) System.out.println("Parsed value: " + desc); System.out.println(value.debugDump()); assertPrismValue(value); if (serializer != null) { String serialized = serializer.apply(value); System.out.println("Serialized:\n" + serialized); T reparsed = parser.apply(prismContext.parserFor(serialized)); assertResolvableRawValues(reparsed); // should be right here, before any getValue is called (TODO reconsider) System.out.println("Reparsed: " + desc); System.out.println(reparsed.debugDump()); assertPrismValue(reparsed); Collection<? extends ItemDelta> deltas = value.diff(reparsed); assertTrue("Deltas not empty", deltas.isEmpty()); assertTrue("Values not equal", value.equals(reparsed, EquivalenceStrategy.NOT_LITERAL)); } }