Changeset 11170 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-10-26T18:49:40+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r11122 r11170 7 7 import java.util.ArrayList; 8 8 import java.util.Arrays; 9 import java.util.Collection; 9 10 import java.util.HashMap; 10 11 import java.util.LinkedList; … … 13 14 import java.util.Optional; 14 15 import java.util.concurrent.CopyOnWriteArrayList; 16 import java.util.function.Predicate; 15 17 import java.util.stream.Collectors; 16 18 … … 270 272 271 273 // here we store our shortcuts 272 private static List<Shortcut> shortcuts = new CopyOnWriteArrayList<>(); 274 private static Collection<Shortcut> shortcuts = new CopyOnWriteArrayList<Shortcut>() { 275 @Override 276 public boolean add(Shortcut shortcut) { 277 // expensive consistency check only in debug mode 278 if (Main.isDebugEnabled() 279 && stream().map(Shortcut::getShortText).anyMatch(shortcut.getShortText()::equals)) { 280 Main.warn(new AssertionError(shortcut.getShortText() + " already added")); 281 } 282 return super.add(shortcut); 283 } 284 }; 273 285 274 286 // and here our modifier groups … … 289 301 290 302 private static Optional<Shortcut> findShortcutByKeyOrShortText(int requestedKey, int modifier, String shortText) { 291 if (modifier == getGroupModifier(NONE))292 return Optional.empty();303 final Predicate<Shortcut> sameKey = sc -> modifier != getGroupModifier(NONE) && sc.isSame(requestedKey, modifier); 304 final Predicate<Shortcut> sameShortText = sc -> sc.getShortText().equals(shortText); 293 305 return shortcuts.stream() 294 .filter(s c -> sc.isSame(requestedKey, modifier) || (shortText != null && shortText.equals(sc.getShortText())))306 .filter(sameKey.or(sameShortText)) 295 307 .findAny(); 296 297 308 } 298 309 … … 401 412 // shutdown handling 402 413 public static boolean savePrefs() { 403 boolean changed = false; 404 for (Shortcut sc : shortcuts) { 405 changed = changed | sc.save(); 406 } 407 return changed; 414 return shortcuts.stream() 415 .map(Shortcut::save) 416 .reduce(false, Boolean::logicalOr); // has changed 408 417 } 409 418 … … 510 519 shortText, conflict.getShortText(), newsc.getKeyText())); 511 520 newsc.saveDefault(); 512 shortcuts. replaceAll(sc -> shortText.equals(sc.getShortText()) ? newsc :sc);521 shortcuts.add(newsc); 513 522 return newsc; 514 523 }
Note:
See TracChangeset
for help on using the changeset viewer.