From: <jan...@us...> - 2006-12-23 23:02:11
|
Revision: 497 http://svn.sourceforge.net/magicmap/?rev=497&view=rev Author: jan_fride Date: 2006-12-23 15:01:49 -0800 (Sat, 23 Dec 2006) Log Message: ----------- javadoc and class did not match (please update javadoc if changing interfaces!) Modified Paths: -------------- trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java Modified: trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java 2006-12-18 14:52:51 UTC (rev 496) +++ trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java 2006-12-23 23:01:49 UTC (rev 497) @@ -164,7 +164,8 @@ /** * Gibt alle Orte/Referenzpunkte zur\xFCck, die mindestens einen * AccessPoint mit der \xFCbergebenen gemeinsam haben. - * @param result + * @param accesspoints + * @param exclude * @return */ public ArrayList<LocationNode> getLocationsWithAtLeastOneAccessPoint(ArrayList<AccessPointNode> accesspoints, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jan...@us...> - 2007-01-11 17:03:12
|
Revision: 498 http://svn.sourceforge.net/magicmap/?rev=498&view=rev Author: jan_fride Date: 2007-01-11 09:02:31 -0800 (Thu, 11 Jan 2007) Log Message: ----------- replaced while(iterator) with foreach Modified Paths: -------------- trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java Modified: trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java 2006-12-23 23:01:49 UTC (rev 497) +++ trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java 2007-01-11 17:02:31 UTC (rev 498) @@ -34,233 +34,243 @@ */ public class NodeModel implements INodeModel { - private final Map<String, Node> nodes; - private final Map<String, Node> accesspoints; - private final List<NodeModelListener> listeners; - private final List<NodeModelSelectionListener> selectListeners; + private final Map<String, Node> nodes; + private final Map<String, AccessPointNode> accesspoints; + private final List<NodeModelListener> listeners; + private final List<NodeModelSelectionListener> selectListeners; - private Node selectedNode = Node.EMPTY_NODE; + private Node selectedNode = Node.EMPTY_NODE; - private final Log log = LogFactory.getLog(NodeModel.class); - /** - * Erzeugt neues leeres Model - * - */ - public NodeModel() { - // Collections.synchronizedMap(new HashMap<String, Double>()); + private final Log log = LogFactory.getLog(NodeModel.class); + /** + * Erzeugt neues leeres Model + * + */ + public NodeModel() { + // Collections.synchronizedMap(new HashMap<String, Double>()); - this.nodes = Collections.synchronizedMap(new HashMap<String, Node>()); - this.accesspoints = Collections.synchronizedMap(new HashMap<String, Node>()); - this.listeners = Collections.synchronizedList(new ArrayList<NodeModelListener>()); - this.selectListeners = Collections.synchronizedList(new ArrayList<NodeModelSelectionListener>()); - } + this.nodes = Collections.synchronizedMap(new HashMap<String, Node>()); + this.accesspoints = Collections.synchronizedMap(new HashMap<String, AccessPointNode>()); + this.listeners = Collections.synchronizedList(new ArrayList<NodeModelListener>()); + this.selectListeners = Collections.synchronizedList(new ArrayList<NodeModelSelectionListener>()); + } - /** - * Add a new node and notifies all listeners about it. - * DOes nothing if a node with the model contains a node with the same name. - * @param node the node to add. - */ - public void addNode(Node node){ - if (this.nodes.containsKey(node.getName())) return; - log.info("Adding Node: " + node.getName()); - this.nodes.put(node.getName(), node); - // special handling for APs - if (node.getType() == NodeModelConstants.NODETYPE_ACCESSPOINT) // Wenn AccessPoint, dann nach MAC-Adresse extra hashen - this.accesspoints.put(((AccessPointNode) node).getMacAddress(), node); - Iterator it = this.listeners.iterator(); - while (it.hasNext()) { - NodeModelListener l = (NodeModelListener) it.next(); - l.nodeAddedEvent(node); - } - } + /** + * Add a new node and notifies all listeners about it. + * DOes nothing if a node with the model contains a node with the same name. + * @param node the node to add. + */ + public void addNode(Node node){ + if (this.nodes.containsKey(node.getName())) return; + log.info("Adding Node: " + node.getName()); + this.nodes.put(node.getName(), node); + // special handling for APs + if (node.getType() == NodeModelConstants.NODETYPE_ACCESSPOINT) // Wenn AccessPoint, dann nach MAC-Adresse extra hashen + this.accesspoints.put(((AccessPointNode) node).getMacAddress(), (AccessPointNode)node); - /** - * Remove a node - * @param node - */ - public void removeNode(Node node){ - this.nodes.remove(node.getName()); - if (node.getType() == NodeModelConstants.NODETYPE_ACCESSPOINT) // Wenn AccessPoint, dann nach MAC-Adresse extra hashen - this.accesspoints.remove(((AccessPointNode) node).getMacAddress()); - Iterator it = this.listeners.iterator(); - while (it.hasNext()) { - NodeModelListener l = (NodeModelListener) it.next(); - l.nodeRemovedEvent(node); - } - } + for (NodeModelListener listener : this.listeners) { + NodeModelListener l = (NodeModelListener) listener; + l.nodeAddedEvent(node); + } + } - public void fireSeesAccessPoint(Node node, AccessPointNode ap){ - updateNode(node, NodeModelConstants.UPDATE_SEESACCESSPOINT, ap); - } + /** + * Remove a node + * @param node + */ + public void removeNode(Node node){ + this.nodes.remove(node.getName()); + if (node.getType() == NodeModelConstants.NODETYPE_ACCESSPOINT) // Wenn AccessPoint, dann nach MAC-Adresse extra hashen + this.accesspoints.remove(((AccessPointNode) node).getMacAddress()); - public void fireNotSeesAccessPoint(Node node, AccessPointNode ap){ - updateNode(node, NodeModelConstants.UPDATE_NOTSEESACCESSPOINT, ap); - } + for (NodeModelListener listener : this.listeners) { + NodeModelListener l = (NodeModelListener) listener; + l.nodeRemovedEvent(node); + } + } - /** - * Notofiziert alle Listener das sich ein Knoten ge\xE4ndert hat. - * - * @param node der ge\xE4ndert Knoten - * @param type die Art der \xC4nderung - * @param data Daten? - */ - public void updateNode(Node node, int type, Object data){ - Iterator it = this.listeners.iterator(); - while (it.hasNext()) { - NodeModelListener l = (NodeModelListener) it.next(); - l.nodeUpdatedEvent(node, type, data); - } - } + public void fireSeesAccessPoint(Node node, AccessPointNode ap){ + updateNode(node, NodeModelConstants.UPDATE_SEESACCESSPOINT, ap); + } - /** - * Aktualisiert den Hash-Schl\xFCssel f\xFCr einen Knoten. - * Unter Node.name wird der neue Hashwert erwartet. - * - * @param node Knoten der aktualisiert werden soll - * @param name Alter Hash-Wert - */ - public void rehashNode(Node node, String name){ - this.nodes.remove(name); - this.nodes.put(node.getName(), node); - updateNode(node, NodeModelConstants.UPDATE_LABELCHANGED, name); - } + public void fireNotSeesAccessPoint(Node node, AccessPointNode ap){ + updateNode(node, NodeModelConstants.UPDATE_NOTSEESACCESSPOINT, ap); + } - public ArrayList findNeighbors(Node node){ - ArrayList result = new ArrayList(); - if (node instanceof ClientNode) { - ArrayList aes = ((ClientNode) node).getApEdges(); - } - return result; - } + /** + * Notofiziert alle Listener das sich ein Knoten ge\xE4ndert hat. + * + * @param node der ge\xE4ndert Knoten + * @param type die Art der \xC4nderung + * @param data Daten, z.B. ein AccessPoint + */ + public void updateNode(Node node, int type, Object data){ - public ArrayList findNonNeighbors(Node node){ - ArrayList result = new ArrayList(); - return result; - } + for (NodeModelListener listener : this.listeners) { + NodeModelListener l = (NodeModelListener) listener; + l.nodeUpdatedEvent(node, type, data); + } + } - public void addNodeModelListener(NodeModelListener nodeModelListener){ - if (!this.listeners.contains(nodeModelListener)) { - this.listeners.add(nodeModelListener); - Iterator nodesIterator = this.nodes.values().iterator(); - while (nodesIterator.hasNext()) { - Node node = (Node) nodesIterator.next(); - nodeModelListener.nodeAddedEvent(node); - } - } - } + /** + * Aktualisiert den Hash-Schl\xFCssel f\xFCr einen Knoten. + * Unter Node.name wird der neue Hashwert erwartet. + * + * @param node Knoten der aktualisiert werden soll + * @param name Alter Hash-Wert + */ + public void rehashNode(Node node, String name){ + this.nodes.remove(name); + this.nodes.put(node.getName(), node); + updateNode(node, NodeModelConstants.UPDATE_LABELCHANGED, name); + } - public void removeNodeModelListener(NodeModelListener l){ - this.listeners.remove(l); - } + public ArrayList findNeighbors(Node node){ + ArrayList result = new ArrayList(); + if (node instanceof ClientNode) { + ArrayList aes = ((ClientNode) node).getApEdges(); + } + return result; + } - public NodeModelListener[] nodeModelListeners(){ - return this.listeners.toArray(new NodeModelListener[0]); - } + public ArrayList findNonNeighbors(Node node){ + ArrayList result = new ArrayList(); + return result; + } - public ArrayList<LocationNode> getLocationsWithAtLeastOneAccessPoint(ArrayList<AccessPointNode> accesspoints){ - return getLocationsWithAtLeastOneAccessPoint(accesspoints, null); - } + public void addNodeModelListener(NodeModelListener nodeModelListener){ + if (!this.listeners.contains(nodeModelListener)) { + this.listeners.add(nodeModelListener); - /** - * Gibt alle Orte/Referenzpunkte zur\xFCck, die mindestens einen - * AccessPoint mit der \xFCbergebenen gemeinsam haben. - * @param accesspoints - * @param exclude - * @return - */ - public ArrayList<LocationNode> getLocationsWithAtLeastOneAccessPoint(ArrayList<AccessPointNode> accesspoints, - Node exclude){ - ArrayList<LocationNode> result = new ArrayList<LocationNode>(); - HashSet<AccessPointNode> accessPointsHash = new HashSet<AccessPointNode>(accesspoints); - Iterator it = this.nodes.values().iterator(); - while (it.hasNext()) { - Node o = (Node) it.next(); - if (o.getType() == NodeModelConstants.NODETYPE_LOCATION && exclude != o) { - LocationNode location = (LocationNode) o; - ArrayList<AccessPointNode> seenAccessPoints = location.getSeenAccessPoints(); - for (int j = 0; j < seenAccessPoints.size(); j++) { - AccessPointNode p = seenAccessPoints.get(j); - if (accessPointsHash.contains(p)) { - result.add(location); - break; - } - } - } - } - return result; - } + for (Node node1 : this.nodes.values()) { + Node node = (Node) node1; + nodeModelListener.nodeAddedEvent(node); + } + } + } - /** - * - */ - public Node findNode(String name){ - Node node = this.nodes.get(name); - return node; - } + public void removeNodeModelListener(NodeModelListener l){ + this.listeners.remove(l); + } - public boolean nodeExists(String name){ - return (findNode(name) != null); - } + public NodeModelListener[] nodeModelListeners(){ + return this.listeners.toArray(new NodeModelListener[0]); + } - public AccessPointNode findAccessPoint(String mac){ - AccessPointNode node = (AccessPointNode) this.accesspoints.get(mac); - return node; - } + public ArrayList<LocationNode> getLocationsWithAtLeastOneAccessPoint(ArrayList<AccessPointNode> accesspoints){ + return getLocationsWithAtLeastOneAccessPoint(accesspoints, null); + } - public boolean accessPointExists(String mac){ - return (findAccessPoint(mac) != null); - } + /** + * Gibt alle Orte/Referenzpunkte zur\xFCck, die mindestens einen + * AccessPoint mit der \xFCbergebenen gemeinsam haben. + * @param accesspoints a list of accesspoints + * @param exclude dont add this node to the results + * @return + */ + public ArrayList<LocationNode> getLocationsWithAtLeastOneAccessPoint( + ArrayList<AccessPointNode> accesspoints, + Node exclude){ + ArrayList<LocationNode> result = new ArrayList<LocationNode>(); + HashSet<AccessPointNode> accessPointsHash = new HashSet<AccessPointNode>(accesspoints); - /** - * @return - */ - public Collection getNodes(){ - return Collections.unmodifiableCollection(this.nodes.values()); - } + for (Node node : this.nodes.values()) { + if (node.getType() == NodeModelConstants.NODETYPE_LOCATION && exclude != node) { + LocationNode location = (LocationNode) node; + ArrayList<AccessPointNode> seenAccessPoints = location.getSeenAccessPoints(); + for (AccessPointNode p : seenAccessPoints) { + if (accessPointsHash.contains(p)) { + result.add(location); + break; + } + } + } + } + return result; + } - /** - * Entfernt alles aus dem Model - * - */ - public void clear(){ - for (Node node : this.nodes.values()) - if (node instanceof AccessPointSeerNode) ((AccessPointSeerNode) node).clearAllEdges(); - this.nodes.clear(); - this.accesspoints.clear(); - updateNode(null, NodeModelConstants.UPDATE_CLEAR, null); - } + /** + * Returns the node with the given name. + * @param name the nodes (display) name + * @return a node or null if node with given name exists + */ + public Node findNode(String name){ + Node node = this.nodes.get(name); + return node; + } - public void addNodeModelSelectionListener(NodeModelSelectionListener l){ - this.selectListeners.add(l); + /** + * Checks if a node with a given name exists in this model + * @param name the nodes name + * @return true if a node with the given name exists, false else + */ + public boolean nodeExists(String name){ + return (findNode(name) != null); + } - } + /** + * Finds an access point with the given mac + * @param mac the mac to search for + * @return an ap or null + */ + public AccessPointNode findAccessPoint(String mac){ + AccessPointNode node = (AccessPointNode) this.accesspoints.get(mac); + return node; + } - public void removeNodeModelSelectionListener(NodeModelSelectionListener l){ - this.selectListeners.remove(l); + public boolean accessPointExists(String mac){ + return accesspoints.containsKey(mac); + } - } + /** + * @return + */ + public Collection getNodes(){ + return Collections.unmodifiableCollection(this.nodes.values()); + } - public Node selectNode(Node newSelectedNode){ - if (null == newSelectedNode) throw new IllegalArgumentException("Not may not be null"); + /** + * Entfernt alles aus dem Model + * + */ + public void clear(){ + for (Node node : this.nodes.values()) + if (node instanceof AccessPointSeerNode) ((AccessPointSeerNode) node).clearAllEdges(); + this.nodes.clear(); + this.accesspoints.clear(); + updateNode(null, NodeModelConstants.UPDATE_CLEAR, null); + } - NodeModelSelectionEvent e = new NodeModelSelectionEvent(this, newSelectedNode, this.selectedNode); - this.selectedNode = newSelectedNode; - updateSelection(e); - return this.selectedNode; - } + public void addNodeModelSelectionListener(NodeModelSelectionListener l){ + this.selectListeners.add(l); - /** - * - * @param e - */ - private void updateSelection(NodeModelSelectionEvent e){ - LinkedList<NodeModelSelectionListener> tmpList = new LinkedList<NodeModelSelectionListener>(); - synchronized (this.selectListeners) { - tmpList.addAll(this.selectListeners); - } + } - for (NodeModelSelectionListener listener : tmpList) - listener.selectionChanged(e); + public void removeNodeModelSelectionListener(NodeModelSelectionListener l){ + this.selectListeners.remove(l); + } - } + public Node selectNode(Node newSelectedNode){ + if (null == newSelectedNode) throw new IllegalArgumentException("node must not be null"); + + NodeModelSelectionEvent e = new NodeModelSelectionEvent(this, newSelectedNode, this.selectedNode); + this.selectedNode = newSelectedNode; + updateSelection(e); + return this.selectedNode; + } + + /** + * + * @param e + */ + private void updateSelection(NodeModelSelectionEvent e){ + LinkedList<NodeModelSelectionListener> tmpList = new LinkedList<NodeModelSelectionListener>(); + synchronized (this.selectListeners) { + tmpList.addAll(this.selectListeners); + } + + for (NodeModelSelectionListener listener : tmpList) + listener.selectionChanged(e); + + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |