本文整理了Java中org.apache.tinkerpop.gremlin.structure.Graph.vertices()
方法的一些代码示例,展示了Graph.vertices()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.vertices()
方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Graph
类名称:Graph
方法名:vertices
[英]Get the Vertex objects in this graph with the provided vertex ids or Vertex objects themselves. If no ids are provided, get all vertices. Note that a vertex identifier does not need to correspond to the actual id used in the graph. It needs to be a bit more flexible than that in that given the Graph.Features around id support, multiple arguments might be applicable here.
If the graph return true for Features.VertexFeatures#supportsNumericIds() then it should support filters as with:
If the graph return true for Features.VertexFeatures#supportsCustomIds() ()} then it should support filters as with:
If the graph return true for Features.VertexFeatures#supportsAnyIds() ()} then it should support filters as with:
If the graph return true for Features.VertexFeatures#supportsStringIds() ()} then it should support filters as with:
If the graph return true for Features.EdgeFeatures#supportsStringIds() ()} then it should support filters as with:
代码示例来源:origin: thinkaurelius/titan
resultgraph = graph.newTransaction();
for (Map.Entry<Long, Map<String, Object>> vprop : mutatedProperties.entrySet()) {
Vertex v = resultgraph.vertices(vprop.getKey()).next();
for (Map.Entry<String, Object> prop : vprop.getValue().entrySet()) {
v.property(VertexProperty.Cardinality.single, prop.getKey(), prop.getValue());
代码示例来源:origin: apache/tinkerpop
@Override
public void run() {
final long gCounter = IteratorUtils.count(graph.vertices());
assertEquals(1l, gCounter);
final long g1Counter = IteratorUtils.count(g1.vertices());
assertEquals(0l, g1Counter);
}
};
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldEvaluateEquivalentVerticesWithNoSuppliedIds() {
final Vertex v = graph.addVertex();
assertNotNull(v);
final Vertex u = graph.vertices(v.id()).next();
assertNotNull(u);
assertEquals(v, u);
assertEquals(graph.vertices(u.id()).next(), graph.vertices(u.id()).next());
assertEquals(graph.vertices(v.id()).next(), graph.vertices(u.id()).next());
assertEquals(graph.vertices(v.id()).next(), graph.vertices(v.id()).next());
}
代码示例来源:origin: apache/tinkerpop
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldCreateVertex() {
final DetachedVertex detachedVertex = new DetachedVertex(23, "dog", Collections.emptyMap());
detachedVertex.attach(Attachable.Method.create(graph));
assertEquals(7, IteratorUtils.count(graph.vertices()));
final AtomicInteger dogTimes = new AtomicInteger(0);
graph.vertices().forEachRemaining(vertex -> {
if (vertex.label().equals("dog")) {
dogTimes.incrementAndGet();
}
});
assertEquals(1, dogTimes.get());
}
代码示例来源:origin: apache/tinkerpop
@Test
public void shouldHaveExceptionConsistencyWhenFindVertexByIdThatIsNonExistentViaIterator() {
try {
graph.vertices(graphProvider.convertId(10000l, Vertex.class)).next();
fail("Call to g.vertices(10000l) should throw an exception");
} catch (Exception ex) {
assertThat(ex, IsInstanceOf.instanceOf(NoSuchElementException.class));
}
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
public void shouldEvaluateEquivalentVertexHashCodeWithSuppliedIds() {
final Vertex v = graph.addVertex(T.id, graphProvider.convertId("1", Vertex.class));
final Vertex u = graph.vertices(graphProvider.convertId("1", Vertex.class)).next();
assertEquals(v, u);
final Set<Vertex> set = new HashSet<>();
set.add(v);
set.add(v);
set.add(u);
set.add(u);
set.add(graph.vertices(graphProvider.convertId("1", Vertex.class)).next());
set.add(graph.vertices(graphProvider.convertId("1", Vertex.class)).next());
assertEquals(1, set.size());
assertEquals(v.hashCode(), u.hashCode());
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
public void shouldNotMixTypesForGettingSpecificVerticesWithStringFirst() {
final Vertex v1 = graph.addVertex();
try {
graph.vertices(graphProvider.convertId("1", Vertex.class), v1);
fail("Should have thrown an exception because id arguments were mixed.");
} catch (Exception ex) {
final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement();
assertEquals(expected.getClass(), ex.getClass());
assertEquals(expected.getMessage(), ex.getMessage());
}
}
代码示例来源:origin: JanusGraph/janusgraph
resultgraph = graph.newTransaction();
for (Map.Entry<Long, Map<String, Object>> vertexProperty : mutatedProperties.entrySet()) {
Vertex v = resultgraph.vertices(vertexProperty.getKey()).next();
for (Map.Entry<String, Object> prop : vertexProperty.getValue().entrySet()) {
if (prop.getValue() instanceof List) {
代码示例来源:origin: apache/tinkerpop
/**
* Generate a graph with lots of vertices, then iterate the vertices and remove them from the graph
*/
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_VERTICES)
public void shouldRemoveVerticesWithoutConcurrentModificationException() {
for (int i = 0; i < 100; i++) {
graph.addVertex();
}
final Iterator<Vertex> vertexIterator = graph.vertices();
assertTrue(vertexIterator.hasNext());
while (vertexIterator.hasNext()) {
vertexIterator.next().remove();
}
assertFalse(vertexIterator.hasNext());
tryCommit(graph, graph -> assertFalse(graph.vertices().hasNext()));
}
代码示例来源:origin: apache/tinkerpop
public static Consumer<Graph> getAssertVertexEdgeCounts(final int expectedVertexCount, final int expectedEdgeCount) {
return (g) -> {
assertEquals(expectedVertexCount, IteratorUtils.count(g.vertices()));
assertEquals(expectedEdgeCount, IteratorUtils.count(g.edges()));
};
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS)
public void shouldAddVertexWithUserSuppliedAnyIdUsingString() {
final UUID uuid = UUID.randomUUID();
graph.addVertex(T.id, uuid.toString());
graph.addVertex();
tryCommit(graph, graph -> {
final Vertex v = graph.vertices(uuid.toString()).next();
assertEquals(uuid.toString(), v.id());
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
public void shouldNotMixTypesForGettingSpecificVerticesWithVertexFirst() {
final Vertex v1 = graph.addVertex();
try {
graph.vertices(v1, graphProvider.convertId("1", Vertex.class));
fail("Should have thrown an exception because id arguments were mixed.");
} catch (Exception ex) {
final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement();
assertEquals(expected.getClass(), ex.getClass());
assertEquals(expected.getMessage(), ex.getMessage());
}
}
代码示例来源:origin: apache/tinkerpop
private Iterable<Vertex> getVerticesAndNormalizeIfRequired(final Graph graph) {
final Iterable<Vertex> vertices;
if (normalize) {
vertices = new ArrayList<>();
final Iterator<Vertex> vertexIterator = graph.vertices();
while (vertexIterator.hasNext()) {
((Collection<Vertex>) vertices).add(vertexIterator.next());
}
Collections.sort((List<Vertex>) vertices, Comparators.ELEMENT_COMPARATOR);
} else
vertices = IteratorUtils.list(graph.vertices());
return vertices;
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_PROPERTY)
public void shouldAllowRemovalFromVertexWhenAlreadyRemoved() {
final Vertex v = graph.addVertex("name", "marko");
tryCommit(graph);
final Vertex v1 = graph.vertices(v.id()).next();
try {
final Property p = v1.property("name");
p.remove();
p.remove();
v1.property("name").remove();
v1.property("name").remove();
} catch (Exception ex) {
fail("Removing a vertex property that was already removed should not throw an exception");
}
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateVerticesWithCustomIdSupportUsingReferenceVertex() {
final Vertex v1 = graph.addVertex();
graph.addVertex();
tryCommit(graph, graph -> {
final Vertex v = graph.vertices(ReferenceFactory.detach(v1)).next();
assertEquals(v1.id(), v.id());
assertThat(v, is(not(instanceOf(ReferenceVertex.class))));
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateVerticesWithCustomIdSupportUsingStringRepresentations() {
final Vertex v1 = graph.addVertex();
final Vertex v2 = graph.addVertex();
graph.addVertex();
tryCommit(graph, graph -> {
assertEquals(2, IteratorUtils.count(graph.vertices(v1.id().toString(), v2.id().toString())));
});
}
代码示例来源:origin: apache/tinkerpop
public static void createRandomGraph(final Graph graph, final int numberOfVertices, final int maxNumberOfEdgesPerVertex) {
final Random random = new Random();
for (int i = 0; i < numberOfVertices; i++) {
graph.addVertex(T.id, i);
}
graph.vertices().forEachRemaining(vertex -> {
for (int i = 0; i < random.nextInt(maxNumberOfEdgesPerVertex); i++) {
final Vertex other = graph.vertices(random.nextInt(numberOfVertices)).next();
vertex.addEdge("link", other);
}
});
}
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
public void shouldCountVerticesEdgesOnPreTransactionCommit() {
// see a more complex version of this test at GraphTest.shouldProperlyCountVerticesAndEdgesOnAddRemove()
Vertex v1 = graph.addVertex();
graph.tx().commit();
assertVertexEdgeCounts(graph, 1, 0);
final Vertex v2 = graph.addVertex();
v1 = graph.vertices(v1.id()).next();
v1.addEdge("friend", v2);
assertVertexEdgeCounts(graph, 2, 1);
graph.tx().commit();
assertVertexEdgeCounts(graph, 2, 1);
}
代码示例来源:origin: apache/tinkerpop
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertex() throws Exception {
final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
final Vertex v = graph.vertices(convertToVertexId("marko")).next();
final String json = mapper.writeValueAsString(v);
final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
assertEquals(GraphSONTokens.VERTEX, m.get(GraphSONTokens.TYPE));
assertEquals(v.label(), m.get(GraphSONTokens.LABEL));
assertNotNull(m.get(GraphSONTokens.ID));
final Map<String,List<Map<String,Object>>> properties = (Map<String,List<Map<String,Object>>>) m.get(GraphSONTokens.PROPERTIES);
assertEquals(v.value("name").toString(), properties.get("name").get(0).get(GraphSONTokens.VALUE).toString());
assertEquals((Integer) v.value("age"), properties.get("age").get(0).get(GraphSONTokens.VALUE));
assertEquals(1, properties.get("name").size());
assertEquals(1, properties.get("age").size());
assertEquals(2, properties.size());
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadGraphMLWithoutEdgeIds() throws IOException {
final GraphReader reader = GraphMLReader.build().strict(false).create();
try (final InputStream stream = IoTest.class.getResourceAsStream(TestHelper.convertPackageToResourcePath(GraphMLResourceAccess.class) + "graph-no-edge-ids.xml")) {
reader.readGraph(stream, graph);
}
assertEquals(1, IteratorUtils.count(graph.edges()));
assertEquals(2, IteratorUtils.count(graph.vertices()));
}
内容来源于网络,如有侵权,请联系作者删除!