当前位置: 首页>>代码示例>>Java>>正文


Java Schematic.addConnection方法代码示例

本文整理汇总了Java中org.manifold.compiler.middle.Schematic.addConnection方法的典型用法代码示例。如果您正苦于以下问题:Java Schematic.addConnection方法的具体用法?Java Schematic.addConnection怎么用?Java Schematic.addConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.manifold.compiler.middle.Schematic的用法示例。


在下文中一共展示了Schematic.addConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserializeConnections

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
/**
 * <pre>
 * connections: {
 *  con_one: {
 *    type: connection_type
 *    attributes: { ... }
 *    from: nodeName:portName
 *    to: nodeName:portName
 *  },
 *  ...
 * }
 * </pre>
 */
private void deserializeConnections(Schematic sch, JsonObject in)
    throws UndeclaredIdentifierException, UndeclaredAttributeException,
    InvalidAttributeException, MultipleAssignmentException,
    TypeMismatchException {

  if (in == null) {
    // TODO warning?
    return;
  }

  for (Entry<String, JsonElement> entry : in.entrySet()) {
    JsonObject obj = entry.getValue().getAsJsonObject();

    // TODO: read attributes; non-trivial since we no longer have their type
    Map<String, Value> attributeMap = new HashMap<>();
    ConnectionValue conVal = new ConnectionValue(
        getPortValue(sch, obj.get(ConnectionConsts.FROM).getAsString()),
        getPortValue(sch, obj.get(ConnectionConsts.TO).getAsString()),
        attributeMap);

    compTable.put(entry.getKey(), conVal);
    sch.addConnection(entry.getKey(), conVal);
  }
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:38,代码来源:SchematicDeserializer.java

示例2: testGetConnection

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testGetConnection() throws SchematicException {
  Schematic sch = new Schematic("test");
  ConnectionTypeValue connType = null;
  NodeValue node1 = null, node2 = null;
  Map<String, Value> connAttrs = null;
  String connName = "conn1";
  // create a test port type
  String portTypeName = "TestPort";
  PortTypeValue portType = new PortTypeValue(
      BooleanTypeValue.getInstance(), portAttributes);
  sch.addPortType(portTypeName, portType);
  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  ports.put("p", portType);
  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create two nodes based on this type
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  nodePortAttrs.put("p", new HashMap<>());
  node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("node1", node1);
  node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("node2", node2);

  // create the first connection
  connAttrs = new HashMap<>();
  ConnectionValue conn1 = new ConnectionValue(
      node1.getPort("p"), node2.getPort("p"), connAttrs);
  sch.addConnection(connName, conn1);
  ConnectionValue actual = sch.getConnection(connName);
  assertEquals(conn1, actual);
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:36,代码来源:TestSchematic.java

示例3: testGetConnectionName

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testGetConnectionName()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  // create a test port type
  String portTypeName = "TestPort";
  PortTypeValue portType1 = new PortTypeValue(
      BooleanTypeValue.getInstance(), portAttributes);
  sch.addPortType(portTypeName, portType1);

  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  ports.put("p0", portType1);

  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create two nodes based on this type
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  nodePortAttrs.put("p0", new HashMap<>());
  NodeValue node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("testNode1", node1);
  NodeValue node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("testNode2", node2);

  String connName = "testConn1";
  ConnectionValue conn = new ConnectionValue(
      node1.getPort("p0"), node2.getPort("p0"), nodeAttrs);
  sch.addConnection(connName, conn);
  String retrievedName = sch.getConnectionName(conn);
  assertEquals(connName, retrievedName);
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:34,代码来源:TestSchematic.java

示例4: setup

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Before
public void setup() throws SchematicException {

  testSchematic = new Schematic(TEST_SCHEMATIC_NAME);

  // port type
  PortTypeValue din = new PortTypeValue(
      testSchematic.getUserDefinedType("Bool"), new HashMap<>());
  PortTypeValue dout = new PortTypeValue(
      testSchematic.getUserDefinedType("Bool"), new HashMap<>());
  testSchematic.addPortType(DIGITAL_IN, din);
  testSchematic.addPortType(DIGITAL_OUT, dout);

  // node type
  HashMap<String, PortTypeValue> dinPortMap = new HashMap<>();
  dinPortMap.put(IN_PORT_NAME, din);

  HashMap<String, PortTypeValue> doutPortMap = new HashMap<>();
  doutPortMap.put(OUT_PORT_NAME, dout);

  NodeTypeValue dinNodeType = new NodeTypeValue(new HashMap<>(), dinPortMap);
  NodeTypeValue doutNodeType = new NodeTypeValue(new HashMap<>(),
      doutPortMap);

  testSchematic.addNodeType(IN_NODE_NAME, dinNodeType);
  testSchematic.addNodeType(OUT_NODE_NAME, doutNodeType);

  // node
  Map<String, Map<String, Value>> inNodeAttr = new HashMap<>();
  inNodeAttr.put(IN_PORT_NAME, new HashMap<>());

  Map<String, Map<String, Value>> outNodeAttr = new HashMap<>();
  outNodeAttr.put(OUT_PORT_NAME, new HashMap<>());

  NodeValue inNode = new NodeValue(dinNodeType, new HashMap<>(), inNodeAttr);
  testSchematic.addNode("nIN", inNode);

  NodeValue outNode = new NodeValue(doutNodeType, new HashMap<>(),
      outNodeAttr);
  testSchematic.addNode("nOUT", outNode);

  ConnectionValue con = new ConnectionValue(inNode
      .getPort(IN_PORT_NAME), outNode.getPort(OUT_PORT_NAME),
      new HashMap<>());

  testSchematic.addConnection(CONNECTION_NAME, con);

  // constraint
  TypeValue stringType = testSchematic.getUserDefinedType("String");
  ConstraintType constraintType = new ConstraintType(ImmutableMap.of(
      "foo", stringType,
      "din_reference", dinNodeType,
      "port_reference", din));
  testSchematic.addConstraintType(TEST_CONSTRAINT_TYPE_NAME, constraintType);

  ConstraintValue constraintValue = new ConstraintValue(constraintType,
      ImmutableMap.of(
          "foo", new StringValue(stringType, "bar"),
          "din_reference", inNode,
          "port_reference", inNode.getPort(IN_PORT_NAME)));

  testSchematic.addConstraint("c1", constraintValue);
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:64,代码来源:TestSerialization.java

示例5: testAddConnection_AlreadyDeclared_ThrowsException

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test(expected = MultipleAssignmentException.class)
public void testAddConnection_AlreadyDeclared_ThrowsException()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  ConnectionTypeValue connType = null;
  NodeValue node1 = null, node2 = null;
  Map<String, Value> connAttrs = null;
  String connName = "conn1";
  try {
    // create a test port type
    String portTypeName = "TestPort";
    PortTypeValue portType = new PortTypeValue(
        BooleanTypeValue.getInstance(), portAttributes);
    sch.addPortType(portTypeName, portType);
    // create a test node type
    String nodeTypeName = "TestNode";
    Map<String, PortTypeValue> ports = new HashMap<>();
    ports.put("p", portType);
    NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
    sch.addNodeType(nodeTypeName, nodeType);
    // create two nodes based on this type
    Map<String, Value> nodeAttrs = new HashMap<>();
    Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
    nodePortAttrs.put("p", new HashMap<>());
    node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
    sch.addNode("node1", node1);
    node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
    sch.addNode("node2", node2);

    // create the first connection
    connAttrs = new HashMap<>();
    ConnectionValue conn1 = new ConnectionValue(
        node1.getPort("p"), node2.getPort("p"), connAttrs);
    sch.addConnection(connName, conn1);
  } catch (MultipleAssignmentException e) {
    fail("exception thrown too early");
  }
  ConnectionValue conn2 = new ConnectionValue(
      node1.getPort("p"), node2.getPort("p"), connAttrs);
  sch.addConnection(connName, conn2);
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:42,代码来源:TestSchematic.java


注:本文中的org.manifold.compiler.middle.Schematic.addConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。