@Override public int put(final Node node) { Preconditions.checkArgument(TYPE.FEATURE == node.getType(), "Can't add non feature nodes to quad-tree: %s", node); return super.put(node); }
@Override public int put(final Node node) { Preconditions.checkArgument(TYPE.FEATURE == node.getType(), "Can't add non feature nodes to quad-tree: %s", node); return super.put(node); }
@Override public boolean put(final Node node) { checkNotNull(node, "Argument node is null"); checkState(!disposed.get(), "TreeBuilder is already disposed"); int delta = clusteringStrategy().put(node); checkState(delta != -1); return delta == 1; }
@Override public boolean put(final Node node) { checkNotNull(node, "Argument node is null"); checkState(!disposed.get(), "TreeBuilder is already disposed"); int delta = clusteringStrategy().put(node); checkState(delta != -1); return delta == 1; }
/** * Replaces {@code oldNode} by {@code newNode} * <p> * This default implemetation just calls {@link #remove(Node) remove(oldNode)} and then * {@link #put(Node) put(newNode)}. Subclasses are encouraged to override with optimized * versions whenever possible. * * @return {@code 0} if the operation resulted in no change, {@code 1} if the node was * inserted/updated, {@code -1} if the node was deleted */ public int update(Node oldNode, Node newNode) { Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); if (remove(oldNode)) { return put(newNode); } return 0; }
/** * Replaces {@code oldNode} by {@code newNode} * <p> * This default implemetation just calls {@link #remove(Node) remove(oldNode)} and then * {@link #put(Node) put(newNode)}. Subclasses are encouraged to override with optimized * versions whenever possible. * * @return {@code 0} if the operation resulted in no change, {@code 1} if the node was * inserted/updated, {@code -1} if the node was deleted */ public int update(Node oldNode, Node newNode) { Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); if (remove(oldNode)) { return put(newNode); } return 0; }
public boolean remove(Node node) { if (!node.getObjectId().isNull()) { node = node.update(ObjectId.NULL); } int delta = put(node); return -1 == delta; }
public boolean remove(Node node) { if (!node.getObjectId().isNull()) { node = node.update(ObjectId.NULL); } int delta = put(node); return -1 == delta; }
/** * @param * @return {@code 0} if the operation resulted in no change, {@code 1} if the node was * inserted/updated, {@code -1} if the node was deleted */ public int put(final Node node) { @Nullable final NodeId nodeId = computeId(node); if (null == nodeId) { return 0; } // nodeId can be null if it's not to be added to the tree at all (e.g. a non spatial // feature in a spatial index) boolean remove = node.getObjectId().isNull(); int delta; writeLock.lock(); try { delta = put(root, nodeId, remove); dagCache.prune(); } finally { writeLock.unlock(); } if (!remove) { storageProvider.saveNode(nodeId, node); } return delta; }
/** * @param * @return {@code 0} if the operation resulted in no change, {@code 1} if the node was * inserted/updated, {@code -1} if the node was deleted */ public int put(final Node node) { @Nullable final NodeId nodeId = computeId(node); if (null == nodeId) { return 0; } // nodeId can be null if it's not to be added to the tree at all (e.g. a non spatial // feature in a spatial index) boolean remove = node.getObjectId().isNull(); int delta; writeLock.lock(); try { delta = put(root, nodeId, remove); dagCache.prune(); } finally { writeLock.unlock(); } if (!remove) { storageProvider.saveNode(nodeId, node); } return delta; }
@Test public void nodeReplacedOnEditsWithBaseRevTree() { final RevTree origTree = manuallyCreateBucketsTree(); store.put(origTree); final Set<Node> original = new HashSet<>(); final Set<Node> edited = new HashSet<>(); { Iterator<NodeRef> it = new DepthTreeIterator("", ObjectId.NULL, origTree, store, Strategy.RECURSIVE_FEATURES_ONLY); while (it.hasNext()) { original.add(it.next().getNode()); } for (Node n : original) { ObjectId oid = RevObjectTestSupport.hashString(n.toString()); Node edit = Node.create(n.getName(), oid, ObjectId.NULL, TYPE.FEATURE, n.bounds().orNull()); edited.add(edit); } assertFalse(original.equals(edited)); } strategy = canonical.original(origTree).build(); for (Node n : edited) { strategy.put(n); } Set<Node> edittedResult = new HashSet<>(); DAG root = strategy.buildRoot(); edittedResult.addAll(toNode(flatten(root))); assertEquals(edited.size(), edittedResult.size()); assertEquals(edited, edittedResult); }
@Test public void nodeReplacedOnEditsWithBaseRevTree() { final RevTree origTree = manuallyCreateBucketsTree(); store.put(origTree); final Set<Node> original = new HashSet<>(); final Set<Node> edited = new HashSet<>(); { Iterator<NodeRef> it = new DepthTreeIterator("", ObjectId.NULL, origTree, store, Strategy.RECURSIVE_FEATURES_ONLY); while (it.hasNext()) { original.add(it.next().getNode()); } for (Node n : original) { ObjectId oid = RevObjectTestSupport.hashString(n.toString()); Node edit = RevObjectFactory.defaultInstance().createNode(n.getName(), oid, ObjectId.NULL, TYPE.FEATURE, n.bounds().orNull(), null); edited.add(edit); } assertFalse(original.equals(edited)); } strategy = canonical.original(origTree).build(); for (Node n : edited) { strategy.put(n); } Set<Node> edittedResult = new HashSet<>(); DAG root = strategy.buildRoot(); edittedResult.addAll(toNode(flatten(root))); assertEquals(edited.size(), edittedResult.size()); assertEquals(edited, edittedResult); }
@Test public void promoteLeafNodes() { final RevTree original = manuallyCreateLeafTree( CanonicalNodeNameOrder.normalizedSizeLimit(0)); store.put(original); strategy = canonical.original(original).build(); final int numNodes = 2 * strategy.normalizedSizeLimit(0); Stopwatch sw = Stopwatch.createStarted(); for (int i = 0; i < numNodes; i++) { Node node = featureNode("f", i, true); strategy.put(node); } System.err.printf("Added %,d nodes in %s\n", numNodes, sw.stop()); DAG root = strategy.buildRoot(); assertTrue(children(root).isEmpty()); assertFalse(buckets(root).isEmpty()); assertEquals(1, strategy.depth()); List<NodeId> flattenedNodes = flatten(root); assertEquals(numNodes, flattenedNodes.size()); }
@Test public void buildSplittedDAGFromScratch() { strategy = canonical.build(); final int numNodes = 2 * strategy.normalizedSizeLimit(0); for (int i = 0; i < numNodes; i++) { Node node = featureNode("f", i, true); strategy.put(node); } DAG root = strategy.buildRoot(); assertTrue(children(root).isEmpty()); assertFalse(buckets(root).isEmpty()); assertEquals(1, strategy.depth()); List<NodeId> flattenedNodes = flatten(root); assertEquals(numNodes, flattenedNodes.size()); }
@Test public void promoteLeafNodes() { final RevTree original = manuallyCreateLeafTree( CanonicalNodeNameOrder.normalizedSizeLimit(0)); store.put(original); strategy = canonical.original(original).build(); final int numNodes = 2 * strategy.normalizedSizeLimit(0); Stopwatch sw = Stopwatch.createStarted(); for (int i = 0; i < numNodes; i++) { Node node = featureNode("f", i, true); strategy.put(node); } System.err.printf("Added %,d nodes in %s\n", numNodes, sw.stop()); DAG root = strategy.buildRoot(); assertTrue(children(root).isEmpty()); assertFalse(buckets(root).isEmpty()); assertEquals(1, strategy.depth()); List<NodeId> flattenedNodes = flatten(root); assertEquals(numNodes, flattenedNodes.size()); }
@Test public void buildSimpleDAGFromScratch() { strategy = canonical.build(); for (int i = 0; i < strategy.normalizedSizeLimit(0); i++) { Node node = featureNode("f", i); strategy.put(node); } DAG root = strategy.buildRoot(); assertTrue(buckets(root).isEmpty()); assertFalse(children(root).isEmpty()); assertEquals(strategy.normalizedSizeLimit(0), children(root).size()); assertEquals(0, strategy.depth()); }
@Test public void buildSplittedDAGFromScratch() { strategy = canonical.build(); final int numNodes = 2 * strategy.normalizedSizeLimit(0); for (int i = 0; i < numNodes; i++) { Node node = featureNode("f", i, true); strategy.put(node); } DAG root = strategy.buildRoot(); assertTrue(children(root).isEmpty()); assertFalse(buckets(root).isEmpty()); assertEquals(1, strategy.depth()); List<NodeId> flattenedNodes = flatten(root); assertEquals(numNodes, flattenedNodes.size()); }
@Test public void buildSimpleDAGFromScratch() { strategy = canonical.build(); for (int i = 0; i < strategy.normalizedSizeLimit(0); i++) { Node node = featureNode("f", i); strategy.put(node); } DAG root = strategy.buildRoot(); assertTrue(buckets(root).isEmpty()); assertFalse(children(root).isEmpty()); assertEquals(strategy.normalizedSizeLimit(0), children(root).size()); assertEquals(0, strategy.depth()); }