Changeset 15440 in josm for trunk/src


Ignore:
Timestamp:
2019-10-07T21:32:54+02:00 (5 years ago)
Author:
Don-vip
Message:

checkstyle/findbugs/sonar

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r15113 r15440  
    1616import java.util.Locale;
    1717import java.util.Map;
     18import java.util.Objects;
    1819import java.util.Optional;
    1920import java.util.function.Predicate;
     
    711712        @Override
    712713        public boolean match(Tagged osm) {
    713 
    714714            if (keyPattern != null) {
    715                 if (!osm.hasKeys())
    716                     return false;
    717 
    718                 /* The string search will just get a key like
    719                  * 'highway' and look that up as osm.get(key). But
    720                  * since we're doing a regex match we'll have to loop
    721                  * over all the keys to see if they match our regex,
    722                  * and only then try to match against the value
    723                  */
    724 
    725                 for (String k: osm.keySet()) {
    726                     String v = osm.get(k);
    727 
    728                     Matcher matcherKey = keyPattern.matcher(k);
    729                     boolean matchedKey = matcherKey.find();
    730 
    731                     if (matchedKey) {
    732                         Matcher matcherValue = valuePattern.matcher(v);
    733                         boolean matchedValue = matcherValue.find();
    734 
    735                         if (matchedValue)
     715                if (osm.hasKeys()) {
     716                    // The string search will just get a key like 'highway' and look that up as osm.get(key).
     717                    // But since we're doing a regex match we'll have to loop over all the keys to see if they match our regex,
     718                    // and only then try to match against the value
     719                    for (String k: osm.keySet()) {
     720                        if (keyPattern.matcher(k).find() && valuePattern.matcher(osm.get(k)).find()) {
    736721                            return true;
    737                     }
    738                 }
    739             } else {
    740                 String mv;
    741 
    742                 if ("timestamp".equals(key) && osm instanceof OsmPrimitive) {
    743                     mv = DateUtils.fromTimestamp(((OsmPrimitive) osm).getRawTimestamp());
    744                 } else {
    745                     mv = osm.get(key);
    746                     if (!caseSensitive && mv == null) {
    747                         for (String k: osm.keySet()) {
    748                             if (key.equalsIgnoreCase(k)) {
    749                                 mv = osm.get(k);
    750                                 break;
    751                             }
    752722                        }
    753723                    }
    754724                }
    755 
    756                 if (mv == null)
    757                     return false;
    758 
    759                 String v1 = caseSensitive ? mv : mv.toLowerCase(Locale.ENGLISH);
    760                 String v2 = caseSensitive ? value : value.toLowerCase(Locale.ENGLISH);
    761 
    762                 v1 = Normalizer.normalize(v1, Normalizer.Form.NFC);
    763                 v2 = Normalizer.normalize(v2, Normalizer.Form.NFC);
    764                 return v1.indexOf(v2) != -1;
    765             }
    766 
     725            } else {
     726                String mv = getMv(osm);
     727                if (mv != null) {
     728                    String v1 = Normalizer.normalize(caseSensitive ? mv : mv.toLowerCase(Locale.ENGLISH), Normalizer.Form.NFC);
     729                    String v2 = Normalizer.normalize(caseSensitive ? value : value.toLowerCase(Locale.ENGLISH), Normalizer.Form.NFC);
     730                    return v1.indexOf(v2) != -1;
     731                }
     732            }
    767733            return false;
    768734        }
    769735
     736        private String getMv(Tagged osm) {
     737            String mv;
     738            if ("timestamp".equals(key) && osm instanceof OsmPrimitive) {
     739                mv = DateUtils.fromTimestamp(((OsmPrimitive) osm).getRawTimestamp());
     740            } else {
     741                mv = osm.get(key);
     742                if (!caseSensitive && mv == null) {
     743                    for (String k: osm.keySet()) {
     744                        if (key.equalsIgnoreCase(k)) {
     745                            mv = osm.get(k);
     746                            break;
     747                        }
     748                    }
     749                }
     750            }
     751            return mv;
     752        }
     753
    770754        @Override
    771755        public String toString() {
     
    775759        @Override
    776760        public int hashCode() {
    777             final int prime = 31;
    778             int result = 1;
    779             result = prime * result + (caseSensitive ? 1231 : 1237);
    780             result = prime * result + ((key == null) ? 0 : key.hashCode());
    781             result = prime * result + ((keyPattern == null) ? 0 : keyPattern.hashCode());
    782             result = prime * result + ((value == null) ? 0 : value.hashCode());
    783             result = prime * result + ((valuePattern == null) ? 0 : valuePattern.hashCode());
    784             return result;
     761            return Objects.hash(caseSensitive, key, keyPattern, value, valuePattern);
    785762        }
    786763
     
    792769                return false;
    793770            KeyValue other = (KeyValue) obj;
    794             if (caseSensitive != other.caseSensitive)
    795                 return false;
    796             if (key == null) {
    797                 if (other.key != null)
    798                     return false;
    799             } else if (!key.equals(other.key))
    800                 return false;
    801             if (keyPattern == null) {
    802                 if (other.keyPattern != null)
    803                     return false;
    804             } else if (!keyPattern.equals(other.keyPattern))
    805                 return false;
    806             if (value == null) {
    807                 if (other.value != null)
    808                     return false;
    809             } else if (!value.equals(other.value))
    810                 return false;
    811             if (valuePattern == null) {
    812                 if (other.valuePattern != null)
    813                     return false;
    814             } else if (!valuePattern.equals(other.valuePattern))
    815                 return false;
    816             return true;
     771            return caseSensitive == other.caseSensitive
     772                    && Objects.equals(key, other.key)
     773                    && Objects.equals(keyPattern, other.keyPattern)
     774                    && Objects.equals(value, other.value)
     775                    && Objects.equals(valuePattern, other.valuePattern);
    817776        }
    818777    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/QuadStateCheckBox.java

    r15437 r15440  
    4545    private final transient QuadStateDecorator cbModel;
    4646    private State[] allowed;
    47     private final MouseListener mouseAdapter = new MouseAdapter() {
     47    private final transient MouseListener mouseAdapter = new MouseAdapter() {
    4848        @Override
    4949        public void mousePressed(MouseEvent e) {
Note: See TracChangeset for help on using the changeset viewer.