From: David ‘Bombe’ Roden Date: Tue, 3 Jun 2008 06:50:51 +0000 (+0200) Subject: store nodes by id X-Git-Url: https://git.pterodactylus.net/?p=jSite2.git;a=commitdiff_plain;h=f2aa4d06e218670fe40b602ea068db3c50446358 store nodes by id add method to get node by id --- diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 4224cf1..c251232 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -72,6 +72,9 @@ public class NodeManager implements Iterable, PropertyChangeListener, High /** All nodes. */ private List nodes = Collections.synchronizedList(new ArrayList()); + /** Map from node ID to node. */ + private Map idNodes = Collections.synchronizedMap(new HashMap()); + /** All FCP connections. */ private Map nodeClients = Collections.synchronizedMap(new HashMap()); @@ -332,6 +335,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High node.addPropertyChangeListener(this); HighLevelClient highLevelClient = new HighLevelClient(clientName); nodes.add(node); + idNodes.put(node.getId(), node); clientNodes.put(highLevelClient, node); nodeClients.put(node, highLevelClient); highLevelClient.addHighLevelClientListener(this); @@ -355,6 +359,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High disconnect(node); } nodes.remove(node); + idNodes.remove(node.getId()); node.removePropertyChangeListener(this); fireNodeRemoved(node); } @@ -432,6 +437,18 @@ public class NodeManager implements Iterable, PropertyChangeListener, High } /** + * Returns the node identified by the given ID. + * + * @param id + * The ID of the node + * @return The node with the given ID, or null if no such + * node was found + */ + Node getNode(String id) { + return idNodes.get(id); + } + + /** * Generates a new SSK key pair. * * @return An array with the private key at index 0 and the