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); }
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); }
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; }
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 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); }
@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); }
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); }
@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()); }
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); }