Changeset 13121 in josm for trunk/src/org
- Timestamp:
- 2017-11-13T00:59:15+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/tagging/ac/AutoCompletionItem.java
r12859 r13121 22 22 private AutoCompletionPriority priority; 23 23 /** the value of this item */ 24 private String value;24 private final String value; 25 25 26 26 /** … … 79 79 * @param value the value; must not be null 80 80 * @throws IllegalArgumentException if value if null 81 * @deprecated value is now final, set it when constructing the object 81 82 */ 83 @Deprecated 82 84 public void setValue(String value) { 83 85 CheckParameterUtil.ensureParameterNotNull(value, "value"); 84 th is.value = value;86 throw new UnsupportedOperationException("setValue() is no longer supported"); 85 87 } 86 88 -
trunk/src/org/openstreetmap/josm/data/tagging/ac/AutoCompletionSet.java
r12901 r13121 5 5 import java.util.Objects; 6 6 import java.util.Optional; 7 import java.util.Set; 7 8 import java.util.TreeSet; 8 9 import java.util.stream.Collectors; … … 18 19 public class AutoCompletionSet extends TreeSet<AutoCompletionItem> { 19 20 21 // Keep a separate tree set of values for determining fast if a value is present 22 private final Set<String> values = new TreeSet<>(); 23 20 24 @Override 21 25 public boolean add(AutoCompletionItem e) { 22 26 // Is there already an item for the value? 23 Optional<AutoCompletionItem> result = stream().filter(i -> i.getValue().equals(e.getValue())).findFirst(); 24 if (result.isPresent()) { 25 AutoCompletionItem item = result.get(); 26 // yes: merge priorities 27 AutoCompletionPriority newPriority = item.getPriority().mergeWith(e.getPriority()); 28 // if needed, remove/re-add the updated item to maintain set ordering 29 if (!item.getPriority().equals(newPriority)) { 30 remove(item); 31 item.setPriority(newPriority); 32 return add(item); 27 String value = e.getValue(); 28 if (contains(value)) { // Fast 29 Optional<AutoCompletionItem> result = stream().filter(i -> i.getValue().equals(e.getValue())).findFirst(); // Slow 30 if (result.isPresent()) { 31 AutoCompletionItem item = result.get(); 32 // yes: merge priorities 33 AutoCompletionPriority newPriority = item.getPriority().mergeWith(e.getPriority()); 34 // if needed, remove/re-add the updated item to maintain set ordering 35 if (!item.getPriority().equals(newPriority)) { 36 super.remove(item); 37 item.setPriority(newPriority); 38 return super.add(item); 39 } else { 40 return false; 41 } 33 42 } else { 34 return false; 43 // Should never happen if values is correctly synchronized with this set 44 throw new IllegalStateException(value); 35 45 } 36 46 } else { 47 values.add(value); 37 48 return super.add(e); 38 49 } 50 } 51 52 @Override 53 public boolean remove(Object o) { 54 if (o instanceof AutoCompletionItem) { 55 values.remove(((AutoCompletionItem) o).getValue()); 56 } 57 return super.remove(o); 58 } 59 60 @Override 61 public void clear() { 62 values.clear(); 63 super.clear(); 39 64 } 40 65 … … 74 99 */ 75 100 public boolean contains(String value) { 76 return stream().anyMatch(i -> i.getValue().equals(value));101 return values.contains(value); 77 102 } 78 103 … … 83 108 */ 84 109 public boolean remove(String key) { 85 return removeIf(i -> i.getValue().equals(key));110 return values.remove(key) && removeIf(i -> i.getValue().equals(key)); 86 111 } 87 112 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionListItem.java
r12859 r13121 86 86 */ 87 87 public void setValue(String value) { 88 item.setValue(value);88 throw new UnsupportedOperationException("setValue() is no longer supported"); 89 89 } 90 90 -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
r12865 r13121 332 332 333 333 /** 334 * Populates the an{@link AutoCompletionList} with the currently cached values for some given tags334 * Populates the {@link AutoCompletionList} with the currently cached values for some given tags 335 335 * 336 336 * @param list the list to populate
Note:
See TracChangeset
for help on using the changeset viewer.