source: josm/src/org/openstreetmap/josm/data/osm/Key.java@ 8

Last change on this file since 8 was 8, checked in by imi, 19 years ago
  • added Selection Dialog
  • added support for graphic engines with a better default engine
  • reorganized data classes with back references
File size: 1.6 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import java.util.Collection;
4import java.util.HashMap;
5import java.util.LinkedList;
6import java.util.Map;
7
8import org.openstreetmap.josm.data.osm.visitor.Visitor;
9
10
11/**
12 * A key can be associated together with a value to any osm primitive.
13 *
14 * @author imi
15 */
16public class Key extends OsmPrimitive {
17
18 /**
19 * The key's name
20 */
21 public final String name;
22
23 /**
24 * All keys are stored here.
25 */
26 private static Map<String, Key> allKeys = new HashMap<String, Key>();
27
28 /**
29 * Generate a key with the given name. You cannot call this directly but
30 * have to use the static constructor. This makes sure, you get every key
31 * only once.
32 */
33 private Key(String name) {
34 this.name = name;
35 }
36
37 /**
38 * Get an instance of the key with the given name.
39 * @param name The name of the key to get.
40 * @return An shared instance of the key with the given name.
41 */
42 public static Key get(String name) {
43 Key key = allKeys.get(name);
44 if (key == null) {
45 key = new Key(name);
46 allKeys.put(name, key);
47 }
48 return key;
49 }
50
51 /**
52 * Return an empty list, since keys cannot have nodes.
53 */
54 @Override
55 public Collection<Node> getAllNodes() {
56 return new LinkedList<Node>();
57 }
58
59 /**
60 * Keys are equal, when their name is equal, regardless of their other keys.
61 */
62 @Override
63 public boolean equals(Object obj) {
64 if (!(obj instanceof Key))
65 return false;
66 return name.equals(((Key)obj).name);
67 }
68
69 @Override
70 public int hashCode() {
71 return name.hashCode();
72 }
73
74 @Override
75 public void visit(Visitor visitor) {
76 visitor.visit(this);
77 }
78}
Note: See TracBrowser for help on using the repository browser.