Changeset 15936 in josm


Ignore:
Timestamp:
2020-02-26T01:52:21+01:00 (5 weeks ago)
Author:
simon04
Message:

PseudoClassCondition: use Stream API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java

    r15934 r15936  
    44import java.lang.reflect.Method;
    55import java.text.MessageFormat;
     6import java.util.Arrays;
    67import java.util.EnumSet;
    78import java.util.Map;
     
    828829
    829830        protected static Method getMethod(String id) {
    830             String cleanId = id.replaceAll("-|_", "");
    831             for (Method method : PseudoClasses.class.getDeclaredMethods()) {
    832                 // for backwards compatibility, consider :sameTags == :same-tags == :same_tags (#11150)
    833                 final String methodName = method.getName().replaceAll("-|_", "");
    834                 if (methodName.equalsIgnoreCase(cleanId)) {
    835                     return method;
    836                 }
    837             }
    838             return null;
     831            String cleanId = clean(id);
     832            return Arrays.stream(PseudoClasses.class.getDeclaredMethods())
     833                    .filter(method -> clean(method.getName()).equalsIgnoreCase(cleanId))
     834                    .findFirst().orElse(null);
     835        }
     836
     837        private static String clean(String id) {
     838            // for backwards compatibility, consider :sameTags == :same-tags == :same_tags (#11150)
     839            return id.replaceAll("[-_]", "");
    839840        }
    840841
Note: See TracChangeset for help on using the changeset viewer.