public Node update(final ObjectId newId, final @Nullable Envelope newBounds) { ObjectId mdId = getMetadataId().or(ObjectId.NULL); return Node.create(getName(), newId, mdId, getType(), newBounds, getExtraData()); }
static BoundedSimpleFeature empty(SimpleFeatureType type, Node node, CoordinateReferenceSystem crs) { FeatureId fid = new FeatureIdImpl(node.getName()); ReferencedEnvelope env = new ReferencedEnvelope(crs); node.expand(env); return new BoundedSimpleFeature(Collections.emptyList(), type, fid, env); } }
/** * Provides for natural ordering of {@code Node}, based on {@link #getName() name} */ public final @Override int compareTo(Node o) { int c = getName().compareTo(o.getName()); if (c == 0) { c = getType().compareTo(o.getType()); } if (c == 0) { c = getObjectId().compareTo(o.getObjectId()); } return c; }
private void append(StringBuilder sb, Node node, int indent) { sb.append(Strings.repeat(" ", indent)).append(node.getName()).append("->") .append(node.getObjectId()).append(" (").append(node.getMetadataId()).append(")\n"); }
private void verifyMetadata(Node node) { if (node.getMetadataId().isPresent()) { ObjectId mdId = node.getMetadataId().get(); String msg = "RevFeatureType " + mdId + " is not present (from " + node.getName() + ")"; assertTrue(msg, objectDb.exists(mdId)); } }
private void assertNodesEqual(List<Node> l1, List<Node> l2) { assertEquals(l1, l2); for (int i = 0; i < l1.size(); i++) { Node n1 = l1.get(i); Node n2 = l2.get(i); assertEquals(n1.getExtraData(), n2.getExtraData()); assertEquals(n1.getMetadataId(), n2.getMetadataId()); assertEquals(n1.bounds(), n2.bounds()); } }
/** * 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); }
/** * @return the simple name of the {@link Node} this object points to */ public String name() { return node.getName(); }
private void verifyFeature(Node node) { ObjectId objectId = node.getObjectId(); assertTrue("feature " + node.getName() + " -> " + objectId + " is not present in objectDb", objectDb.exists(objectId)); }
public RevTree build(ObjectStore store) { final ObjectId treeId = this.node.getObjectId(); final RevTree original = EMPTY_TREE_ID.equals(treeId) ? EMPTY : store.getTree(treeId); CanonicalTreeBuilder builder = CanonicalTreeBuilder.create(store, original);// .clearSubtrees(); ImmutableList<Node> currentTrees = original.trees(); currentTrees.forEach((n) -> builder.remove(n.getName())); for (MutableTree childTree : this.childTrees.values()) { childTree.build(store); Node newNode = childTree.node; builder.put(newNode); } final Node oldNode = this.node; RevTree newTree = builder.build(); Envelope newBounds = SpatialOps.boundsOf(newTree); Node newNode = oldNode.update(newTree.getId(), newBounds); this.node = newNode; return newTree; }
/** * Expands the provided {@link Envelope} to encompass the {@code Node} this object points to. * * @param env the {@link Envelope} to expand */ @Override public void expand(Envelope env) { node.expand(env); }
/** * 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; }
/** * @deprecated use {@link #getObjectId()} instead */ @Deprecated public ObjectId objectId() { return node.getObjectId(); }
public boolean remove(Node node) { if (!node.getObjectId().isNull()) { node = node.update(ObjectId.NULL); } int delta = put(node); return -1 == delta; }
/** * @deprecated use {@link RevObjectFactory#createNode} */ public static Node tree(final String name, final ObjectId oid, final ObjectId metadataId) { return create(name, oid, metadataId, TYPE.TREE, null); }
@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); }
@SuppressWarnings("unchecked") public static Map<String, Object> getMaterializedAttributes(Node n) { Object v = n.getExtraData(IndexInfo.FEATURE_ATTRIBUTES_EXTRA_DATA); Preconditions.checkArgument(v == null || v instanceof Map); return (Map<String, Object>) v; }
public Node createNode(String name, @Nullable Envelope bounds) { ObjectId id = RevObjectTestSupport.hashString(name); Node n = Node.create(name, id, ObjectId.NULL, RevObject.TYPE.FEATURE, bounds); if (bounds != null && !bounds.isNull()) { Envelope float32Bounds = n.bounds().get(); Assert.assertTrue(float32Bounds.contains(bounds)); } return n; }