org.securegraph.Vertex.getVertices()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.securegraph.Vertex.getVertices()方法的一些代码示例,展示了Vertex.getVertices()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.getVertices()方法的具体详情如下:
包路径:org.securegraph.Vertex
类名称:Vertex
方法名:getVertices

Vertex.getVertices介绍

[英]Similar to getEdges but gets the vertices on the other side of the edges attached to this vertex that have the given label.
[中]

代码示例

代码示例来源:origin: org.securegraph/securegraph-test

  1. @Test
  2. public void testGetVerticesFromVertex() {
  3. Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  4. Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
  5. Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A);
  6. Vertex v4 = graph.addVertex("v4", VISIBILITY_A, AUTHORIZATIONS_A);
  7. graph.addEdge(v1, v2, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  8. graph.addEdge(v1, v3, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  9. graph.addEdge(v1, v4, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  10. graph.addEdge(v2, v3, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  11. v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
  12. assertEquals(3, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  13. assertEquals(3, count(v1.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  14. assertEquals(0, count(v1.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  15. v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
  16. assertEquals(2, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  17. assertEquals(1, count(v2.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  18. assertEquals(1, count(v2.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  19. v3 = graph.getVertex("v3", AUTHORIZATIONS_A);
  20. assertEquals(2, count(v3.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  21. assertEquals(0, count(v3.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  22. assertEquals(2, count(v3.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  23. v4 = graph.getVertex("v4", AUTHORIZATIONS_A);
  24. assertEquals(1, count(v4.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  25. assertEquals(0, count(v4.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  26. assertEquals(1, count(v4.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  27. }

代码示例来源:origin: org.securegraph/securegraph-core

  1. @Override
  2. public Iterable<Vertex> vertices(EnumSet<FetchHint> fetchHints) {
  3. Iterable<Vertex> vertices = getSourceVertex().getVertices(Direction.BOTH, fetchHints, getParameters().getAuthorizations());
  4. return new DefaultGraphQueryIterable<Vertex>(getParameters(), vertices, true, true);
  5. }

代码示例来源:origin: lumifyio/securegraph

  1. @Test
  2. public void testGetVerticesFromVertex() {
  3. Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  4. Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
  5. Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A);
  6. Vertex v4 = graph.addVertex("v4", VISIBILITY_A, AUTHORIZATIONS_A);
  7. graph.addEdge(v1, v2, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  8. graph.addEdge(v1, v3, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  9. graph.addEdge(v1, v4, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  10. graph.addEdge(v2, v3, "knows", VISIBILITY_A, AUTHORIZATIONS_A);
  11. v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
  12. assertEquals(3, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  13. assertEquals(3, count(v1.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  14. assertEquals(0, count(v1.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  15. v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
  16. assertEquals(2, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  17. assertEquals(1, count(v2.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  18. assertEquals(1, count(v2.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  19. v3 = graph.getVertex("v3", AUTHORIZATIONS_A);
  20. assertEquals(2, count(v3.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  21. assertEquals(0, count(v3.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  22. assertEquals(2, count(v3.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  23. v4 = graph.getVertex("v4", AUTHORIZATIONS_A);
  24. assertEquals(1, count(v4.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  25. assertEquals(0, count(v4.getVertices(Direction.OUT, AUTHORIZATIONS_A)));
  26. assertEquals(1, count(v4.getVertices(Direction.IN, AUTHORIZATIONS_A)));
  27. }

代码示例来源:origin: org.securegraph/securegraph-blueprints

  1. @Override
  2. public Iterable<Vertex> getVertices(Direction direction, final String... labels) {
  3. final org.securegraph.Direction sgDirection = SecureGraphBlueprintsConvert.toSecureGraph(direction);
  4. final Authorizations authorizations = getGraph().getAuthorizationsProvider().getAuthorizations();
  5. return new ConvertingIterable<org.securegraph.Vertex, Vertex>(getSecureGraphElement().getVertices(sgDirection, labels, authorizations)) {
  6. @Override
  7. protected Vertex convert(org.securegraph.Vertex vertex) {
  8. return SecureGraphBlueprintsVertex.create(getGraph(), vertex, authorizations);
  9. }
  10. };
  11. }

代码示例来源:origin: lumifyio/securegraph

  1. @Override
  2. public Iterable<Vertex> vertices(EnumSet<FetchHint> fetchHints) {
  3. Iterable<Vertex> vertices = getSourceVertex().getVertices(Direction.BOTH, fetchHints, getParameters().getAuthorizations());
  4. return new DefaultGraphQueryIterable<Vertex>(getParameters(), vertices, true, true);
  5. }

代码示例来源:origin: lumifyio/securegraph

  1. @Override
  2. public Iterable<Vertex> getVertices(Direction direction, final String... labels) {
  3. final org.securegraph.Direction sgDirection = SecureGraphBlueprintsConvert.toSecureGraph(direction);
  4. final Authorizations authorizations = getGraph().getAuthorizationsProvider().getAuthorizations();
  5. return new ConvertingIterable<org.securegraph.Vertex, Vertex>(getSecureGraphElement().getVertices(sgDirection, labels, authorizations)) {
  6. @Override
  7. protected Vertex convert(org.securegraph.Vertex vertex) {
  8. return SecureGraphBlueprintsVertex.create(getGraph(), vertex, authorizations);
  9. }
  10. };
  11. }

代码示例来源:origin: org.securegraph/securegraph-core

  1. 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) {
  2. // if this is our first source vertex report progress back to the progress callback
  3. boolean firstLevelRecursion = hops == totalHops;
  4. seenVertices.add(sourceVertex.getId());
  5. if (sourceVertex.getId().equals(destVertex.getId())) {
  6. foundPaths.add(currentPath);
  7. } else if (hops > 0) {
  8. Iterable<Vertex> vertices = sourceVertex.getVertices(Direction.BOTH, authorizations);
  9. int vertexCount = 0;
  10. if (firstLevelRecursion) {
  11. vertices = toList(vertices);
  12. vertexCount = ((List<Vertex>) vertices).size();
  13. }
  14. int i = 0;
  15. for (Vertex child : vertices) {
  16. if (firstLevelRecursion) {
  17. // this will never get to 100% since i starts at 0. which is good. 100% signifies done and we still have work to do.
  18. double progressPercent = (double) i / (double) vertexCount;
  19. progressCallback.progress(progressPercent, ProgressCallback.Step.SEARCHING_EDGES, i + 1, vertexCount);
  20. }
  21. if (!seenVertices.contains(child.getId())) {
  22. findPathsRecursive(foundPaths, child, destVertex, hops - 1, totalHops, seenVertices, new Path(currentPath, child.getId()), progressCallback, authorizations);
  23. }
  24. i++;
  25. }
  26. }
  27. seenVertices.remove(sourceVertex.getId());
  28. }
  29. }

代码示例来源:origin: lumifyio/securegraph

  1. 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) {
  2. // if this is our first source vertex report progress back to the progress callback
  3. boolean firstLevelRecursion = hops == totalHops;
  4. seenVertices.add(sourceVertex.getId());
  5. if (sourceVertex.getId().equals(destVertex.getId())) {
  6. foundPaths.add(currentPath);
  7. } else if (hops > 0) {
  8. Iterable<Vertex> vertices = sourceVertex.getVertices(Direction.BOTH, authorizations);
  9. int vertexCount = 0;
  10. if (firstLevelRecursion) {
  11. vertices = toList(vertices);
  12. vertexCount = ((List<Vertex>) vertices).size();
  13. }
  14. int i = 0;
  15. for (Vertex child : vertices) {
  16. if (firstLevelRecursion) {
  17. // this will never get to 100% since i starts at 0. which is good. 100% signifies done and we still have work to do.
  18. double progressPercent = (double) i / (double) vertexCount;
  19. progressCallback.progress(progressPercent, ProgressCallback.Step.SEARCHING_EDGES, i + 1, vertexCount);
  20. }
  21. if (!seenVertices.contains(child.getId())) {
  22. findPathsRecursive(foundPaths, child, destVertex, hops - 1, totalHops, seenVertices, new Path(currentPath, child.getId()), progressCallback, authorizations);
  23. }
  24. i++;
  25. }
  26. }
  27. seenVertices.remove(sourceVertex.getId());
  28. }
  29. }

代码示例来源:origin: org.securegraph/securegraph-test

  1. @Test
  2. public void testRemoveEdge() {
  3. Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  4. Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
  5. Edge addedEdge = graph.addEdge("e1", v1, v2, "label1", VISIBILITY_A, AUTHORIZATIONS_A);
  6. assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  7. try {
  8. graph.removeEdge("e1", AUTHORIZATIONS_B);
  9. } catch (IllegalArgumentException e) {
  10. // expected
  11. }
  12. assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  13. graph.removeEdge("e1", AUTHORIZATIONS_A);
  14. assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A)));
  15. v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
  16. assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  17. v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
  18. assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  19. graph.flush();
  20. assertEvents(
  21. new AddVertexEvent(graph, v1),
  22. new AddVertexEvent(graph, v2),
  23. new AddEdgeEvent(graph, addedEdge),
  24. new RemoveEdgeEvent(graph, addedEdge)
  25. );
  26. }

代码示例来源:origin: lumifyio/securegraph

  1. @Test
  2. public void testRemoveEdge() {
  3. Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  4. Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
  5. Edge addedEdge = graph.addEdge("e1", v1, v2, "label1", VISIBILITY_A, AUTHORIZATIONS_A);
  6. assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  7. try {
  8. graph.removeEdge("e1", AUTHORIZATIONS_B);
  9. } catch (IllegalArgumentException e) {
  10. // expected
  11. }
  12. assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  13. graph.removeEdge("e1", AUTHORIZATIONS_A);
  14. assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A)));
  15. v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
  16. assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  17. v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
  18. assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  19. graph.flush();
  20. assertEvents(
  21. new AddVertexEvent(graph, v1),
  22. new AddVertexEvent(graph, v2),
  23. new AddEdgeEvent(graph, addedEdge),
  24. new RemoveEdgeEvent(graph, addedEdge)
  25. );
  26. }

相关文章