org.apache.edgent.graph.Graph.getVertices()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(99)

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

Graph.getVertices介绍

[英]Return an unmodifiable view of all vertices in this graph.
[中]返回此图中所有顶点的不可修改视图。

代码示例

代码示例来源:origin: apache/incubator-edgent

/**
 * Create an instance of {@link GraphType} using the specified 
 * {@link IdMapper} to generate unique object identifiers.
 * @param g the associated Graph
 * @param ids the id mapper
 */
public GraphType(Graph g, IdMapper<String> ids) {
  if (ids == null) {
    ids = new GraphType.Mapper();
  }
  ArrayList<VertexType<?,?>> vertices = 
      new ArrayList<VertexType<?,?>>();
  ArrayList<EdgeType> edges = new ArrayList<EdgeType>();
  
  for (Vertex<? extends Oplet<?,?>, ?, ?> v : g.getVertices()) {
    @SuppressWarnings({ "rawtypes", "unchecked" })
    VertexType<?,?> vertex = new VertexType(v, ids);
    vertices.add(vertex);
  }
  for (Edge e : g.getEdges()) {
    edges.add(new EdgeType(e, ids));
  }
  this.vertices = vertices;
  this.edges = edges;
}

代码示例来源:origin: org.apache.edgent/edgent-runtime-etiao

/**
 * Create an instance of {@link GraphType} using the specified 
 * {@link IdMapper} to generate unique object identifiers.
 * @param g the associated Graph
 * @param ids the id mapper
 */
public GraphType(Graph g, IdMapper<String> ids) {
  if (ids == null) {
    ids = new GraphType.Mapper();
  }
  ArrayList<VertexType<?,?>> vertices = 
      new ArrayList<VertexType<?,?>>();
  ArrayList<EdgeType> edges = new ArrayList<EdgeType>();
  
  for (Vertex<? extends Oplet<?,?>, ?, ?> v : g.getVertices()) {
    @SuppressWarnings({ "rawtypes", "unchecked" })
    VertexType<?,?> vertex = new VertexType(v, ids);
    vertices.add(vertex);
  }
  for (Edge e : g.getEdges()) {
    edges.add(new EdgeType(e, ids));
  }
  this.vertices = vertices;
  this.edges = edges;
}

代码示例来源:origin: apache/incubator-edgent

@Test
public void testEmptyGraph() {
  assertTrue(getGraph().getVertices().isEmpty());
}

代码示例来源:origin: apache/incubator-edgent

private void _testFanoutWithPeek(boolean after) throws Exception {
  Topology t = newTopology();
  Graph g = t.graph();
  /*                            -- Filter -- Sink(.)
   *                           / 
   * Source -- Peek -- FanOut ---- Modify -- Sink(@)
   * 
   */
  TStream<Integer> d = integers(t, 1, 2, 3);
  List<Integer> peekedValues = new ArrayList<>();
  
  if (!after)
    d.peek(tuple -> peekedValues.add(tuple));
  TStream<Integer> df = d.filter(tuple -> tuple.intValue() > 0);
  TStream<Integer> dm = d.modify(tuple -> new Integer(tuple.intValue() + 1));
  if (after)
    d.peek(tuple -> peekedValues.add(tuple));
  df.sink(tuple -> System.out.print("."));
  dm.sink(tuple -> System.out.print("@"));
  
  assertEquals(7, g.getVertices().size());
  assertEquals(6, g.getEdges().size());
  // Insert counter metrics into all the streams 
  Metrics.counter(t);
  printGraph(g);
  assertEquals(10, g.getVertices().size());
  assertEquals(9, g.getEdges().size());
}

代码示例来源:origin: apache/incubator-edgent

/**
 * Test Peek. This will only work with an embedded setup.
 * 
 * @throws Exception on failure
 */
@Test
public void metricsEverywherePeek() throws Exception {
  Topology t = newTopology();
  Graph g = t.graph();
  TStream<String> s = t.strings("a", "b", "c");
  List<String> peekedValues = new ArrayList<>();
  TStream<String> speek = s.peek(tuple -> peekedValues.add(tuple));
  speek.sink(tuple -> System.out.print("."));
  Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
  assertEquals(3, vertices.size());
  Collection<Edge> edges = g.getEdges();
  assertEquals(2, edges.size());
  Metrics.counter(t);
  printGraph(g);
  // One single counter inserted after the peek 
  vertices = g.getVertices();
  assertEquals(4, vertices.size());
  edges = g.getEdges();
  assertEquals(3, edges.size());
}

代码示例来源:origin: apache/incubator-edgent

@Test
public void metricsEverywhereMultiplePeek() throws Exception {
  Topology t = newTopology();
  Graph g = t.graph();
  TStream<String> s = t.strings("a", "b", "c");
  List<String> peekedValues = new ArrayList<>();
  TStream<String> speek = s.peek(tuple -> peekedValues.add(tuple + "1st"));
  TStream<String> speek2 = speek.peek(tuple -> peekedValues.add(tuple + "2nd"));
  TStream<String> speek3 = speek2.peek(tuple -> peekedValues.add(tuple + "3rd"));
  speek3.sink(tuple -> System.out.print("."));
  Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
  assertEquals(5, vertices.size());
  Collection<Edge> edges = g.getEdges();
  assertEquals(4, edges.size());
  Metrics.counter(t);
  printGraph(g);
  // One single counter inserted after the 3rd peek 
  vertices = g.getVertices();
  assertEquals(6, vertices.size());
  edges = g.getEdges();
  assertEquals(5, edges.size());
}

代码示例来源:origin: apache/incubator-edgent

@Test
public void testMetricsEverywhere() throws Exception {
  Topology t = newTopology();
  TStream<String> s = t.strings("a", "b", "c");
  // Condition inserts a sink
  Condition<Long> tc = t.getTester().tupleCount(s, 3);
  Graph g = t.graph();
  Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
  
  // Two vertices before submission
  assertEquals(2, vertices.size());
  complete(t, tc);
  // At least three vertices after submission
  // (provide may have added other oplets as well)
  Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> verticesAfterSubmit = g.getVertices();
  assertTrue("size="+verticesAfterSubmit.size(), verticesAfterSubmit.size() >= 3);
  
  // There is exactly one vertex for a metric oplet
  int numOplets = 0;
  for (Vertex<? extends Oplet<?, ?>, ?, ?> v : verticesAfterSubmit) {
    Oplet<?,?> oplet = v.getInstance();
    if (oplet instanceof CounterOp) {
      numOplets++;
    }
  }
  assertEquals(1, numOplets);
}

代码示例来源:origin: apache/incubator-edgent

@Test
public void metricsEverywhereFanOut() {
  
  Topology t = newTopology();
  Graph g = t.graph();
  /*                   -- OP_3 (Sink)
   *                  / 
   * OP_0 -- FanOut ----- OP_4 (Sink)
   */
  TStream<Integer> d = integers(t, 1, 2, 3);
  d.sink(tuple -> System.out.print("."));
  d.sink(tuple -> System.out.print("@"));
  
  // Insert counter metrics into all the topology streams 
  Metrics.counter(t);
  printGraph(g);
  
  Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
  assertEquals(5, vertices.size());
  
  Collection<Edge> edges = g.getEdges();
  assertEquals(4, edges.size());
}

代码示例来源:origin: apache/incubator-edgent

@Test
public void metricsEverywhereSimple() throws Exception {
  
  Topology t = newTopology();
  Graph g = t.graph();
  // Source
  TStream<Integer> d = integers(t, 1, 2, 3);
  d.sink(tuple -> System.out.print("."));
  
  // Insert counter metrics into all the topology streams 
  Metrics.counter(t);
  printGraph(g);
  
  Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
  assertEquals(3, vertices.size());
  
  Collection<Edge> edges = g.getEdges();
  assertEquals(2, edges.size());
}

代码示例来源:origin: apache/incubator-edgent

Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
assertEquals(10, vertices.size());

代码示例来源:origin: apache/incubator-edgent

Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices();
Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> verticesAfterSubmit = g.getVertices();
assertTrue("size="+verticesAfterSubmit.size(), verticesAfterSubmit.size() >= 7);

代码示例来源:origin: apache/incubator-edgent

assertSame(op, v.getInstance());
Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> c = getGraph().getVertices();
assertNotNull(c);
Vertex<TestOp<Integer, Void>, Integer, Void> v2 = g.insert(op2, 1, 0);
c = getGraph().getVertices();
assertNotNull(c);

代码示例来源:origin: apache/incubator-edgent

Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = t.graph().getVertices();
PeriodicSource<?> src = null;
for (Vertex<? extends Oplet<?, ?>, ?, ?> v : vertices) {

相关文章

微信公众号

最新文章

更多