source: josm/trunk/src/org/openstreetmap/josm/data/osm/Tagged.java@ 13633

Last change on this file since 13633 was 13625, checked in by Don-vip, 6 years ago

extract getNumKeys() from AbstractPrimitive to Tagged

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.Collection;
5import java.util.Map;
6
7/**
8 * Objects implement Tagged if they provide a map of key/value pairs.
9 *
10 * @since 2115
11 */
12// FIXME: better naming? setTags(), getTags(), getKeys() instead of keySet() ?
13//
14public interface Tagged {
15
16 /**
17 * The maximum tag length allowed by OSM API
18 * @since 13414
19 */
20 int MAX_TAG_LENGTH = 255;
21
22 /**
23 * Sets the map of key/value pairs
24 *
25 * @param keys the map of key value pairs. If null, reset to the empty map.
26 */
27 void setKeys(Map<String, String> keys);
28
29 /**
30 * Replies the map of key/value pairs. Never null, but may be the empty map.
31 *
32 * @return the map of key/value pairs
33 */
34 Map<String, String> getKeys();
35
36 /**
37 * Sets a key/value pairs
38 *
39 * @param key the key
40 * @param value the value. If null, removes the key/value pair.
41 */
42 void put(String key, String value);
43
44 /**
45 * Sets a key/value pairs
46 *
47 * @param tag The tag to set.
48 * @since 10736
49 */
50 default void put(Tag tag) {
51 put(tag.getKey(), tag.getValue());
52 }
53
54 /**
55 * Replies the value of the given key; null, if there is no value for this key
56 *
57 * @param key the key
58 * @return the value
59 */
60 String get(String key);
61
62 /**
63 * Removes a given key/value pair
64 *
65 * @param key the key
66 */
67 void remove(String key);
68
69 /**
70 * Replies true, if there is at least one key/value pair; false, otherwise
71 *
72 * @return true, if there is at least one key/value pair; false, otherwise
73 */
74 boolean hasKeys();
75
76 /**
77 * Replies true if there is a tag with key <code>key</code>.
78 * The value could however be empty. See {@link #hasTag(String)} to check for non-empty tags.
79 *
80 * @param key the key
81 * @return true, if there is a tag with key <code>key</code>
82 * @see #hasTag(String)
83 * @since 11608
84 */
85 default boolean hasKey(String key) {
86 return get(key) != null;
87 }
88
89 /**
90 * Replies true if there is a non-empty tag with key <code>key</code>.
91 *
92 * @param key the key
93 * @return true, if there is a non-empty tag with key <code>key</code>
94 * @see Tagged#hasKey(String)
95 * @since 13430
96 */
97 default boolean hasTag(String key) {
98 String v = get(key);
99 return v != null && !v.isEmpty();
100 }
101
102 /**
103 * Replies the set of keys
104 *
105 * @return the set of keys
106 */
107 Collection<String> keySet();
108
109 /**
110 * Gets the number of keys
111 * @return The number of keys set for this tagged object.
112 * @since 13625
113 */
114 int getNumKeys();
115
116 /**
117 * Removes all tags
118 */
119 void removeAll();
120}
Note: See TracBrowser for help on using the repository browser.