當前位置: 首頁>>代碼示例>>Java>>正文


Java Schematic.addNode方法代碼示例

本文整理匯總了Java中org.manifold.compiler.middle.Schematic.addNode方法的典型用法代碼示例。如果您正苦於以下問題:Java Schematic.addNode方法的具體用法?Java Schematic.addNode怎麽用?Java Schematic.addNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.manifold.compiler.middle.Schematic的用法示例。


在下文中一共展示了Schematic.addNode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGetNode

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testGetNode() throws SchematicException {
  Schematic sch = new Schematic("test");
  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create a node based on this type
  String nodeName = "testNode";
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  NodeValue node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode(nodeName, node1);
  NodeValue actual = sch.getNode(nodeName);
  assertEquals(node1, actual);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:18,代碼來源:TestSchematic.java

示例2: testGetNodeName

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testGetNodeName()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create a node based on this type
  String nodeName = "testNode";
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  NodeValue node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode(nodeName, node1);
  String retrievedNodeName = sch.getNodeName(node1);
  assertEquals(nodeName, retrievedNodeName);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:19,代碼來源:TestSchematic.java

示例3: testAddNode_AlreadyDeclared_ThrowsException

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = MultipleAssignmentException.class)
public void testAddNode_AlreadyDeclared_ThrowsException()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create a node based on this type
  String nodeName = "testNode";
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  try {
    NodeValue node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
    sch.addNode(nodeName, node1);
  } catch (MultipleAssignmentException e) {
    fail("exception thrown too early");
  }
  // try to add another node with the same name
  NodeValue node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode(nodeName, node2);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:24,代碼來源:TestSchematic.java

示例4: deserializeNodes

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
/**
 * Node defn:
 *
 * <pre>
 * nodes: {
 *  node_one: {
 *    type: node_type,
 *    attributes: { ... },
 *    portAttrs: {
 *      port1: { ... },
 *      port2: { ... },
 *      ...
 *    }
 *  },
 *  ...
 * }
 * </pre>
 */
private void deserializeNodes(Schematic sch, JsonObject in)
    throws SchematicException {

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

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

    NodeTypeValue nodeType = sch
        .getNodeType(nodeDef.get(GlobalConsts.TYPE).getAsString());
    Map<String, Value> attributeMap = getValueAttributes(sch, nodeType
        .getAttributes(), nodeDef);
    Map<String, Map<String, Value>> portAttrMap = new HashMap<>();

    JsonObject portAttrJson = nodeDef.getAsJsonObject(NodeConsts.PORT_ATTRS);

    for (Entry<String, JsonElement> p : portAttrJson.entrySet()) {
      if (!(nodeType.getPorts().containsKey(p.getKey()))) {
        throw new UndeclaredIdentifierException(p.getKey());
      }
      Map<String, TypeValue> expectedPortAttributes =
          nodeType.getPorts().get(p.getKey()).getAttributes();
      portAttrMap.put(p.getKey(), getValueAttributes(
          sch,
          // here we want the port attribute map
          expectedPortAttributes,
          p.getValue().getAsJsonObject()));
    }

    NodeValue node = new NodeValue(nodeType, attributeMap, portAttrMap);
    compTable.put(entry.getKey(), node);
    node.getPorts()
        .forEach((key, port) -> compTable.put(key, port));
    sch.addNode(entry.getKey(), node);
  }
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:58,代碼來源:SchematicDeserializer.java

示例5: 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

示例6: 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

示例7: testGetConnectionName_Undeclared_ThrowsException

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = NoSuchElementException.class)
public void testGetConnectionName_Undeclared_ThrowsException()
    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);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:33,代碼來源:TestSchematic.java

示例8: 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

示例9: 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.addNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。