/** * Sets all parents to null. This is good if the items are to be "transplanted" into a * different Containerable. */ public static <T extends PrismValue> Collection<T> resetParentCollection(Collection<T> values) { for (T value: values) { value.setParent(null); } return values; }
/** * @param value value, has to be parent-less */ public void setValue(V value) { this.values = new ArrayList<>(); if (value != null) { value.setParent(this); values.add(value); } }
public V remove(int index) { checkMutability(); V removed = values.remove(index); removed.setParent(null); return removed; }
@Override public void clear() { checkMutability(); for (V value : values) { value.setParent(null); } values.clear(); }
private Collection<V> cloneSet(ItemDeltaImpl clone, Collection<V> thisSet) { if (thisSet == null) { return null; } Collection<V> clonedSet = newValueCollection(); for (V thisVal : thisSet) { V clonedVal = (V) thisVal.clone(); clonedVal.setParent(clone); clonedSet.add(clonedVal); } return clonedSet; }
@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; }
protected ValueFilterImpl(@NotNull ItemPath fullPath, @Nullable D definition, @Nullable QName matchingRule, @Nullable List<V> values, @Nullable ExpressionWrapper expression, @Nullable ItemPath rightHandSidePath, @Nullable ItemDefinition rightHandSideDefinition) { Validate.isTrue(!ItemPath.isEmpty(fullPath), "path in filter is null or empty"); this.fullPath = fullPath; this.definition = definition; this.matchingRule = matchingRule; this.expression = expression; this.values = values; this.rightHandSidePath = rightHandSidePath; this.rightHandSideDefinition = rightHandSideDefinition; if (values != null) { for (V value : values) { value.setParent(this); } } checkConsistence(false); }
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; }
@Nullable private <IV extends PrismValue> IV getSingleParentlessValue(Item<IV, ?> item) { if (item.size() == 0) { return null; } else if (item.size() == 1) { IV value = item.getValues().get(0); value.setParent(null); return value; } else { throw new IllegalStateException("Expected one item value, got " + item.getValues().size() + " while parsing " + item); } }
public void addValueToReplace(V newValue) { checkMutability(); if (valuesToAdd != null) { throw new IllegalStateException("Delta " + this + " already has values to add, attempt to set value to replace"); } if (valuesToDelete != null) { throw new IllegalStateException("Delta " + this + " already has values to delete, attempt to set value to replace"); } if (valuesToReplace == null) { valuesToReplace = newValueCollection(); } if (newValue != null) { valuesToReplace.add(newValue); newValue.setParent(this); newValue.recompute(); } }
public void setValuesToReplace(V... newValues) { checkMutability(); if (valuesToAdd != null) { throw new IllegalStateException("Delta " + this + " already has values to add, attempt to set value to replace"); } if (valuesToDelete != null) { throw new IllegalStateException("Delta " + this + " already has values to delete, attempt to set value to replace"); } if (valuesToReplace == null) { valuesToReplace = newValueCollection(); } else { valuesToReplace.clear(); } for (V val : newValues) { valuesToReplace.add(val); val.setParent(this); val.recompute(); } }
public void setValueToReplace(V newValue) { checkMutability(); if (valuesToAdd != null) { throw new IllegalStateException("Delta " + this + " already has values to add, attempt to set value to replace"); } if (valuesToDelete != null) { throw new IllegalStateException("Delta " + this + " already has values to delete, attempt to set value to replace"); } if (valuesToReplace == null) { valuesToReplace = newValueCollection(); } else { valuesToReplace.clear(); } if (newValue != null) { valuesToReplace.add(newValue); newValue.setParent(this); newValue.recompute(); } }
public void setValuesToReplace(Collection<V> newValues) { checkMutability(); if (newValues == null) { return; } if (valuesToAdd != null) { throw new IllegalStateException("Delta " + this + " already has values to add ("+valuesToAdd+"), attempt to set value to replace ("+newValues+")"); } if (valuesToDelete != null) { throw new IllegalStateException("Delta " + this + " already has values to delete, attempt to set value to replace"); } if (valuesToReplace == null) { valuesToReplace = newValueCollection(); } else { valuesToReplace.clear(); } for (V val : newValues) { valuesToReplace.add(val); val.setParent(this); val.recompute(); } }
public void addEstimatedOldValue(V newValue) { checkMutability(); if (estimatedOldValues == null) { estimatedOldValues = newValueCollection(); } if (PrismValueCollectionsUtil.containsRealValue(estimatedOldValues,newValue)) { return; } estimatedOldValues.add(newValue); newValue.setParent(this); newValue.recompute(); }
public void addValueToAdd(V newValue) { checkMutability(); if (valuesToReplace != null) { throw new IllegalStateException("Delta " + this + " already has values to replace ("+valuesToReplace+"), attempt to add value ("+newValue+") is an error"); } if (valuesToAdd == null) { valuesToAdd = newValueCollection(); } if (PrismValueCollectionsUtil.containsRealValue(valuesToAdd,newValue)) { return; } valuesToAdd.add(newValue); newValue.setParent(this); newValue.recompute(); }
public void addValueToDelete(V newValue) { checkMutability(); if (valuesToReplace != null) { throw new IllegalStateException("Delta " + this + " already has values to replace ("+valuesToReplace+"), attempt to set value to delete ("+newValue+")"); } if (valuesToDelete == null) { valuesToDelete = newValueCollection(); } if (containsEquivalentValue(valuesToDelete, newValue)) { return; } valuesToDelete.add(newValue); newValue.setParent(this); newValue.recompute(); }
public void mergeValueToAdd(V newValue) { checkMutability(); if (valuesToReplace != null) { if (!PrismValueCollectionsUtil.containsRealValue(valuesToReplace, newValue)) { valuesToReplace.add(newValue); newValue.setParent(this); } } else { if (!removeValueToDelete(newValue)) { addValueToAdd(newValue); } } }
public boolean add(@NotNull V newValue, boolean checkUniqueness, @NotNull EquivalenceStrategy equivalenceStrategy) throws SchemaException { checkMutability(); if (newValue.getPrismContext() == null) { newValue.setPrismContext(prismContext); } Itemable originalParent = newValue.getParent(); newValue.setParent(this); // needed e.g. because of PrismReferenceValue comparisons if (checkUniqueness && contains(newValue, equivalenceStrategy)) { newValue.setParent(originalParent); return false; } D definition = getDefinition(); if (definition != null) { if (!values.isEmpty() && definition.isSingleValue()) { throw new SchemaException("Attempt to put more than one value to single-valued item " + this + "; newly added value: " + newValue); } newValue.applyDefinition(definition, false); } return values.add(newValue); }
for (V val : values) { if (val.getParent() == null) { val.setParent(filter);