Class NodeMap

 1 /*
 2  * Copyright (c) 2016 Vivid Solutions.
 3  *
 4  * All rights reserved. This program and the accompanying materials
 5  * are made available under the terms of the Eclipse Public License 2.0
 6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 8  * and the Eclipse Distribution License is available at
 9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  */
12  
13 package org.locationtech.jts.planargraph;
14  
15  
16 import java.util.Collection;
17 import java.util.Iterator;
18 import java.util.Map;
19 import java.util.TreeMap;
20  
21 import org.locationtech.jts.geom.Coordinate;
22  
23  
24 /**
25  * A map of {@link Node}s, indexed by the coordinate of the node.
26  *
27  * @version 1.7
28  */
29 public class NodeMap
30  
31 {
32  
33   private Map nodeMap = new TreeMap();
34   
35   /**
36    * Constructs a NodeMap without any Nodes.
37    */
38   public NodeMap() {
39   }
40  
41   /**
42    * Adds a node to the map, replacing any that is already at that location.
43    * @return the added node
44    */
45   public Node add(Node n)
46   {
47     nodeMap.put(n.getCoordinate(), n);
48     return n;
49   }
50  
51   /**
52    * Removes the Node at the given location, and returns it (or null if no Node was there).
53    */
54   public Node remove(Coordinate pt)
55   {
56     return (Node) nodeMap.remove(pt);
57   }
58  
59   /**
60    * Returns the Node at the given location, or null if no Node was there.
61    */
62   public Node find(Coordinate coord)  {    return (Node) nodeMap.get(coord);  }
63  
64   /**
65    * Returns an Iterator over the Nodes in this NodeMap, sorted in ascending order
66    * by angle with the positive x-axis.
67    */
68   public Iterator iterator()
69   {
70     return nodeMap.values().iterator();
71   }
72   /**
73    * Returns the Nodes in this NodeMap, sorted in ascending order
74    * by angle with the positive x-axis.
75    */
76   public Collection values()
77   {
78     return nodeMap.values();
79   }
80  
81 }
82