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

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

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

Graph.insert介绍

[英]Add a new unconnected Vertex into the graph.
[中]将新的未连接顶点添加到图形中。

代码示例

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

@Override
public <U> TStream<U> fanin(FanIn<T,U> fanin, List<TStream<T>> others) {
 if (others.isEmpty() || others.size() == 1 && others.contains(this)) 
  throw new IllegalArgumentException("others");  // use pipe()
 if (new HashSet<>(others).size() != others.size())
  throw new IllegalArgumentException("others has dups");
 
 for (TStream<T> other : others)
   verify(other);
 
 others = new ArrayList<>(others);
 others.add(0, this);
 
 Vertex<Oplet<T,U>, T, U> fanInVertex = graph().insert(fanin, others.size(), 1);
 int inputPort = 0;
 for (TStream<T> other : others) {
   @SuppressWarnings("unchecked")
   ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
   cs.connector.connect(fanInVertex, inputPort++);
 }
   
 return derived(fanInVertex.getConnectors().get(0));
}

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

@Override
public <U> TStream<U> fanin(FanIn<T,U> fanin, List<TStream<T>> others) {
 if (others.isEmpty() || others.size() == 1 && others.contains(this)) 
  throw new IllegalArgumentException("others");  // use pipe()
 if (new HashSet<>(others).size() != others.size())
  throw new IllegalArgumentException("others has dups");
 
 for (TStream<T> other : others)
   verify(other);
 
 others = new ArrayList<>(others);
 others.add(0, this);
 
 Vertex<Oplet<T,U>, T, U> fanInVertex = graph().insert(fanin, others.size(), 1);
 int inputPort = 0;
 for (TStream<T> other : others) {
   @SuppressWarnings("unchecked")
   ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
   cs.connector.connect(fanInVertex, inputPort++);
 }
   
 return derived(fanInVertex.getConnectors().get(0));
}

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

@Override
public List<TStream<T>> split(int n, ToIntFunction<T> splitter) {
  if (n <= 0)
    throw new IllegalArgumentException("n <= 0");
  Split<T> splitOp = new Split<T>(splitter);
  Vertex<Split<T>, T, T> splitVertex = graph().insert(splitOp, 1, n);
  connector.connect(splitVertex, 0);
  List<TStream<T>> outputs = new ArrayList<>(n);
  for (int i = 0; i < n; i++) {
    outputs.add(derived(splitVertex.getConnectors().get(i)));
  }
  return outputs;
}

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

@Override
public List<TStream<T>> split(int n, ToIntFunction<T> splitter) {
  if (n <= 0)
    throw new IllegalArgumentException("n <= 0");
  Split<T> splitOp = new Split<T>(splitter);
  Vertex<Split<T>, T, T> splitVertex = graph().insert(splitOp, 1, n);
  connector.connect(splitVertex, 0);
  List<TStream<T>> outputs = new ArrayList<>(n);
  for (int i = 0; i < n; i++) {
    outputs.add(derived(splitVertex.getConnectors().get(i)));
  }
  return outputs;
}

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

@Override
public TStream<T> union(Set<TStream<T>> others) {
  if (others.isEmpty())
    return this;
  if (others.size() == 1 && others.contains(this))
    return this;
  
  for (TStream<T> other : others)
    verify(other);
  
  // Create a set we can modify and add this stream
  others = new HashSet<>(others);
  others.add(this);
  
  Union<T> fanInOp = new Union<T>();
  Vertex<Union<T>, T, T> fanInVertex = graph().insert(fanInOp, others.size(), 1);
  int inputPort = 0;
  for (TStream<T> other : others) {
    @SuppressWarnings("unchecked")
    ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
    cs.connector.connect(fanInVertex, inputPort++);
  }
    
  return derived(fanInVertex.getConnectors().get(0));
}

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

@Override
public TSink<T> sink(Sink<T> oplet) {
  Vertex<Sink<T>, T, Void> sinkVertex = graph().insert(oplet, 1, 0);
  connector.connect(sinkVertex, 0);
  return new ConnectorSink<>(this);
}

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

@Override
public TStream<T> union(Set<TStream<T>> others) {
  if (others.isEmpty())
    return this;
  if (others.size() == 1 && others.contains(this))
    return this;
  
  for (TStream<T> other : others)
    verify(other);
  
  // Create a set we can modify and add this stream
  others = new HashSet<>(others);
  others.add(this);
  
  Union<T> fanInOp = new Union<T>();
  Vertex<Union<T>, T, T> fanInVertex = graph().insert(fanInOp, others.size(), 1);
  int inputPort = 0;
  for (TStream<T> other : others) {
    @SuppressWarnings("unchecked")
    ConnectorStream<G,T> cs = (ConnectorStream<G, T>) other;
    cs.connector.connect(fanInVertex, inputPort++);
  }
    
  return derived(fanInVertex.getConnectors().get(0));
}

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

@Override
public TSink<T> sink(Sink<T> oplet) {
  Vertex<Sink<T>, T, Void> sinkVertex = graph().insert(oplet, 1, 0);
  connector.connect(sinkVertex, 0);
  return new ConnectorSink<>(this);
}

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

@Test
public void testGraphToJson() {
  Graph g = getGraph();
  TestOp<String, Integer> op = new TestOp<>();
  /* Vertex<TestOp<String, Integer>, String, Integer> v = */g.insert(op, 1, 1);
  GraphType gt = new GraphType(g);
  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  String json = gson.toJson(gt);
  
  GraphType gt2 = new Gson().fromJson(json, GraphType.class);
  assertEquals(1, gt2.getVertices().size());
  assertEquals(0, gt2.getEdges().size());
}

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

@Test
public void testGraphToJson2() {
  Graph g = getGraph();
  TestOp<String, Integer> op1 = new TestOp<>();
  Vertex<TestOp<String, Integer>, String, Integer> v = g.insert(op1, 1, 1);
  
  TestOp<Integer, Integer> op2 = new TestOp<>();
  /*Connector<Integer> out2 = */g.pipe(v.getConnectors().get(0), op2);
  
  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  String json = gson.toJson(new GraphType(g));
  
  GraphType gt2 = new Gson().fromJson(json, GraphType.class);
  assertEquals(2, gt2.getVertices().size());
  assertEquals(1, gt2.getEdges().size());
}

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

@Test
public void testGraphToJson4() {
  Graph g = getGraph();
  
  /*                                   /-- V2
   * V0(Integer)-- V1(Double)-- FanOut
   *                                   \-- V3 
   */
  Vertex<TestOp<String, Integer>, String, Integer> v0 = g.insert(new TestOp<>(), 1, 1);
  Connector<Integer> out0 = v0.getConnectors().get(0);
  Connector<Double> out1 = g.pipe(out0, new TestOp<Integer, Double>());
  Vertex<TestOp<Double, String>, Double, String> v2 = g.insert(new TestOp<Double, String>(), 1, 1);
  Vertex<TestOp<Double, String>, Double, String> v3 = g.insert(new TestOp<Double, String>(), 1, 1);
  out1.connect(v2, 0);
  out1.connect(v3, 0);
  
  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  String json = gson.toJson(new GraphType(g));
  
  GraphType gt2 = new Gson().fromJson(json, GraphType.class);
  assertEquals(5, gt2.getVertices().size());
  assertEquals(4, gt2.getEdges().size());
}

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

Vertex<SupplierPeriodicSource<Double>, Void, Double> v0 = g.insert(
    new SupplierPeriodicSource<>(100, TimeUnit.MILLISECONDS, () -> (r.nextDouble() * 3)),
    0, 1);
Vertex<Split<Double>, Double, Double> v1 = g.insert(splitOp, 1, 3);
out0.connect(v1, 0);
Vertex<Sink<Double>, Double, Void> v2 = g.insert(
    new Sink<>(tuple -> System.out.print(".")), 1, 0);
v1.getConnectors().get(0).connect(v2, 0);
v1.getConnectors().get(0).tag("dots");
Vertex<Sink<Double>, Double, Void> v3 = g.insert(
    new Sink<>(tuple -> System.out.print("#")), 1, 0);
v1.getConnectors().get(1).connect(v3, 0);
v1.getConnectors().get(1).tag("hashes");
Vertex<Sink<Double>, Double, Void> v4 = g.insert(
    new Sink<>(tuple -> System.out.print("@")), 1, 0);
v1.getConnectors().get(2).connect(v4, 0);

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

Vertex<TestOp<String, Integer>, String, Integer> v = g.insert(op, 1, 1);
assertNotNull(v);
assertSame(op, v.getInstance());
Vertex<TestOp<Integer, Void>, Integer, Void> v2 = g.insert(op2, 1, 0);

相关文章