@Override public boolean equals(Object o) { if (!(o instanceof DirectDAGNode)) { return false; } return node.equals(((DirectDAGNode) o).node); } }
@Override public boolean equals(Object o) { if (!(o instanceof DirectDAGNode)) { return false; } return node.equals(((DirectDAGNode) o).node); } }
/** * Overrides to only call {@link #put(Node) put(newNode)} since both old and new are guaranteed * to fall on the same bucket as mandated by the canonical node order. */ @Override public int update(Node oldNode, Node newNode) { Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); int delta = put(newNode); if (delta == 0 && !oldNode.equals(newNode)) { delta = 1; } return delta; }
/** * Overrides to only call {@link #put(Node) put(newNode)} since both old and new are guaranteed * to fall on the same bucket as mandated by the canonical node order. */ @Override public int update(Node oldNode, Node newNode) { Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); int delta = put(newNode); if (delta == 0 && !oldNode.equals(newNode)) { delta = 1; } return delta; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof MutableTree)) { return false; } MutableTree other = (MutableTree) o; return node.equals(other.node) && node.getMetadataId().equals(other.node.getMetadataId()) && childTrees.equals(other.childTrees); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof MutableTree)) { return false; } MutableTree other = (MutableTree) o; return node.equals(other.node) && node.getMetadataId().equals(other.node.getMetadataId()) && childTrees.equals(other.childTrees); }
/** * Tests equality over another {@code NodeRef} based on {@link #getParentPath() parent path}, * {@link #getNode() node} name and id, and {@link #getMetadataId()} */ @Override public boolean equals(Object o) { if (!(o instanceof NodeRef)) { return false; } NodeRef r = (NodeRef) o; return Objects.equal(parentPath, r.parentPath) && node.equals(r.node) && getMetadataId().equals(r.getMetadataId()); }
/** * Tests equality over another {@code NodeRef} based on {@link #getParentPath() parent path}, * {@link #getNode() node} name and id, and {@link #getMetadataId()} */ @Override public boolean equals(Object o) { if (!(o instanceof NodeRef)) { return false; } NodeRef r = (NodeRef) o; return Objects.equal(parentPath, r.parentPath) && node.equals(r.node) && getMetadataId().equals(r.getMetadataId()); }
if (!left.equals(right)) { checkState(updated, "Node %s was not updated to %s", left, right);
if (!left.equals(right)) { checkState(updated, "Node %s was not updated to %s", left, right);
@Override public boolean feature(final @Nullable NodeRef left, @Nullable final NodeRef right) { final boolean cancelled = progress.isCanceled(); if (!cancelled) { if (left == null) { Node node = right.getNode(); boolean put = builder.put(node); checkState(put, "Node was not added to index: %s", node); } else if (right == null) { Node node = left.getNode(); boolean removed = builder.remove(node); checkState(removed, "Node was not removed from index: %s", node); } else { Node lnode = left.getNode(); Node rnode = right.getNode(); boolean updated = builder.update(lnode, rnode); if (!lnode.equals(rnode)) { checkState(updated, "Node %s was not updated to %s", lnode, rnode); } } progress.setProgress(count.incrementAndGet()); } return !cancelled; }
@Override public boolean feature(final @Nullable NodeRef left, @Nullable final NodeRef right) { final boolean cancelled = progress.isCanceled(); if (!cancelled) { if (left == null) { Node node = right.getNode(); boolean put = builder.put(node); checkState(put, "Node was not added to index: %s", node); } else if (right == null) { Node node = left.getNode(); boolean removed = builder.remove(node); checkState(removed, "Node was not removed from index: %s", node); } else { Node lnode = left.getNode(); Node rnode = right.getNode(); boolean updated = builder.update(lnode, rnode); if (!lnode.equals(rnode)) { checkState(updated, "Node %s was not updated to %s", lnode, rnode); } } progress.setProgress(count.incrementAndGet()); } return !cancelled; }
/** * Finds tree pointers that point to the same tree (path and object id) on the left and right * sides of the comparison but have different {@link NodeRef#getMetadataId() metadata ids} */ public Map<NodeRef, NodeRef> findPureMetadataChanges() { SortedMap<String, MutableTree> leftEntries = leftTree.getChildrenAsMap(); SortedMap<String, MutableTree> rightEntries = rightTree.getChildrenAsMap(); Map<NodeRef, NodeRef> matches = Maps.newTreeMap(); for (Map.Entry<String, MutableTree> e : leftEntries.entrySet()) { final String nodePath = e.getKey(); final MutableTree leftTree = e.getValue(); final Node leftNode = leftTree.getNode(); @Nullable final MutableTree rightTree = rightEntries.get(nodePath); final Node rightNode = rightTree == null ? null : rightTree.getNode(); if (leftNode.equals(rightNode)) { final Optional<ObjectId> leftMetadata = leftNode.getMetadataId(); final Optional<ObjectId> rightMetadata = rightNode.getMetadataId(); if (!leftMetadata.equals(rightMetadata)) { String parentPath = NodeRef.parentPath(nodePath); NodeRef leftRef = new NodeRef(leftNode, parentPath, ObjectId.NULL); NodeRef rightRef = new NodeRef(rightNode, parentPath, ObjectId.NULL); matches.put(leftRef, rightRef); } } } return matches; }
/** * Finds tree pointers that point to the same tree (path and object id) on the left and right * sides of the comparison but have different {@link NodeRef#getMetadataId() metadata ids} */ public Map<NodeRef, NodeRef> findPureMetadataChanges() { SortedMap<String, MutableTree> leftEntries = leftTree.getChildrenAsMap(); SortedMap<String, MutableTree> rightEntries = rightTree.getChildrenAsMap(); Map<NodeRef, NodeRef> matches = Maps.newTreeMap(); for (Map.Entry<String, MutableTree> e : leftEntries.entrySet()) { final String nodePath = e.getKey(); final MutableTree leftTree = e.getValue(); final Node leftNode = leftTree.getNode(); @Nullable final MutableTree rightTree = rightEntries.get(nodePath); final Node rightNode = rightTree == null ? null : rightTree.getNode(); if (leftNode.equals(rightNode)) { final Optional<ObjectId> leftMetadata = leftNode.getMetadataId(); final Optional<ObjectId> rightMetadata = rightNode.getMetadataId(); if (!leftMetadata.equals(rightMetadata)) { String parentPath = NodeRef.parentPath(nodePath); NodeRef leftRef = new NodeRef(leftNode, parentPath, ObjectId.NULL); NodeRef rightRef = new NodeRef(rightNode, parentPath, ObjectId.NULL); matches.put(leftRef, rightRef); } } } return matches; }
/** * Overrides to implement a simple optimization for the case where the node bounds haven't * changed and hence avoid calling remove and then put, but call put only, since the * {@code NodeId} is guaranteed to lay on the same bucket at any depth. */ @Override public int update(Node oldNode, Node newNode) { Optional<Envelope> oldBounds = oldNode.bounds(); Optional<Envelope> newBounds = newNode.bounds(); if (oldBounds.equals(newBounds)) { // in case the bounds didn't change, put will override the old value, // otherwise need to remove old and add new separately Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); int delta = put(newNode); if (delta == 0 && !oldNode.equals(newNode)) { delta = 1; } } return super.update(oldNode, newNode); }
/** * Overrides to implement a simple optimization for the case where the node bounds haven't * changed and hence avoid calling remove and then put, but call put only, since the * {@code NodeId} is guaranteed to lay on the same bucket at any depth. */ @Override public int update(Node oldNode, Node newNode) { Optional<Envelope> oldBounds = oldNode.bounds(); Optional<Envelope> newBounds = newNode.bounds(); if (oldBounds.equals(newBounds)) { // in case the bounds didn't change, put will override the old value, // otherwise need to remove old and add new separately Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); int delta = put(newNode); if (delta == 0 && !oldNode.equals(newNode)) { delta = 1; } } return super.update(oldNode, newNode); }
strategy.put(ref); Node newNode = strategy.getNode(nodeId); assertFalse(currNode.equals(newNode));
strategy.put(ref); Node newNode = strategy.getNode(nodeId); assertFalse(currNode.equals(newNode));
@Test public void testIsEqual() { Node node = RevObjectFactory.defaultInstance().createNode("Points.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0000"), ObjectId.NULL, TYPE.FEATURE, null, null); Node node2 = RevObjectFactory.defaultInstance().createNode("Lines.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0001"), ObjectId.NULL, TYPE.FEATURE, null, null); Node node3 = RevObjectFactory.defaultInstance().createNode("Lines.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0001"), ObjectId.valueOf("abc123000000000000001234567890abcdef0002"), TYPE.TREE, null, null); Node node4 = RevObjectFactory.defaultInstance().createNode("Lines.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0003"), ObjectId.NULL, TYPE.FEATURE, null, null); assertFalse(node.equals("NotANode")); assertFalse(node.equals(node2)); assertFalse(node2.equals(node3)); assertFalse(node2.equals(node4)); assertTrue(node.equals(node)); }
Node newNode = resultNodes.get(changedNodeName); assertNotNull(newNode); assertFalse(oldNode.equals(newNode)); assertEquals(newValues.get(changedNodeName), newNode);