本文整理匯總了Java中org.manifold.compiler.middle.Schematic.addNodeType方法的典型用法代碼示例。如果您正苦於以下問題:Java Schematic.addNodeType方法的具體用法?Java Schematic.addNodeType怎麽用?Java Schematic.addNodeType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.manifold.compiler.middle.Schematic
的用法示例。
在下文中一共展示了Schematic.addNodeType方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
示例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);
}
示例3: testGetNodeName_Undeclared_ThrowsException
import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = NoSuchElementException.class)
public void testGetNodeName_Undeclared_ThrowsException()
throws NoSuchElementException, 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);
// don't add this node to the schematic, but instead try to get its name
String retrievedName = sch.getNodeName(node1);
}
示例4: testAddNodeType_AlreadyDefined_ThrowsException
import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = MultipleDefinitionException.class)
public void testAddNodeType_AlreadyDefined_ThrowsException()
throws SchematicException {
Schematic sch = new Schematic("test");
// add the first node type
String nodeTypeName = "TestNode";
Map<String, PortTypeValue> ports = new HashMap<>();
try {
NodeTypeValue nv1 = new NodeTypeValue(attributes, ports);
sch.addNodeType(nodeTypeName, nv1);
} catch (MultipleDefinitionException e) {
fail("exception thrown too early");
}
// try to add another node type with the same name
NodeTypeValue nv2 = new NodeTypeValue(attributes, ports);
sch.addNodeType(nodeTypeName, nv2);
}
示例5: 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);
}
示例6: testGetNodeType
import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testGetNodeType() throws SchematicException {
Schematic sch = new Schematic("test");
// add the first node type
String nodeTypeName = "TestNode";
Map<String, PortTypeValue> ports = new HashMap<>();
NodeTypeValue nv1 = new NodeTypeValue(attributes, ports);
sch.addNodeType(nodeTypeName, nv1);
NodeTypeValue actual = sch.getNodeType(nodeTypeName);
assertEquals(nv1, actual);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: elaborateSchematicTypes
import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
public static void elaborateSchematicTypes(ExpressionGraph g, Schematic s)
throws Exception {
// look for all primitive node/port vertices in the expression graph;
// for each one, find any variables to which
// it is directly assigned, and use the non-namespaced identifier
// as the type name in the schematic
for (ExpressionVertex v : g.getNonVariableVertices()) {
if (v instanceof PrimitivePortVertex ||
v instanceof PrimitiveNodeVertex) {
v.elaborate(); // usually redundant but always safe
List<ExpressionEdge> outgoingEdges = g.getEdgesFromSource(v);
for (ExpressionEdge e : outgoingEdges) {
if (e.getTarget() instanceof VariableReferenceVertex) {
VariableReferenceVertex id = (VariableReferenceVertex)
e.getTarget();
String typename = id.getIdentifier().getName();
// now add to the correct schematic type list
if (v instanceof PrimitivePortVertex) {
log.debug("elaborated port type " + typename);
PortTypeValue portType = (PortTypeValue) v.getValue();
s.addPortType(typename, portType);
} else if (v instanceof PrimitiveNodeVertex) {
log.debug("elaborated node type " + typename);
NodeTypeValue nodeType = (NodeTypeValue) v.getValue();
s.addNodeType(typename, nodeType);
}
}
} // for (e: outgoingEdges)
} // if (v instanceof ...)
}
}
示例11: deserializeNodeTypes
import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
private void deserializeNodeTypes(Schematic sch, JsonObject in)
throws JsonSyntaxException, MultipleDefinitionException,
UndeclaredIdentifierException {
if (in == null) {
// TODO warning?
return;
}
for (Entry<String, JsonElement> entry : in.entrySet()) {
Map<String, TypeValue> attributeMap = getTypeDefAttributes(sch,
entry.getValue().getAsJsonObject());
Map<String, PortTypeValue> portMap = new HashMap<>();
JsonObject portMapJson = entry.getValue().getAsJsonObject()
.getAsJsonObject(NodeTypeConsts.PORT_MAP);
for (Entry<String, JsonElement> portEntry : portMapJson.entrySet()) {
portMap.put(portEntry.getKey(), sch.getPortType(portEntry.getValue()
.getAsString()));
}
// get supertype if it exists
NodeTypeValue supertype = null;
if (entry.getValue().getAsJsonObject().has(SUPERTYPE)) {
String supertypeName = entry.getValue().getAsJsonObject()
.get(SUPERTYPE).getAsString();
supertype = sch.getNodeType(supertypeName);
}
NodeTypeValue nodeTypeValue;
if (supertype == null) {
nodeTypeValue = new NodeTypeValue(attributeMap, portMap);
} else {
nodeTypeValue = new NodeTypeValue(attributeMap, portMap, supertype);
}
compTable.put(entry.getKey(), nodeTypeValue);
sch.addNodeType(entry.getKey(), nodeTypeValue);
}
}
示例12: 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);
}
示例13: 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);
}