Ignore:
Timestamp:
2016-10-26T21:23:33+02:00 (3 years ago)
Author:
simon04
Message:

Shortcut.findShortcut: return Optional object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r11172 r11173  
    293293     * @param requestedKey the requested key
    294294     * @param modifier the modifier
    295      * @return the registered shortcut or {@code null}
    296      */
    297     public static Shortcut findShortcut(int requestedKey, int modifier) {
    298         return findShortcutByKeyOrShortText(requestedKey, modifier, null)
    299                 .orElse(null);
     295     * @return an {@link Optional} registered shortcut, never {@code null}
     296     */
     297    public static Optional<Shortcut> findShortcut(int requestedKey, int modifier) {
     298        return findShortcutByKeyOrShortText(requestedKey, modifier, null);
    300299    }
    301300
     
    368367        Main.pref.getAllPrefixCollectionKeys("shortcut.entry.").stream()
    369368                .map(Shortcut::new)
    370                 .filter(sc -> findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null)
     369                .filter(sc -> !findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()).isPresent())
    371370                .sorted(Comparator.comparing(sc -> sc.isAssignedUser() ? 1 : sc.isAssignedDefault() ? 2 : 3))
    372371                .forEachOrdered(shortcuts::add);
     
    458457                // Try to reassign Meta to Ctrl
    459458                int newmodifier = findNewOsxModifier(requestedGroup);
    460                 if (findShortcut(requestedKey, newmodifier) == null) {
     459                if (!findShortcut(requestedKey, newmodifier).isPresent()) {
    461460                    Main.info("Reassigning OSX shortcut '" + shortText + "' from Meta to Ctrl because of conflict with " + conflict);
    462461                    return reassignShortcut(shortText, longText, requestedKey, conflict, requestedGroup, requestedKey, newmodifier);
     
    466465                for (int k : keys) {
    467466                    int newmodifier = getGroupModifier(m);
    468                     if (findShortcut(k, newmodifier) == null) {
     467                    if (!findShortcut(k, newmodifier).isPresent()) {
    469468                        Main.info("Reassigning shortcut '" + shortText + "' from " + modifier + " to " + newmodifier +
    470469                                " because of conflict with " + conflict);
Note: See TracChangeset for help on using the changeset viewer.