private static AttributesUpdate invertUpdate(AttributesUpdate attrUpdate) { AttributesUpdate inverseUpdate = new AttributesUpdateImpl(); // TODO: This is a little silly. We should do this a better way. for (int i = 0; i < attrUpdate.changeSize(); ++i) { inverseUpdate = inverseUpdate.composeWith(new AttributesUpdateImpl( attrUpdate.getChangeKey(i), attrUpdate.getNewValue(i), attrUpdate.getOldValue(i))); } return inverseUpdate; }
@Override public void updateAttributes(AttributesUpdate attrUpdate) { Map<String, String> updates = new HashMap<String, String>(); for (int i = 0; i < attrUpdate.changeSize(); i++) { updates.put(attrUpdate.getChangeKey(i), attrUpdate.getNewValue(i)); } b.updateAttributes(updates); }
@Override public AttributesUpdate map(final String name) { for (int i = 0; i < finalAccu.changeSize(); i++) { if (finalAccu.getChangeKey(i).equals(name)) { return null; } } return pickRandomNonNullMappedElement(r, p.getAttributeValues(), new Mapper<String, AttributesUpdate>() { @Override public AttributesUpdate map(String value) { AttributesUpdate b = finalAccu.composeWith(new AttributesUpdateImpl(name, oldAttributes.get(name), value)); assert b != finalAccu; // assert non-destructiveness ValidationResult v = checker.check(b); if (valid && !v.isValid() || !valid && v.isIllFormed()) { return null; } else { return b; } } }); } });
@Override public void updateAttributes(AttributesUpdate attrUpdate) { flushAnnotations(); normalizer.updateAttributes(this.attrUpdate.composeWith(attrUpdate)); target = defaultTarget; }
assert accu.changeSize() == 0; accu = pickRandomNonNullMappedElement(r, p.getAttributeNames(), new Mapper<String, AttributesUpdate>() {
/** * Validate the given <code>AttributesUpdate</code>. * * @param update the <code>AttributesUpdate</code> to validate * @return information about whether the <code>AttributesUpdate</code> is * valid and, if not, why it is not */ AttributeValidationResult validate(AttributesUpdate update) { for (int i = 0; i < update.changeSize(); ++i) { String name = update.getChangeKey(i); ValueValidator validator = valueValidators.get(name); if (validator == null) { return new AttributeNotAllowed(name); } String value = update.getNewValue(i); if (value == null) { if (requiredAttributes.contains(name)) { return new RemovingRequiredAttribute(name); } } else { if (!validator.validate(value)) { return new InvalidAttributeValue(name, value); } } } return AttributeValidationResult.VALID; }
private boolean equal(AttributesUpdate a, AttributesUpdate b) { int changeSize = a.changeSize(); if (changeSize != b.changeSize()) { return false; } for (int i = 0; i < changeSize; ++i) { if (!equal(a.getChangeKey(i), b.getChangeKey(i))) { return false; } if (!equalNullable(a.getOldValue(i), b.getOldValue(i))) { return false; } if (!equalNullable(a.getNewValue(i), b.getNewValue(i))) { return false; } } return true; }
@Override public void updateAttributes(AttributesUpdate attrUpdate) { AttributesUpdate update = new AttributesUpdateImpl(); // TODO: This is a little silly. We should do this a better way. for (int i = 0; i < attrUpdate.changeSize(); ++i) { update = update.composeWith(new AttributesUpdateImpl(attrUpdate.getChangeKey(i), attrUpdate.getNewValue(i), attrUpdate.getOldValue(i))); } target.updateAttributes(update); }
public AttributesModified(E element, AttributesUpdate update) { super(Type.ATTRIBUTES); this.element = element; HashMap<String, String> oldV = new HashMap<String, String>(); HashMap<String, String> newV = new HashMap<String, String>(); for (int i = 0; i < update.changeSize(); i++) { String oldValue = update.getOldValue(i); String newValue = update.getNewValue(i); if (ValueUtils.notEqual(newValue, oldValue)) { oldV.put(update.getChangeKey(i), oldValue); newV.put(update.getChangeKey(i), newValue); } } this.oldValues = Collections.unmodifiableMap(oldV); this.newValues = Collections.unmodifiableMap(newV); }
@Override void resolveUpdateAttributes(AttributesUpdate update) { syncAnnotations(); Map<String, String> updated = new HashMap<String, String>(); for (int i = 0; i < update.changeSize(); ++i) { updated.put(update.getChangeKey(i), update.getNewValue(i)); } AttributesUpdate newUpdate = new AttributesUpdateImpl(); // TODO: This is a little silly. We should do this a better way. for (int i = 0; i < this.update.changeSize(); ++i) { String key = this.update.getChangeKey(i); String newOldValue = updated.containsKey(key) ? updated.get(key) : this.update.getOldValue(i); newUpdate = newUpdate.composeWith(new AttributesUpdateImpl(key, newOldValue, this.update.getNewValue(i))); } targetDocument.updateAttributes(newUpdate); Set<String> keySet = new HashSet<String>(); for (int i = 0; i < this.update.changeSize(); ++i) { keySet.add(this.update.getChangeKey(i)); } AttributesUpdate transformedAttributes = update.exclude(keySet); otherTarget.targetDocument.updateAttributes(transformedAttributes); }
public static String toConciseString(AttributesUpdate update) { if (update.changeSize() == 0) { return "{}"; } StringBuilder b = new StringBuilder(); b.append("{ "); for (int i = 0; i < update.changeSize(); ++i) { if (i > 0) { b.append(", "); } b.append(update.getChangeKey(i)); b.append(": "); b.append(literalString(update.getOldValue(i))); b.append(" -> "); b.append(literalString(update.getNewValue(i))); } b.append(" }"); return b.toString(); }
public static AttributesUpdate scrubAttributesUpdate(AttributesUpdate unscrubbed, ScrubCache nameScrubber) { List<AttributeUpdate> list = new ArrayList<AttributeUpdate>(); for (int i = 0; i < unscrubbed.changeSize(); i++) { list.add(new AttributeUpdate( nameScrubber.scrubUniquely(unscrubbed.getChangeKey(i)), scrubMostString(unscrubbed.getOldValue(i)), scrubMostString(unscrubbed.getNewValue(i)))); } return AttributesUpdateImpl.fromUnsortedUpdatesUnchecked(list); }
@Override public void updateAttributes(AttributesUpdate attributes) { ProtocolDocumentOperation.Component.UpdateAttributes.Builder u = ProtocolDocumentOperation.Component.UpdateAttributes.newBuilder(); if (attributes.changeSize() == 0) { u.setEmpty(true); } else { for (int i = 0; i < attributes.changeSize(); i++) { u.addAttributeUpdate(makeKeyValueUpdate( attributes.getChangeKey(i), attributes.getOldValue(i), attributes.getNewValue(i))); } } output.addComponent(newComponentBuilder().setUpdateAttributes(u.build()).build()); }
private ValidationResult checkAttributesUpdateWellFormed(AttributesUpdate u, ViolationCollector v) { if (u == null) { return nullAttributesUpdate(v); } String previousKey = null; for (int i = 0; i < u.changeSize(); i++) { String key = u.getChangeKey(i); if (key == null) { return nullAttributeKey(v); } if (!Utf16Util.isXmlName(key)) { return attributeNameNotXmlName(v, key); } if (previousKey != null && previousKey.compareTo(key) >= 0) { return attributeKeysNotStrictlyMonotonic(v, previousKey, key); } if (u.getOldValue(i) != null && !Utf16Util.isValidUtf16(u.getOldValue(i))) { return attributeValueNotValidUtf16(v); } if (u.getNewValue(i) != null && !Utf16Util.isValidUtf16(u.getNewValue(i))) { return attributeValueNotValidUtf16(v); } previousKey = key; } return ValidationResult.VALID; }
@Override void resolveUpdateAttributes(AttributesUpdate update) { Map<String, String> updated = new HashMap<String, String>(); for (int i = 0; i < update.changeSize(); ++i) { updated.put(update.getChangeKey(i), update.getNewValue(i)); } AttributesUpdate newUpdate = new AttributesUpdateImpl(); // TODO: This is a little silly. We should do this a better way. for (int i = 0; i < this.update.changeSize(); ++i) { String key = this.update.getChangeKey(i); String newOldValue = updated.containsKey(key) ? updated.get(key) : this.update.getOldValue(i); newUpdate = newUpdate.composeWith(new AttributesUpdateImpl(key, newOldValue, this.update.getNewValue(i))); } targetDocument.updateAttributes(newUpdate); Set<String> keySet = new HashSet<String>(); for (int i = 0; i < this.update.changeSize(); ++i) { keySet.add(this.update.getChangeKey(i)); } AttributesUpdate transformedAttributes = update.exclude(keySet); otherTarget.targetDocument.updateAttributes(transformedAttributes); }
@Override void resolveUpdateAttributes(AttributesUpdate update) { Map<String, String> updated = new HashMap<String, String>(); for (int i = 0; i < update.changeSize(); ++i) { updated.put(update.getChangeKey(i), update.getNewValue(i)); } AttributesUpdate newUpdate = new AttributesUpdateImpl(); // TODO: This is a little silly. We should do this a better way. for (int i = 0; i < this.update.changeSize(); ++i) { String key = this.update.getChangeKey(i); String newOldValue = updated.containsKey(key) ? updated.get(key) : this.update.getOldValue(i); newUpdate = newUpdate.composeWith(new AttributesUpdateImpl(key, newOldValue, this.update.getNewValue(i))); } targetDocument.updateAttributes(newUpdate); Set<String> keySet = new HashSet<String>(); for (int i = 0; i < this.update.changeSize(); ++i) { keySet.add(this.update.getChangeKey(i)); } AttributesUpdate transformedAttributes = update.exclude(keySet); otherTarget.targetDocument.updateAttributes(transformedAttributes); }
assert type != null; Attributes oldAttrs = effectiveDocSymbolAttributes(); for (int i = 0; i < u.changeSize(); i++) { String key = u.getChangeKey(i); String oldValue = u.getOldValue(i); if (!equal(oldValue, oldAttrs.get(key))) { return oldAttributesDifferFromDocument(v); } for (int i = 0; i < u.changeSize(); i++) { String key = u.getChangeKey(i); String value = u.getNewValue(i); if (value != null) { if (!elementAllowsAttribute(type, key, value)) {