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

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

本文整理了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

@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

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

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

@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-blueprints

@Override
public Iterable<Vertex> getVertices(Direction direction, final String... labels) {
  final org.securegraph.Direction sgDirection = SecureGraphBlueprintsConvert.toSecureGraph(direction);
  final Authorizations authorizations = getGraph().getAuthorizationsProvider().getAuthorizations();
  return new ConvertingIterable<org.securegraph.Vertex, Vertex>(getSecureGraphElement().getVertices(sgDirection, labels, authorizations)) {
    @Override
    protected Vertex convert(org.securegraph.Vertex vertex) {
      return SecureGraphBlueprintsVertex.create(getGraph(), vertex, authorizations);
    }
  };
}

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

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

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

@Override
public Iterable<Vertex> getVertices(Direction direction, final String... labels) {
  final org.securegraph.Direction sgDirection = SecureGraphBlueprintsConvert.toSecureGraph(direction);
  final Authorizations authorizations = getGraph().getAuthorizationsProvider().getAuthorizations();
  return new ConvertingIterable<org.securegraph.Vertex, Vertex>(getSecureGraphElement().getVertices(sgDirection, labels, authorizations)) {
    @Override
    protected Vertex convert(org.securegraph.Vertex vertex) {
      return SecureGraphBlueprintsVertex.create(getGraph(), vertex, authorizations);
    }
  };
}

代码示例来源: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: lumifyio/securegraph

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/securegraph-test

@Test
public void testRemoveEdge() {
  Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
  Edge addedEdge = graph.addEdge("e1", v1, v2, "label1", VISIBILITY_A, AUTHORIZATIONS_A);
  assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  try {
    graph.removeEdge("e1", AUTHORIZATIONS_B);
  } catch (IllegalArgumentException e) {
    // expected
  }
  assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  graph.removeEdge("e1", AUTHORIZATIONS_A);
  assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A)));
  v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
  assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
  assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  graph.flush();
  assertEvents(
      new AddVertexEvent(graph, v1),
      new AddVertexEvent(graph, v2),
      new AddEdgeEvent(graph, addedEdge),
      new RemoveEdgeEvent(graph, addedEdge)
  );
}

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

@Test
public void testRemoveEdge() {
  Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
  Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
  Edge addedEdge = graph.addEdge("e1", v1, v2, "label1", VISIBILITY_A, AUTHORIZATIONS_A);
  assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  try {
    graph.removeEdge("e1", AUTHORIZATIONS_B);
  } catch (IllegalArgumentException e) {
    // expected
  }
  assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A)));
  graph.removeEdge("e1", AUTHORIZATIONS_A);
  assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A)));
  v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
  assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  v2 = graph.getVertex("v2", AUTHORIZATIONS_A);
  assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A)));
  graph.flush();
  assertEvents(
      new AddVertexEvent(graph, v1),
      new AddVertexEvent(graph, v2),
      new AddEdgeEvent(graph, addedEdge),
      new RemoveEdgeEvent(graph, addedEdge)
  );
}

相关文章