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


Java Schematic.getNode方法代碼示例

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


在下文中一共展示了Schematic.getNode方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: testModifyNodeAttribute

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testModifyNodeAttribute() throws SchematicException {
  // Modify the "foo" attribute on node "nIN" to be False instead of True.

  NodeValue inOriginal = originalSchematic.getNode("nIN");
  assertTrue("precondition failed",
      inOriginal.getAttribute(NODE_ATTR_FOO).equals(
          BooleanValue.getInstance(true)));

  BackAnnotationBuilder builder =
      new BackAnnotationBuilder(originalSchematic);
  builder.annotateNodeAttribute("nIN", NODE_ATTR_FOO,
      BooleanValue.getInstance(false));
  Schematic modifiedSchematic = builder.build();

  NodeValue inModified = modifiedSchematic.getNode("nIN");
  assertTrue("back-annotation failed",
      inModified.getAttribute(NODE_ATTR_FOO).equals(
          BooleanValue.getInstance(false)));
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:21,代碼來源:TestBackAnnotationBuilder.java

示例3: testModifyNodeAttribute_PreservesOthers

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testModifyNodeAttribute_PreservesOthers()
    throws SchematicException {
  // Check that modifying one node attribute doesn't modify any others.

  NodeValue inOriginal = originalSchematic.getNode("nIN");
  InferredValue vBar = (InferredValue) inOriginal.getAttribute(NODE_ATTR_BAR);
  assertTrue("precondition failed",
      vBar.get().equals(
          BooleanValue.getInstance(true)));

  BackAnnotationBuilder builder =
      new BackAnnotationBuilder(originalSchematic);
  builder.annotateNodeAttribute("nIN", NODE_ATTR_FOO,
      BooleanValue.getInstance(false));
  Schematic modifiedSchematic = builder.build();

  NodeValue inModified = modifiedSchematic.getNode("nIN");
  vBar = (InferredValue) inModified.getAttribute(NODE_ATTR_BAR);
  assertTrue("back-annotation smashed unmodified node attribute",
      vBar.get().equals(
          BooleanValue.getInstance(true)));
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:24,代碼來源:TestBackAnnotationBuilder.java

示例4: testModifyNodeAttribute_ToInferred

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testModifyNodeAttribute_ToInferred()
    throws SchematicException {
  // Modify the "iBaz" attribute on node "nIN" to be <Inferred> instead of
  // True

  NodeValue inOriginal = originalSchematic.getNode("nIN");
  InferredValue vBar = (InferredValue) inOriginal.getAttribute(NODE_ATTR_BAR);
  assertTrue("precondition failed", vBar.isSet());
  assertTrue("precondition failed",
      vBar.get().equals(
          BooleanValue.getInstance(true)));

  InferredTypeValue maybeBool = new InferredTypeValue(
      originalSchematic.getUserDefinedType("Bool"));
  Value newValue = new InferredValue(maybeBool);

  BackAnnotationBuilder builder =
      new BackAnnotationBuilder(originalSchematic);
  builder.annotateNodeAttribute("nIN", NODE_ATTR_BAR, newValue);
  Schematic modifiedSchematic = builder.build();

  NodeValue inModified = modifiedSchematic.getNode("nIN");
  vBar = (InferredValue) inModified.getAttribute(NODE_ATTR_BAR);
  assertFalse("back-annotation failed", vBar.isSet());
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:27,代碼來源:TestBackAnnotationBuilder.java

示例5: testPassthrough

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testPassthrough() throws SchematicException {
  // If we don't make any annotations, the builder should give us back
  // a schematic whose nodes, ports, connections, and constraints
  // have the same attributes as the one that we started with.

  BackAnnotationBuilder builder =
      new BackAnnotationBuilder(originalSchematic);
  Schematic modifiedSchematic = builder.build();

  NodeValue inNodeOriginal = originalSchematic.getNode("nIN");
  NodeValue inNodeModified = modifiedSchematic.getNode("nIN");
  assertTrue(inNodeOriginal.getAttributes().
      equals(inNodeModified.getAttributes()));

  PortValue inPortOriginal = inNodeOriginal.getPort(IN_PORT_NAME);
  PortValue inPortModified = inNodeModified.getPort(IN_PORT_NAME);
  assertTrue(inPortOriginal.getAttributes().
      equals(inPortModified.getAttributes()));

  ConnectionValue inConnOriginal = originalSchematic.
      getConnection(CONNECTION_NAME);
  ConnectionValue inConnModified = modifiedSchematic.
      getConnection(CONNECTION_NAME);
  assertTrue(inConnOriginal.getAttributes().
      equals(inConnModified.getAttributes()));
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:28,代碼來源:TestBackAnnotationBuilder.java

示例6: testCopyConstraint_RecreatedNode

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testCopyConstraint_RecreatedNode()
    throws SchematicException {
  // Check that a constraint referencing a node actually refers
  // to the correct node in the backannotated copy.
  BackAnnotationBuilder builder =
      new BackAnnotationBuilder(originalSchematic);
  Schematic modifiedSchematic = builder.build();

  NodeValue expectedNode = modifiedSchematic.getNode("nIN");
  ConstraintValue cxt = modifiedSchematic.getConstraint("c1");
  NodeValue actualNode = (NodeValue) cxt.getAttribute("din_reference");
  assertEquals(expectedNode, actualNode);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:15,代碼來源:TestBackAnnotationBuilder.java

示例7: getPortValue

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
private PortValue getPortValue(Schematic sch, String ref)
    throws UndeclaredIdentifierException {
  int delim = ref.indexOf(GlobalConsts.NODE_PORT_DELIM);
  NodeValue node = sch.getNode(ref.substring(0, delim));
  return node.getPort(ref.substring(delim + 1));
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:7,代碼來源:SchematicDeserializer.java

示例8: testDeserialize

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testDeserialize() throws IOException,
    UndeclaredIdentifierException, UndeclaredAttributeException {
  final String IN_NODE_NAME = "in_node";
  final String OUT_NODE_NAME = "out_node";
  final String DIGITAL_IN_PORT_NAME = "digital_in";
  final String DIGITAL_OUT_PORT_NAME = "digital_out";

  URL url = Resources
      .getResource("org/manifold/compiler/serialization/data/"
          + "deserialization-types-test.json");

  JsonObject json = new JsonParser().parse(
      Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
  Schematic sch = new SchematicDeserializer().deserialize(json);

  Map<String, PortTypeValue> outNodePorts = sch.getNodeType(OUT_NODE_NAME)
      .getPorts();
  Map<String, PortTypeValue> inNodePorts = sch.getNodeType(IN_NODE_NAME)
      .getPorts();

  PortTypeValue digitalIn = sch.getPortType(DIGITAL_IN_PORT_NAME);
  PortTypeValue digitalOut = sch.getPortType(DIGITAL_OUT_PORT_NAME);

  assertEquals(TEST_SCHEMATIC_NAME, sch.getName());

  assertTrue(sch.getUserDefinedType("Flag")
      .isSubtypeOf(BooleanTypeValue.getInstance()));

  assertEquals(digitalIn, inNodePorts.get("in1"));
  assertEquals(digitalIn, inNodePorts.get("in2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));

  NodeValue andNode = sch.getNode("and_node");
  NodeValue andNode2 = sch.getNode("and_node2");

  assertEquals(sch.getNodeType("and"), andNode.getType());
  assertEquals(andNode.getType(), andNode2.getType());
  assertEquals(digitalIn, andNode.getPort("in1").getType());
  assertFalse(((BooleanValue) andNode.getAttribute("is_awesome"))
      .toBoolean());
  assertTrue(((BooleanValue) andNode2.getAttribute("is_awesome"))
      .toBoolean());

  ConnectionValue conVal = sch.getConnection("con1");
  assertEquals(andNode.getPort("out1"), conVal.getFrom());
  assertEquals(andNode2.getPort("in2"), conVal.getTo());
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:50,代碼來源:TestSerialization.java

示例9: testSerializeInferredAttributes

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testSerializeInferredAttributes() throws
    SchematicException {

  final String NODE_TYPE_NAME = "NodeInferred";
  final String INFERRED_TYPE_NAME = "InferredBool";
  InferredTypeValue maybe = new InferredTypeValue(
      testSchematic.getUserDefinedType("Bool"));
  // add an inferred UDT to the test schematic
  UserDefinedTypeValue udtMaybe =
      new UserDefinedTypeValue(maybe, INFERRED_TYPE_NAME);
  testSchematic.addUserDefinedType(udtMaybe);
  BooleanValue trueValue = BooleanValue.getInstance(true);

  NodeTypeValue testNodeType = new NodeTypeValue(
      ImmutableMap.of("foom", udtMaybe), new HashMap<>());
  testSchematic.addNodeType(NODE_TYPE_NAME, testNodeType);

  Map<String, Value> withInferred =
      ImmutableMap.of("foom", new InferredValue(maybe, trueValue));
  Map<String, Value> withoutInferred =
      ImmutableMap.of("foom", new InferredValue(maybe));

  NodeValue nodeWithoutInferred =
      new NodeValue(testNodeType, withoutInferred, new HashMap<>());
  NodeValue nodeWithInferred =
      new NodeValue(testNodeType, withInferred, new HashMap<>());
  testSchematic.addNode("n1", nodeWithoutInferred);
  testSchematic.addNode("n2", nodeWithInferred);

  // serialize, deserialize, check that the type looks okay
  JsonObject result = SchematicSerializer.serialize(testSchematic);

  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  JsonParser jp = new JsonParser();
  JsonElement je = jp.parse(result.toString());
  String prettyJsonString = gson.toJson(je);

  System.out.println(prettyJsonString);

  Schematic sch = new SchematicDeserializer().deserialize(result);
  try {
    UserDefinedTypeValue udt = sch.getUserDefinedType(INFERRED_TYPE_NAME);
    assertTrue(udt.getTypeAlias() instanceof InferredTypeValue);
    InferredTypeValue inferredType = (InferredTypeValue) udt.getTypeAlias();
    assertTrue(inferredType.getInferredType()
        .isSubtypeOf(BooleanTypeValue.getInstance()));
  } catch (UndeclaredIdentifierException e) {
    fail("undeclared identifier '" + e.getIdentifier() + "'; "
        + "the user-defined type may not have been serialized");
  }

  NodeValue n2 = sch.getNode("n2");
  InferredValue v2 = (InferredValue) n2.getAttribute("foom");
  assertEquals(trueValue, v2.get());
  NodeValue n1 = sch.getNode("n1");
  InferredValue v1 = (InferredValue) n1.getAttribute("foom");
  assertEquals(null, v1.get());
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:60,代碼來源:TestSerialization.java

示例10: testSerializeInferredAttributesWithoutUDT

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testSerializeInferredAttributesWithoutUDT() throws
    SchematicException {

  final String NODE_TYPE_NAME = "NodeInferred";
  InferredTypeValue maybe = new InferredTypeValue(
      BooleanTypeValue.getInstance());
  BooleanValue trueValue = BooleanValue.getInstance(true);

  NodeTypeValue testNodeType = new NodeTypeValue(
      ImmutableMap.of("foom", maybe), new HashMap<>());
  testSchematic.addNodeType(NODE_TYPE_NAME, testNodeType);

  Map<String, Value> withInferred =
      ImmutableMap.of("foom", new InferredValue(maybe, trueValue));
  Map<String, Value> withoutInferred =
      ImmutableMap.of("foom", new InferredValue(maybe));

  NodeValue nodeWithoutInferred =
      new NodeValue(testNodeType, withoutInferred, new HashMap<>());
  NodeValue nodeWithInferred =
      new NodeValue(testNodeType, withInferred, new HashMap<>());
  testSchematic.addNode("n1", nodeWithoutInferred);
  testSchematic.addNode("n2", nodeWithInferred);

  // serialize, deserialize, check that the type looks okay
  JsonObject result = SchematicSerializer.serialize(testSchematic);

  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  JsonParser jp = new JsonParser();
  JsonElement je = jp.parse(result.toString());
  String prettyJsonString = gson.toJson(je);

  System.out.println(prettyJsonString);

  Schematic sch = new SchematicDeserializer().deserialize(result);

  NodeValue n2 = sch.getNode("n2");
  InferredValue v2 = (InferredValue) n2.getAttribute("foom");
  assertEquals(trueValue, v2.get());
  NodeValue n1 = sch.getNode("n1");
  InferredValue v1 = (InferredValue) n1.getAttribute("foom");
  assertEquals(null, v1.get());
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:45,代碼來源:TestSerialization.java

示例11: testDeserializeInferredAttributes

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testDeserializeInferredAttributes() throws IOException,
    UndeclaredIdentifierException, UndeclaredAttributeException {
  final String IN_NODE_NAME = "in_node";
  final String OUT_NODE_NAME = "out_node";
  final String DIGITAL_IN_PORT_NAME = "digital_in";
  final String DIGITAL_OUT_PORT_NAME = "digital_out";

  URL url = Resources
      .getResource("org/manifold/compiler/serialization/data/"
          + "deserialization-inferred-attributes-test.json");
  JsonObject json = new JsonParser().parse(
      Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
  Schematic sch = new SchematicDeserializer().deserialize(json);

  Map<String, PortTypeValue> outNodePorts = sch.getNodeType(OUT_NODE_NAME)
      .getPorts();
  Map<String, PortTypeValue> inNodePorts = sch.getNodeType(IN_NODE_NAME)
      .getPorts();

  PortTypeValue digitalIn = sch.getPortType(DIGITAL_IN_PORT_NAME);
  PortTypeValue digitalOut = sch.getPortType(DIGITAL_OUT_PORT_NAME);

  assertEquals(TEST_SCHEMATIC_NAME, sch.getName());

  assertEquals(digitalIn, inNodePorts.get("in1"));
  assertEquals(digitalIn, inNodePorts.get("in2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));

  NodeValue andNode = sch.getNode("and_node");
  NodeValue andNode2 = sch.getNode("and_node2");

  assertEquals(sch.getNodeType("and"), andNode.getType());
  assertEquals(andNode.getType(), andNode2.getType());
  assertEquals(digitalIn, andNode.getPort("in1").getType());

  assertEquals(BooleanValue.getInstance(false),
      ((InferredValue) andNode.getAttribute("is_awesome")).get());
  assertEquals(null,
      ((InferredValue) andNode2.getAttribute("is_awesome")).get());

  ConnectionValue conVal = sch.getConnection("con1");
  assertEquals(andNode.getPort("out1"), conVal.getFrom());
  assertEquals(andNode2.getPort("in2"), conVal.getTo());

  InferredValue foom = (InferredValue) andNode.getPort("out1")
      .getAttributes().get("foom");
  InferredValue foom2 = (InferredValue) andNode2.getPort("out1")
      .getAttributes().get("foom");
  assertEquals(null, foom.get());
  assertEquals(BooleanValue.getInstance(true), foom2.get());

  assertEquals(sch.getUserDefinedType("Bool"),
      ((InferredTypeValue) foom.getType()).getInferredType());
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:57,代碼來源:TestSerialization.java

示例12: testGetNode_Undeclared_ThrowsException

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = UndeclaredIdentifierException.class)
public void testGetNode_Undeclared_ThrowsException()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  NodeValue nv = sch.getNode("bogus");
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:7,代碼來源:TestSchematic.java


注:本文中的org.manifold.compiler.middle.Schematic.getNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。