Changeset 2048 in josm for trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java
- Timestamp:
- 2009-09-04T10:49:53+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/tagging/ac
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java
r1930 r2048 1 package org.openstreetmap.josm.gui. dialogs.relation.ac;1 package org.openstreetmap.josm.gui.tagging.ac; 2 2 3 3 import java.util.ArrayList; … … 5 5 import java.util.Collections; 6 6 import java.util.HashMap; 7 import java.util.HashSet; 8 import java.util.LinkedList; 7 9 import java.util.List; 10 import java.util.Set; 8 11 import java.util.logging.Logger; 9 12 … … 67 70 68 71 69 /** the cache */ 70 private HashMap<String, ArrayList<String>> cache; 71 private ArrayList<String> roleCache; 72 /** the cached tags give by a tag key and a list of values for this tag*/ 73 private HashMap<String, Set<String>> tagCache; 74 /** the cached list of member roles */ 75 private Set<String> roleCache; 76 /** the cache of all tag values */ 77 private Set<String> allTagValues; 78 /** the layer this cache is built for */ 72 79 private OsmDataLayer layer; 73 80 81 74 82 /** 75 83 * constructor 76 84 */ 77 85 public AutoCompletionCache(OsmDataLayer layer) { 78 cache = new HashMap<String, ArrayList<String>>(); 79 roleCache = new ArrayList<String>(); 86 tagCache = new HashMap<String, Set<String>>(); 87 roleCache = new HashSet<String>(); 88 allTagValues = new HashSet<String>(); 80 89 this.layer = layer; 81 90 } … … 91 100 */ 92 101 protected void cacheKey(String key) { 93 if ( cache.containsKey(key))102 if (tagCache.containsKey(key)) 94 103 return; 95 else { 96 cache.put(key, new ArrayList<String>()); 97 } 104 tagCache.put(key, new HashSet<String>()); 98 105 } 99 106 … … 106 113 protected void cacheValue(String key, String value) { 107 114 cacheKey(key); 108 ArrayList<String> values = cache.get(key); 109 if (!values.contains(value)) { 110 values.add(value); 111 } 115 tagCache.get(key).add(value); 116 allTagValues.add(value); 112 117 } 113 118 … … 143 148 * 144 149 */ 145 public void initFrom JOSMDataset() {146 cache = new HashMap<String, ArrayList<String>>();150 public void initFromDataSet() { 151 tagCache = new HashMap<String, Set<String>>(); 147 152 if (layer == null) 148 153 return; … … 152 157 } 153 158 for (Relation relation : layer.data.relations) { 154 if (relation.incomplete || relation. deleted) {159 if (relation.incomplete || relation.isDeleted()) { 155 160 continue; 156 161 } 157 162 cacheRelationMemberRoles(relation); 158 Collections.sort(roleCache);159 163 } 160 164 } … … 166 170 */ 167 171 public List<String> getKeys() { 168 return new ArrayList<String>( cache.keySet());172 return new ArrayList<String>(tagCache.keySet()); 169 173 } 170 174 … … 177 181 */ 178 182 public List<String> getValues(String key) { 179 if (! cache.containsKey(key))183 if (!tagCache.containsKey(key)) 180 184 return new ArrayList<String>(); 181 return cache.get(key);185 return new ArrayList<String>(tagCache.get(key)); 182 186 } 183 187 … … 188 192 */ 189 193 public List<String> getMemberRoles() { 190 return roleCache;194 return new ArrayList<String>(roleCache); 191 195 } 192 196 … … 199 203 public void populateWithMemberRoles(AutoCompletionList list) { 200 204 list.clear(); 201 for (String role: roleCache) { 202 list.add(new AutoCompletionListItem(role, AutoCompletionItemPritority.IS_IN_DATASET)); 203 } 205 list.add(roleCache, AutoCompletionItemPritority.IS_IN_DATASET); 206 } 207 208 /** 209 * Populates the an {@see AutoCompletionList} with the currently cached 210 * values for a tag 211 * 212 * @param list the list to populate 213 * @param key the tag key 214 * @param append true to add the values to the list; false, to replace the values 215 * in the list by the tag values 216 */ 217 public void populateWithTagValues(AutoCompletionList list, String key, boolean append) { 218 if (!append) { 219 list.clear(); 220 } 221 list.add(getValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 222 } 223 224 /** 225 * Populates the an {@see AutoCompletionList} with the currently cached 226 * tag keys 227 * 228 * @param list the list to populate 229 * @param append true to add the keys to the list; false, to replace the keys 230 * in the list by the keys in the cache 231 */ 232 public void populateWithKeys(AutoCompletionList list, boolean append) { 233 if (!append) { 234 list.clear(); 235 } 236 list.add(tagCache.keySet(), AutoCompletionItemPritority.IS_IN_DATASET); 237 } 238 239 240 /** 241 * Populates the an {@see AutoCompletionList} with the currently cached 242 * tag values 243 * 244 * @param list the list to populate 245 * @param append true to add the keys to the list; false, to replace the keys 246 * in the list by the keys in the cache 247 */ 248 public void populateWithValues(AutoCompletionList list, boolean append) { 249 if (!append) { 250 list.clear(); 251 } 252 list.add(this.allTagValues, AutoCompletionItemPritority.IS_IN_DATASET); 204 253 } 205 254 }
Note:
See TracChangeset
for help on using the changeset viewer.