private void route(JsonObject message, int fromNode) { String text = message.getString("text", null); int from = message.getInt("from", -1); int to = message.getInt("to", -1); if (fromNode == from && to >= 0 && text != null) { SwingUtilities.invokeLater( () -> { messages.addPacket(from, to, text, getByNode(from).getNetwork()); }); if (to == 0) { for (int i = 0; i < connections.size(); i++) { Connection c = connections.get(i); if (c != null && links.isNeighbour(fromNode, c.getNode())) { send(c, text, from, to); } } } else { Connection c = getByNode(to); if (c != null && links.isNeighbour(from, to)) { send(c, text, from, to); } } } }
private void addLink(int from, int to, String network) { int nodeA = connections.get(from).getNode(); int nodeB = connections.get(to).getNode(); System.out.println("Create link between " + nodeA + " and " + nodeB); if (!links.isNeighbour(nodeA, nodeB)) { links.addElement(new Link(nodeA, nodeB, network)); } }