本文整理了Java中org.apache.tinkerpop.gremlin.structure.Graph.edges()
方法的一些代码示例,展示了Graph.edges()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.edges()
方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Graph
类名称:Graph
方法名:edges
[英]Get the Edge objects in this graph with the provided edge ids or Edge objects. If no ids are provided, get all edges. Note that an edge 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.EdgeFeatures#supportsNumericIds() then it should support filters as with:
If the graph return true for Features.EdgeFeatures#supportsCustomIds() ()} then it should support filters as with:
If the graph return true for Features.EdgeFeatures#supportsAnyIds() ()} 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
originalGraphStep.getTraversal().getGraph().get().edges(elementIds)));
代码示例来源:origin: JanusGraph/janusgraph
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (TraversalHelper.onGraphComputer(traversal))
return;
TraversalHelper.getStepsOfClass(GraphStep.class, traversal).forEach(originalGraphStep -> {
if (originalGraphStep.getIds() == null || originalGraphStep.getIds().length == 0) {
//Try to optimize for index calls
final JanusGraphStep<?, ?> janusGraphStep = new JanusGraphStep<>(originalGraphStep);
TraversalHelper.replaceStep(originalGraphStep, janusGraphStep, traversal);
HasStepFolder.foldInIds(janusGraphStep, traversal);
HasStepFolder.foldInHasContainer(janusGraphStep, traversal, traversal);
HasStepFolder.foldInOrder(janusGraphStep, janusGraphStep.getNextStep(), traversal, traversal, janusGraphStep.returnsVertex(), null);
HasStepFolder.foldInRange(janusGraphStep, JanusGraphTraversalUtil.getNextNonIdentityStep(janusGraphStep), traversal, null);
} else {
//Make sure that any provided "start" elements are instantiated in the current transaction
final Object[] ids = originalGraphStep.getIds();
ElementUtils.verifyArgsMustBeEitherIdOrElement(ids);
if (ids[0] instanceof Element) {
//GraphStep constructor ensures that the entire array is elements
final Object[] elementIds = new Object[ids.length];
for (int i = 0; i < ids.length; i++) {
elementIds[i] = ((Element) ids[i]).id();
}
originalGraphStep.setIteratorSupplier(() -> originalGraphStep.returnsVertex() ?
((Graph) originalGraphStep.getTraversal().getGraph().get()).vertices(elementIds) :
((Graph) originalGraphStep.getTraversal().getGraph().get()).edges(elementIds));
}
}
});
}
代码示例来源:origin: apache/tinkerpop
public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
final Iterator<Edge> edgeIterator = hostGraph.edges(attachableEdge.get().id());
return edgeIterator.hasNext() ? Optional.of(edgeIterator.next()) : Optional.empty();
}
代码示例来源:origin: apache/tinkerpop
private static Map<String, String> determineEdgeTypes(final Graph graph) {
final Map<String, String> edgeKeyTypes = new HashMap<>();
final Iterator<Edge> edges = graph.edges();
while (edges.hasNext()) {
final Edge edge = edges.next();
for (String key : edge.keys()) {
if (!edgeKeyTypes.containsKey(key))
edgeKeyTypes.put(key, GraphMLWriter.getStringType(edge.property(key).value()));
}
}
return edgeKeyTypes;
}
代码示例来源:origin: apache/tinkerpop
public GraphStep(final Traversal.Admin traversal, final Class<E> returnClass, final boolean isStart, final Object... ids) {
super(traversal);
this.returnClass = returnClass;
this.ids = (ids.length == 1 && ids[0] instanceof Collection) ? ((Collection) ids[0]).toArray(new Object[((Collection) ids[0]).size()]) : ids;
this.isStart = isStart;
this.iteratorSupplier = () -> (Iterator<E>) (Vertex.class.isAssignableFrom(this.returnClass) ?
this.getTraversal().getGraph().get().vertices(this.ids) :
this.getTraversal().getGraph().get().edges(this.ids));
}
代码示例来源:origin: apache/tinkerpop
private Iterator<? extends Edge> edges() {
if (null == this.ids)
return Collections.emptyIterator();
return IteratorUtils.filter(this.getTraversal().getGraph().get().edges(this.ids), edge -> HasContainer.testAll(edge, this.hasContainers));
}
代码示例来源:origin: apache/tinkerpop
@Test
public void shouldHaveExceptionConsistencyWhenFindEdgeByIdThatIsNonExistentViaIterator() {
try {
graph.edges(graphProvider.convertId(10000l, Edge.class)).next();
fail("Call to g.edges(10000l) should throw an exception");
} catch (Exception ex) {
assertThat(ex, IsInstanceOf.instanceOf(NoSuchElementException.class));
}
}
代码示例来源:origin: apache/tinkerpop
/**
* make a deep clone of the graph elements that preserves ids
*/
public static void cloneElements(final Graph original, final Graph clone) {
original.vertices().forEachRemaining(v -> DetachedFactory.detach(v, true).attach(Attachable.Method.create(clone)));
original.edges().forEachRemaining(e -> DetachedFactory.detach(e, true).attach(Attachable.Method.create(clone)));
}
}
代码示例来源:origin: apache/tinkerpop
private void addEdgeToSubgraph(final Edge edge) {
final Iterator<Edge> edgeIterator = subgraph.edges(edge.id());
if (edgeIterator.hasNext()) return;
final Iterator<Vertex> vertexIterator = edge.vertices(Direction.BOTH);
final Vertex subGraphOutVertex = getOrCreate(vertexIterator.next());
final Vertex subGraphInVertex = getOrCreate(vertexIterator.next());
final Edge subGraphEdge = subGraphOutVertex.addEdge(edge.label(), subGraphInVertex, T.id, edge.id());
edge.properties().forEachRemaining(property -> subGraphEdge.property(property.key(), property.value()));
}
}
代码示例来源: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
private void distributionGeneratorTest(final Graph graph, final DistributionGenerator generator) {
final int numEdges = generator.generate();
assertTrue(numEdges > 0);
tryCommit(graph, g -> assertEquals(numEdges, 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.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingStringRepresentation() {
final Vertex v = graph.addVertex();
final Edge e1 = v.addEdge("self", v);
v.addEdge("self", v);
tryCommit(graph, graph -> {
final Edge e = graph.edges(e1.id().toString()).next();
assertEquals(e1.id(), e.id());
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_NUMERIC_IDS)
public void shouldAddEdgeWithUserSuppliedNumericId() {
final Vertex v = graph.addVertex();
v.addEdge("self", v, T.id, 1000L);
tryCommit(graph, graph -> {
final Edge e = graph.edges(1000L).next();
assertEquals(1000L, e.id());
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_STRING_IDS)
public void shouldAddEdgeWithUserSuppliedStringId() {
final Vertex v = graph.addVertex();
v.addEdge("self", v, T.id, "1000");
tryCommit(graph, graph -> {
final Edge e = graph.edges("1000").next();
assertEquals("1000", e.id());
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingStringRepresentations() {
final Vertex v = graph.addVertex();
final Edge e1 = v.addEdge("self", v);
final Edge e2 = v.addEdge("self", v);
v.addEdge("self", v);
tryCommit(graph, graph -> {
assertEquals(2, IteratorUtils.count(graph.edges(e1.id().toString(), e2.id().toString())));
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdge() {
final Vertex v = graph.addVertex();
final Edge e1 = v.addEdge("self", v);
v.addEdge("self", v);
tryCommit(graph, graph -> {
final Edge e = graph.edges(e1).next();
assertEquals(e1.id(), e.id());
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdgeId() {
final Vertex v = graph.addVertex();
final Edge e1 = v.addEdge("self", v);
v.addEdge("self", v);
tryCommit(graph, graph -> {
final Edge e = graph.edges(e1.id()).next();
assertEquals(e1.id(), e.id());
});
}
代码示例来源: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()));
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdges() {
final Vertex v = graph.addVertex();
final Edge e1 = v.addEdge("self", v);
final Edge e2 = v.addEdge("self", v);
v.addEdge("self", v);
tryCommit(graph, graph -> {
assertEquals(2, IteratorUtils.count(graph.edges(e1, e2)));
});
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateEdgesWithCustomIdSupportUsingEdgeIds() {
final Vertex v = graph.addVertex();
final Edge e1 = v.addEdge("self", v);
final Edge e2 = v.addEdge("self", v);
v.addEdge("self", v);
tryCommit(graph, graph -> {
assertEquals(2, IteratorUtils.count(graph.edges(e1.id(), e2.id())));
});
}
内容来源于网络,如有侵权,请联系作者删除!