/** * Returns the {@link Node} with the given {@code id} or * {@code null} if the graph contains no respective {@link Node}. * * @param id the id of the Node to be removed * @return {@code true} if the graph contains a {@link Node} with the given {@code id}. Else {@code false}. */ public Node getNode(String id) { for (Node node : nodeList) { if (node.getId().equalsIgnoreCase(id)) { return node; } } return null; }
private static String getMissingSourceMessage(Node node, NodeSource source) { return MessageFormat.format("Missing source ''{0}'' in node ''{1}''", source.getSourceNodeId(), node.getId()); } }
private void initOperatorContext() { try { Field field = Operator.class.getDeclaredField("context"); field.setAccessible(true); operatorContext = (OperatorContext) field.get(operator); operatorContext.setId(node.getId()); field.setAccessible(false); } catch (IllegalAccessException | NoSuchFieldException e) { throw new IllegalStateException(e); } }
/** * Adds a <code>Node</code> to the graph * * @param node a node * @throws IllegalArgumentException if the id of the given node is already in use */ public void addNode(Node node) { if (nodeList.contains(getNode(node.getId()))) { throw new IllegalArgumentException("node ID duplicated"); } nodeList.add(node); }
@Test public void testIt() throws Exception { InputStream stream = BinningInGraphTest.class.getResourceAsStream("BinningInGraphTest.xml"); Graph graph = GraphIO.read(new InputStreamReader(stream)); Assert.assertNotNull(graph); Assert.assertEquals(1, graph.getNodeCount()); Assert.assertEquals("subsetNodeId", graph.getNode(0).getId()); Assert.assertEquals("subsetNodeId", graph.getNode(0).getId()); } }