/** * Creates a {@code NodeRef} pointing to the provided {@code node} and parent path and metadata * id. * * @param parentPath the parent path of the node * @param node the {@code Node} to point to * @param metadataId the metadata id * @return the new {@code NodeRef} */ public static NodeRef create(String parentPath, Node node, ObjectId metadataId) { return new NodeRef(node, parentPath, metadataId); }
/** * Creates a {@code NodeRef} pointing to the provided {@code node} and parent path. * * @param parentPath the parent path of the node * @param node the {@code Node} to point to * @return the new {@code NodeRef} */ public static NodeRef create(String parentPath, Node node) { return new NodeRef(node, parentPath, ObjectId.NULL); }
/** * Creates a {@code NodeRef} pointing to the provided {@code node} and parent path and metadata * id. * * @param parentPath the parent path of the node * @param node the {@code Node} to point to * @param metadataId the metadata id * @return the new {@code NodeRef} */ public static NodeRef create(String parentPath, Node node, ObjectId metadataId) { return new NodeRef(node, parentPath, metadataId); }
/** * Creates a {@code NodeRef} pointing to the provided {@code node} and parent path. * * @param parentPath the parent path of the node * @param node the {@code Node} to point to * @return the new {@code NodeRef} */ public static NodeRef create(String parentPath, Node node) { return new NodeRef(node, parentPath, ObjectId.NULL); }
/** * Creates a {@code NodeRef} pointing to the provided {@code Node} with a {@code null} parent * path, the provided {@code Node} must be a root node. * * @param node the {@code Node} to point to */ public static NodeRef createRoot(Node node) { Preconditions.checkArgument(NodeRef.ROOT.equals(node.getName()), "A root NodeRef can only be created for a root node"); return new NodeRef(node, null, ObjectId.NULL); }
@Override public NodeRef apply(Node node) { return new NodeRef(node, treePath, node.getMetadataId().or(metadataId)); } };
/** * Creates a {@code NodeRef} pointing to the provided {@code Node} with a {@code null} parent * path, the provided {@code Node} must be a root node. * * @param node the {@code Node} to point to */ public static NodeRef createRoot(Node node) { Preconditions.checkArgument(NodeRef.ROOT.equals(node.getName()), "A root NodeRef can only be created for a root node"); return new NodeRef(node, null, ObjectId.NULL); }
@Override public NodeRef apply(Node node) { return new NodeRef(node, treePath, node.getMetadataId().or(metadataId)); } };
public static NodeRef readNodeRef(DataInput in) throws IOException { Node node = readNode(in); final byte[] metadataId = new byte[20]; in.readFully(metadataId); String parentPath = in.readUTF(); return new NodeRef(node, parentPath, ObjectId.createNoClone(metadataId)); }
public static NodeRef readNodeRef(DataInput in) throws IOException { Node node = readNode(in); final ObjectId metadataId = ObjectId.readFrom(in); String parentPath = in.readUTF(); return new NodeRef(node, parentPath, metadataId); }
public NodeRef readNodeRef(DataInput in) throws IOException { Node node = readNode(in); final ObjectId metadataId = readObjectId(in); String parentPath = in.readUTF(); return new NodeRef(node, parentPath, metadataId); }
public NodeRef readNodeRef(DataInput in) throws IOException { Node node = readNode(in); final ObjectId metadataId = readObjectId(in); String parentPath = in.readUTF(); return new NodeRef(node, parentPath, metadataId); }
@Override public DiffEntry apply(String featurePath) { Node node = RevObjectFactory.defaultInstance().createNode( NodeRef.nodeFromPath(featurePath), ObjectId.NULL, ObjectId.NULL, TYPE.FEATURE, null, null); String parentPath = NodeRef.parentPath(featurePath); NodeRef oldFeature = new NodeRef(node, parentPath, ObjectId.NULL); return new DiffEntry(oldFeature, null); }};
private NodeRef tree(String path, ObjectId treeId, @Nullable ObjectId metadataId) { String parentPath = NodeRef.parentPath(path); String name = NodeRef.nodeFromPath(path); Node node = treeNode(name, treeId, metadataId); return new NodeRef(node, parentPath, ObjectId.NULL); }
private NodeRef tree(String path, ObjectId treeId, @Nullable ObjectId metadataId) { String parentPath = NodeRef.parentPath(path); String name = NodeRef.nodeFromPath(path); Node node = treeNode(name, treeId, metadataId); return new NodeRef(node, parentPath, ObjectId.NULL); }
@Test public void testFullEntry() throws IOException { Node ln = RevObjectTestSupport.featureNode("testNode", 1); Node rn = RevObjectTestSupport.featureNode("testNode", 2); ObjectId metadataId = RevObjectTestSupport.hashString("test"); NodeRef left = new NodeRef(ln, "parent/path", metadataId); NodeRef right = new NodeRef(rn, "parent/path", metadataId); DiffEntry entry = new DiffEntry(left, right); serializer.write(out, entry); byte[] array = stream.toByteArray(); DiffEntry read = serializer.read(new DataInputStream(new ByteArrayInputStream(array))); assertEquals(entry, read); }
private NodeRef tree(String path, ObjectId treeId, ObjectId metadataId) { String parentPath = NodeRef.parentPath(path); String name = NodeRef.nodeFromPath(path); Node node = treeNode(name, treeId, metadataId); return new NodeRef(node, parentPath, ObjectId.NULL); }
private NodeRef tree(String path, ObjectId treeId, ObjectId metadataId) { String parentPath = NodeRef.parentPath(path); String name = NodeRef.nodeFromPath(path); Node node = treeNode(name, treeId, metadataId); return new NodeRef(node, parentPath, ObjectId.NULL); }
@Test public void testNullNodeRef() throws IOException { // null parent path is only allowed for NodeRef.ROOT named nodes Node rn = RevObjectTestSupport.featureNode("testNode", 2); ObjectId metadataId = RevObjectTestSupport.hashString("test"); NodeRef left = null; NodeRef right = new NodeRef(rn, "parent/path", metadataId); DiffEntry entry = new DiffEntry(left, right); serializer.write(out, entry); byte[] array = stream.toByteArray(); DiffEntry read = serializer.read(new DataInputStream(new ByteArrayInputStream(array))); assertEquals(entry, read); }
@Test public void testNodeAndNodeRefToString() { Node node = RevObjectFactory.defaultInstance().createNode("Points.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0000"), ObjectId.NULL, TYPE.FEATURE, null, null); NodeRef nodeRef = new NodeRef(node, "Points", ObjectId.NULL); String readableNode = nodeRef.toString(); assertTrue(readableNode .equals("NodeRef[Points/Points.1 -> " + node.getObjectId().toString() + "]")); }