From f2aa4d06e218670fe40b602ea068db3c50446358 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 3 Jun 2008 08:50:51 +0200 Subject: [PATCH] store nodes by id add method to get node by id --- src/net/pterodactylus/jsite/core/NodeManager.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 -- 2.7.4