Changeset 15012 in josm for trunk/src


Ignore:
Timestamp:
2019-04-22T13:56:24+02:00 (5 years ago)
Author:
Don-vip
Message:

remove duplicated code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r14925 r15012  
    1818import java.util.concurrent.TimeUnit;
    1919import java.util.concurrent.atomic.AtomicLong;
     20import java.util.function.BiPredicate;
    2021
    2122import org.openstreetmap.josm.spi.preferences.Config;
     
    629630    }
    630631
    631     /**
    632      * Replies the value for key <code>key</code>. Replies null, if <code>key</code> is null.
    633      * Replies null, if there is no value for the given key.
    634      *
    635      * @param key the key. Can be null, replies null in this case.
    636      * @return the value for key <code>key</code>.
    637      */
    638     @Override
    639     public final String get(String key) {
     632    protected final String doGet(String key, BiPredicate<String, String> predicate) {
    640633        if (key == null)
    641634            return null;
     
    643636            return null;
    644637        for (int i = 0; i < keys.length; i += 2) {
    645             if (keys[i].equals(key)) return keys[i+1];
     638            if (predicate.test(keys[i], key)) return keys[i+1];
    646639        }
    647640        return null;
     641    }
     642
     643    /**
     644     * Replies the value for key <code>key</code>. Replies null, if <code>key</code> is null.
     645     * Replies null, if there is no value for the given key.
     646     *
     647     * @param key the key. Can be null, replies null in this case.
     648     * @return the value for key <code>key</code>.
     649     */
     650    @Override
     651    public final String get(String key) {
     652        return doGet(key, String::equals);
    648653    }
    649654
     
    654659     */
    655660    public final String getIgnoreCase(String key) {
    656         if (key == null)
    657             return null;
    658         if (keys == null)
    659             return null;
    660         for (int i = 0; i < keys.length; i += 2) {
    661             if (keys[i].equalsIgnoreCase(key)) return keys[i+1];
    662         }
    663         return null;
     661        return doGet(key, String::equalsIgnoreCase);
    664662    }
    665663
Note: See TracChangeset for help on using the changeset viewer.