本文整理了Java中org.securegraph.Vertex
类的一些代码示例,展示了Vertex
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex
类的具体详情如下:
包路径:org.securegraph.Vertex
类名称:Vertex
暂无
代码示例来源:origin: org.securegraph/securegraph-test
@Override
protected String convert(Vertex o) {
return o.getId();
}
});
代码示例来源:origin: org.securegraph/securegraph-core
private void findPathsRecursive(List<Path> foundPaths, final Vertex sourceVertex, Vertex destVertex, int hops, int totalHops, Set<String> seenVertices, Path currentPath, ProgressCallback progressCallback, final Authorizations authorizations) {
// if this is our first source vertex report progress back to the progress callback
boolean firstLevelRecursion = hops == totalHops;
seenVertices.add(sourceVertex.getId());
if (sourceVertex.getId().equals(destVertex.getId())) {
foundPaths.add(currentPath);
} else if (hops > 0) {
Iterable<Vertex> vertices = sourceVertex.getVertices(Direction.BOTH, authorizations);
int vertexCount = 0;
if (firstLevelRecursion) {
vertices = toList(vertices);
vertexCount = ((List<Vertex>) vertices).size();
}
int i = 0;
for (Vertex child : vertices) {
if (firstLevelRecursion) {
// this will never get to 100% since i starts at 0. which is good. 100% signifies done and we still have work to do.
double progressPercent = (double) i / (double) vertexCount;
progressCallback.progress(progressPercent, ProgressCallback.Step.SEARCHING_EDGES, i + 1, vertexCount);
}
if (!seenVertices.contains(child.getId())) {
findPathsRecursive(foundPaths, child, destVertex, hops - 1, totalHops, seenVertices, new Path(currentPath, child.getId()), progressCallback, authorizations);
}
i++;
}
}
seenVertices.remove(sourceVertex.getId());
}
}
代码示例来源:origin: org.securegraph.examples/examples-base
public static JSONObject vertexToJson(Vertex vertex) {
JSONObject json = new JSONObject();
json.put("id", vertex.getId());
JSONArray propertiesJson = new JSONArray();
for (Property property : vertex.getProperties()) {
propertiesJson.put(propertyYoJson(property));
}
json.put("properties", propertiesJson);
return json;
}
代码示例来源:origin: lumifyio/securegraph
public VertexBuilder prepareVertex(Vertex vertex) {
return prepareVertex(vertex.getId(), vertex.getVisibility());
}
代码示例来源:origin: lumifyio/securegraph
@Override
public void removeVertex(Vertex vertex, Authorizations authorizations) {
if (!((InMemoryVertex) vertex).canRead(authorizations)) {
return;
}
List<Edge> edgesToRemove = toList(vertex.getEdges(Direction.BOTH, authorizations));
for (Edge edgeToRemove : edgesToRemove) {
removeEdge(edgeToRemove, authorizations);
}
this.vertices.remove(vertex.getId());
getSearchIndex().removeElement(this, vertex, authorizations);
if (hasEventListeners()) {
fireGraphEvent(new RemoveVertexEvent(this, vertex));
}
}
代码示例来源:origin: org.securegraph/securegraph-blueprints
@Override
public Iterable<Edge> getEdges(Direction direction, final String... labels) {
final org.securegraph.Direction sgDirection = SecureGraphBlueprintsConvert.toSecureGraph(direction);
final Authorizations authorizations = getGraph().getAuthorizationsProvider().getAuthorizations();
return new ConvertingIterable<org.securegraph.Edge, Edge>(getSecureGraphElement().getEdges(sgDirection, labels, authorizations)) {
@Override
protected Edge convert(org.securegraph.Edge edge) {
return SecureGraphBlueprintsEdge.create(getGraph(), edge, authorizations);
}
};
}
代码示例来源:origin: org.securegraph/securegraph-test
@Test
public void testGetEdge() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1to2label1", v1, v2, "label1", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1to2label2", v1, v2, "label2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e2to1", v2.getId(), v1.getId(), "label1", VISIBILITY_A, AUTHORIZATIONS_A);
v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(3, count(v1.getEdges(Direction.BOTH, AUTHORIZATIONS_A)));
assertEquals(2, count(v1.getEdges(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals(1, count(v1.getEdges(Direction.IN, AUTHORIZATIONS_A)));
assertEquals(3, count(v1.getEdges(v2, Direction.BOTH, AUTHORIZATIONS_A)));
assertEquals(2, count(v1.getEdges(v2, Direction.OUT, AUTHORIZATIONS_A)));
assertEquals(1, count(v1.getEdges(v2, Direction.IN, AUTHORIZATIONS_A)));
assertEquals(2, count(v1.getEdges(v2, Direction.BOTH, "label1", AUTHORIZATIONS_A)));
assertEquals(1, count(v1.getEdges(v2, Direction.OUT, "label1", AUTHORIZATIONS_A)));
assertEquals(1, count(v1.getEdges(v2, Direction.IN, "label1", AUTHORIZATIONS_A)));
assertEquals(3, count(v1.getEdges(v2, Direction.BOTH, new String[]{"label1", "label2"}, AUTHORIZATIONS_A)));
assertEquals(2, count(v1.getEdges(v2, Direction.OUT, new String[]{"label1", "label2"}, AUTHORIZATIONS_A)));
assertEquals(1, count(v1.getEdges(v2, Direction.IN, new String[]{"label1", "label2"}, AUTHORIZATIONS_A)));
assertArrayEquals(new String[]{"label1", "label2"}, toArray(v1.getEdgeLabels(Direction.OUT, AUTHORIZATIONS_A), String.class));
assertArrayEquals(new String[]{"label1"}, toArray(v1.getEdgeLabels(Direction.IN, AUTHORIZATIONS_A), String.class));
assertArrayEquals(new String[]{"label1", "label2"}, toArray(v1.getEdgeLabels(Direction.BOTH, AUTHORIZATIONS_A), String.class));
}
代码示例来源:origin: org.securegraph/securegraph-test
@Test
public void testGetVerticesFromVertex() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v4 = graph.addVertex("v4", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge(v1, v2, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge(v1, v3, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge(v1, v4, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge(v2, v3, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(3, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
assertEquals(3, count(v1.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals(0, count(v1.getVertices(Direction.IN, AUTHORIZATIONS_A)));
v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
assertEquals(2, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
assertEquals(1, count(v2.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals(1, count(v2.getVertices(Direction.IN, AUTHORIZATIONS_A)));
v3 = graph.getVertex("v3", AUTHORIZATIONS_A);
assertEquals(2, count(v3.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
assertEquals(0, count(v3.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals(2, count(v3.getVertices(Direction.IN, AUTHORIZATIONS_A)));
v4 = graph.getVertex("v4", AUTHORIZATIONS_A);
assertEquals(1, count(v4.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
assertEquals(0, count(v4.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals(1, count(v4.getVertices(Direction.IN, AUTHORIZATIONS_A)));
}
代码示例来源:origin: org.securegraph/securegraph-core
private void findPathsSetIntersection(List<Path> foundPaths, Vertex sourceVertex, Vertex destVertex, ProgressCallback progressCallback, Authorizations authorizations) {
String sourceVertexId = sourceVertex.getId();
String destVertexId = destVertex.getId();
progressCallback.progress(0.1, ProgressCallback.Step.SEARCHING_SOURCE_VERTEX_EDGES);
Set<String> sourceVertexConnectedVertexIds = toSet(sourceVertex.getVertexIds(Direction.BOTH, authorizations));
progressCallback.progress(0.3, ProgressCallback.Step.SEARCHING_DESTINATION_VERTEX_EDGES);
Set<String> destVertexConnectedVertexIds = toSet(destVertex.getVertexIds(Direction.BOTH, authorizations));
progressCallback.progress(0.6, ProgressCallback.Step.MERGING_EDGES);
sourceVertexConnectedVertexIds.retainAll(destVertexConnectedVertexIds);
progressCallback.progress(0.9, ProgressCallback.Step.ADDING_PATHS);
for (String connectedVertexId : sourceVertexConnectedVertexIds) {
foundPaths.add(new Path(sourceVertexId, connectedVertexId, destVertexId));
}
}
代码示例来源:origin: org.securegraph/securegraph-test
assertEquals(1, count(e.getProperties()));
assertEquals("valueA", e.getPropertyValues("propA").iterator().next());
assertEquals(1, count(v1.getEdges(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals("label1", single(v1.getEdgeLabels(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals(1, count(v2.getEdges(Direction.IN, AUTHORIZATIONS_A)));
assertEquals("label1", single(v2.getEdgeLabels(Direction.IN, AUTHORIZATIONS_A)));
assertEquals("valueA", e.getPropertyValues("propA").iterator().next());
v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(1, count(v1.getEdges(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals("label2", single(v1.getEdgeLabels(Direction.OUT, AUTHORIZATIONS_A)));
v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
assertEquals(1, count(v2.getEdges(Direction.IN, AUTHORIZATIONS_A)));
assertEquals("label2", single(v2.getEdgeLabels(Direction.IN, AUTHORIZATIONS_A)));
assertEquals("valueA", e.getPropertyValues("propA").iterator().next());
v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(1, count(v1.getEdges(Direction.OUT, AUTHORIZATIONS_A)));
assertEquals("label3", single(v1.getEdgeLabels(Direction.OUT, AUTHORIZATIONS_A)));
v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
assertEquals(1, count(v2.getEdges(Direction.IN, AUTHORIZATIONS_A)));
assertEquals("label3", single(v2.getEdgeLabels(Direction.IN, AUTHORIZATIONS_A)));
代码示例来源:origin: org.securegraph/securegraph-test
@Test
public void testElementMutationDoesntChangeObjectUntilSave() {
Vertex v = graph.addVertex("v1", VISIBILITY_EMPTY, AUTHORIZATIONS_EMPTY);
v.setProperty("prop1", "value1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B);
ElementMutation<Vertex> m = v.prepareMutation()
.setProperty("prop1", "value2", VISIBILITY_A)
.setProperty("prop2", "value2", VISIBILITY_A);
assertEquals(1, count(v.getProperties()));
assertEquals("value1", v.getPropertyValue("prop1"));
m.save(AUTHORIZATIONS_A_AND_B);
assertEquals(2, count(v.getProperties()));
assertEquals("value2", v.getPropertyValue("prop1"));
assertEquals("value2", v.getPropertyValue("prop2"));
}
代码示例来源:origin: lumifyio/securegraph
v.prepareMutation()
.addPropertyValue("propid1a", "prop1", "value1a", VISIBILITY_A)
.addPropertyValue("propid2a", "prop2", "value2a", VISIBILITY_A)
.save(AUTHORIZATIONS_A_AND_B);
v = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals("value1a", v.getPropertyValues("prop1").iterator().next());
assertEquals("value2a", v.getPropertyValues("prop2").iterator().next());
assertEquals("value3a", v.getPropertyValues("prop3").iterator().next());
assertEquals(3, count(v.getProperties()));
v.prepareMutation()
.addPropertyValue("propid1a", "prop1", "value1b", VISIBILITY_A)
.addPropertyValue("propid2a", "prop2", "value2b", VISIBILITY_A)
.save(AUTHORIZATIONS_A_AND_B);
v = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(1, count(v.getPropertyValues("prop1")));
assertEquals("value1b", v.getPropertyValues("prop1").iterator().next());
assertEquals(1, count(v.getPropertyValues("prop2")));
assertEquals("value2b", v.getPropertyValues("prop2").iterator().next());
assertEquals(1, count(v.getPropertyValues("prop3")));
assertEquals("value3a", v.getPropertyValues("prop3").iterator().next());
assertEquals(3, count(v.getProperties()));
v.addPropertyValue("propid1b", "prop1", "value1a-new", VISIBILITY_A, AUTHORIZATIONS_A_AND_B);
v = graph.getVertex("v1", AUTHORIZATIONS_A);
assertContains("value1b", v.getPropertyValues("prop1"));
assertContains("value1a-new", v.getPropertyValues("prop1"));
assertEquals(4, count(v.getProperties()));
代码示例来源:origin: org.securegraph/securegraph-test
.setProperty("prop2", "value2", VISIBILITY_B)
.save(AUTHORIZATIONS_A_AND_B);
assertEquals(1, count(vertexAdded.getProperties("prop1")));
assertEquals("value1", vertexAdded.getPropertyValues("prop1").iterator().next());
assertEquals(1, count(vertexAdded.getProperties("prop2")));
assertEquals("value2", vertexAdded.getPropertyValues("prop2").iterator().next());
graph.flush();
assertEquals(1, count(v.getProperties("prop1")));
assertEquals("value1", v.getPropertyValues("prop1").iterator().next());
assertEquals(1, count(v.getProperties("prop2")));
assertEquals("value2", v.getPropertyValues("prop2").iterator().next());
new AddPropertyEvent(graph, vertexAdded, vertexAdded.getProperty("prop1")),
new AddPropertyEvent(graph, vertexAdded, vertexAdded.getProperty("prop2"))
);
graphEvents.clear();
vertexAdded = v.prepareMutation()
.addPropertyValue("key1", "prop1Mutation", "value1Mutation", VISIBILITY_A)
.save(AUTHORIZATIONS_A_AND_B);
graph.flush();
v = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B);
assertEquals(1, count(v.getProperties("prop1Mutation")));
assertEquals("value1Mutation", v.getPropertyValues("prop1Mutation").iterator().next());
assertEvents(
new AddPropertyEvent(graph, vertexAdded, vertexAdded.getProperty("prop1Mutation"))
);
代码示例来源:origin: lumifyio/securegraph
Vertex v = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
v.prepareMutation()
.addPropertyValue("propid1a", "prop1", "value1a", VISIBILITY_A)
.addPropertyValue("propid1b", "prop1", "value1b", VISIBILITY_A)
Property prop1_propid1a = v.getProperty("propid1a", "prop1");
Property prop1_propid1b = v.getProperty("propid1b", "prop1");
v.removeProperty("prop1", AUTHORIZATIONS_A_AND_B);
graph.flush();
assertEquals(1, count(v.getProperties()));
v = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(1, count(v.getProperties()));
this.graphEvents.clear();
Property prop2_propid2a = v.getProperty("propid2a", "prop2");
v.removeProperty("propid2a", "prop2", AUTHORIZATIONS_A_AND_B);
graph.flush();
assertEquals(0, count(v.getProperties()));
v = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(0, count(v.getProperties()));
代码示例来源:origin: org.securegraph/securegraph-test
assertEquals(1, count(v.getProperties("prop1")));
Property prop1 = v.getProperties("prop1").iterator().next();
if (prop1 instanceof HasTimestamp) {
assertTrue("timestamp should be more than 0", ((HasTimestamp) prop1).getTimestamp() > 0);
v.prepareMutation()
.setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A)
.save(AUTHORIZATIONS_A_AND_B);
assertEquals(1, count(v.getProperties("prop1")));
prop1 = v.getProperties("prop1").iterator().next();
prop1Metadata = prop1.getMetadata();
assertEquals(2, prop1Metadata.entrySet().size());
v.setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A, AUTHORIZATIONS_A_AND_B);
assertEquals(1, count(v.getProperties("prop1")));
prop1 = v.getProperties("prop1").iterator().next();
prop1Metadata = prop1.getMetadata();
assertEquals(2, prop1Metadata.entrySet().size());
代码示例来源:origin: org.securegraph/securegraph-test
Property prop1_propid1a = v1.getProperty("propid1a", "prop1");
Property prop1_propid1b = v1.getProperty("propid1b", "prop1");
v1.prepareMutation()
.removeProperties("prop1")
.save(AUTHORIZATIONS_A_AND_B);
graph.flush();
assertEquals(1, count(v1.getProperties()));
v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(1, count(v1.getProperties()));
Property prop2_propid2a = v1.getProperty("propid2a", "prop2");
v1.prepareMutation()
.removeProperties("propid2a", "prop2")
.save(AUTHORIZATIONS_A_AND_B);
graph.flush();
assertEquals(0, count(v1.getProperties()));
v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(0, count(v1.getProperties()));
assertEvents(
new RemovePropertyEvent(graph, v1, prop2_propid2a)
代码示例来源:origin: org.securegraph/securegraph-test
.save(AUTHORIZATIONS_A);
assertEquals(3, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties("prop1")));
v1.markPropertyHidden("key1", "prop1", VISIBILITY_A, VISIBILITY_A_AND_B, AUTHORIZATIONS_A_AND_B);
List<Property> properties = toList(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties("prop1"));
assertEquals(2, count(properties));
boolean foundProp1Key2 = false;
assertTrue("Prop1Key1VisB not found", foundProp1Key1VisB);
List<Property> hiddenProperties = toList(graph.getVertex("v1", FetchHint.ALL_INCLUDING_HIDDEN, AUTHORIZATIONS_A_AND_B).getProperties());
assertEquals(3, hiddenProperties.size());
boolean foundProp1Key1VisA = false;
assertTrue("Prop1Key1VisA not found", foundProp1Key1VisA);
v1.markPropertyVisible("key1", "prop1", VISIBILITY_A, VISIBILITY_A_AND_B, AUTHORIZATIONS_A_AND_B);
assertEquals(3, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties("prop1")));
代码示例来源:origin: org.securegraph/securegraph-test
@Test
public void testConcurrentModificationOfProperties() {
Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY)
.setProperty("prop1", "value1", VISIBILITY_A)
.setProperty("prop2", "value2", VISIBILITY_A)
.save(AUTHORIZATIONS_A_AND_B);
int i = 0;
for (Property p : v.getProperties()) {
assertNotNull(p.toString());
if (i == 0) {
v.setProperty("prop3", "value3", VISIBILITY_A, AUTHORIZATIONS_A_AND_B);
}
i++;
}
}
代码示例来源:origin: org.securegraph/securegraph-test
@Test
public void testAddVertexWithPropertiesWithTwoDifferentVisibilities() {
Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY)
.setProperty("prop1", "value1a", VISIBILITY_A)
.setProperty("prop1", "value1b", VISIBILITY_B)
.save(AUTHORIZATIONS_A_AND_B);
assertEquals(2, count(v.getProperties("prop1")));
v = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B);
assertEquals(2, count(v.getProperties("prop1")));
v = graph.getVertex("v1", AUTHORIZATIONS_A);
assertEquals(1, count(v.getProperties("prop1")));
assertEquals("value1a", v.getPropertyValue("prop1"));
v = graph.getVertex("v1", AUTHORIZATIONS_B);
assertEquals(1, count(v.getProperties("prop1")));
assertEquals("value1b", v.getPropertyValue("prop1"));
}
代码示例来源:origin: org.securegraph/securegraph-test
@Test
public void testChangeVisibilityOnStreamingProperty() throws IOException {
String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
PropertyValue propSmall = new StreamingPropertyValue(new ByteArrayInputStream("value1".getBytes()), String.class);
PropertyValue propLarge = new StreamingPropertyValue(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class);
String largePropertyName = "propLarge/\\*!@#$%^&*()[]{}|";
graph.prepareVertex("v1", VISIBILITY_A)
.setProperty("propSmall", propSmall, VISIBILITY_A)
.setProperty(largePropertyName, propLarge, VISIBILITY_A)
.save(AUTHORIZATIONS_A_AND_B);
assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties()));
graph.getVertex("v1", AUTHORIZATIONS_A)
.prepareMutation()
.alterPropertyVisibility("propSmall", VISIBILITY_B)
.save(AUTHORIZATIONS_A_AND_B);
assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties()));
graph.getVertex("v1", AUTHORIZATIONS_A)
.prepareMutation()
.alterPropertyVisibility(largePropertyName, VISIBILITY_B)
.save(AUTHORIZATIONS_A_AND_B);
assertEquals(0, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties()));
assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties()));
}
内容来源于网络,如有侵权,请联系作者删除!