Ignore:
Timestamp:
2016-01-09T23:20:37+01:00 (8 years ago)
Author:
simon04
Message:

Java 7: use Objects.equals and Objects.hash

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java

    r9070 r9371  
    1616import java.util.List;
    1717import java.util.Map;
     18import java.util.Objects;
    1819import java.util.Set;
    1920import java.util.Stack;
     
    343344        @Override
    344345        public int hashCode() {
    345             final int prime = 31;
    346             int result = 1;
    347             result = prime * result + ((a == null) ? 0 : a.hashCode());
    348             result = prime * result + ((b == null) ? 0 : b.hashCode());
    349             return result;
     346            return Objects.hash(a, b);
    350347        }
    351348
    352349        @Override
    353350        public boolean equals(Object obj) {
    354             if (this == obj)
    355                 return true;
    356             if (obj == null)
    357                 return false;
    358             if (getClass() != obj.getClass())
    359                 return false;
    360             NodePair other = (NodePair) obj;
    361             if (a == null) {
    362                 if (other.a != null)
    363                     return false;
    364             } else if (!a.equals(other.a))
    365                 return false;
    366             if (b == null) {
    367                 if (other.b != null)
    368                     return false;
    369             } else if (!b.equals(other.b))
    370                 return false;
    371             return true;
     351            if (this == obj) return true;
     352            if (obj == null || getClass() != obj.getClass()) return false;
     353            NodePair nodePair = (NodePair) obj;
     354            return Objects.equals(a, nodePair.a) &&
     355                    Objects.equals(b, nodePair.b);
    372356        }
    373357    }
  • trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r8895 r9371  
    1111import java.util.LinkedList;
    1212import java.util.List;
     13import java.util.Objects;
    1314import java.util.ServiceConfigurationError;
    1415
     
    350351    @Override
    351352    public int hashCode() {
    352         final int prime = 31;
    353         int result = 1;
    354         result = prime * result + ((defaultExtension == null) ? 0 : defaultExtension.hashCode());
    355         result = prime * result + ((description == null) ? 0 : description.hashCode());
    356         result = prime * result + ((extensions == null) ? 0 : extensions.hashCode());
    357         return result;
     353        return Objects.hash(extensions, description, defaultExtension);
    358354    }
    359355
    360356    @Override
    361357    public boolean equals(Object obj) {
    362         if (this == obj)
    363             return true;
    364         if (obj == null)
    365             return false;
    366         if (getClass() != obj.getClass())
    367             return false;
    368         ExtensionFileFilter other = (ExtensionFileFilter) obj;
    369         if (defaultExtension == null) {
    370             if (other.defaultExtension != null)
    371                 return false;
    372         } else if (!defaultExtension.equals(other.defaultExtension))
    373             return false;
    374         if (description == null) {
    375             if (other.description != null)
    376                 return false;
    377         } else if (!description.equals(other.description))
    378             return false;
    379         if (extensions == null) {
    380             if (other.extensions != null)
    381                 return false;
    382         } else if (!extensions.equals(other.extensions))
    383             return false;
    384         return true;
     358        if (this == obj) return true;
     359        if (obj == null || getClass() != obj.getClass()) return false;
     360        ExtensionFileFilter that = (ExtensionFileFilter) obj;
     361        return Objects.equals(extensions, that.extensions) &&
     362                Objects.equals(description, that.description) &&
     363                Objects.equals(defaultExtension, that.defaultExtension);
    385364    }
    386365}
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r9295 r9371  
    1717import java.util.List;
    1818import java.util.Map;
     19import java.util.Objects;
    1920import java.util.Set;
    2021import java.util.TreeMap;
     
    9293        @Override
    9394        public int hashCode() {
    94             return rel.hashCode();
     95            return Objects.hash(rel, role);
    9596        }
    9697
    9798        @Override
    9899        public boolean equals(Object other) {
    99             if (!(other instanceof RelationRole)) return false;
    100             RelationRole otherMember = (RelationRole) other;
    101             return otherMember.role.equals(role) && otherMember.rel.equals(rel);
     100            if (this == other) return true;
     101            if (other == null || getClass() != other.getClass()) return false;
     102            RelationRole that = (RelationRole) other;
     103            return Objects.equals(rel, that.rel) &&
     104                    Objects.equals(role, that.role);
    102105        }
    103106    }
     
    120123        @Override
    121124        public int hashCode() {
    122             return way.hashCode();
     125            return Objects.hash(way, insideToTheRight);
    123126        }
    124127
    125128        @Override
    126129        public boolean equals(Object other) {
    127             if (!(other instanceof WayInPolygon)) return false;
    128             WayInPolygon otherMember = (WayInPolygon) other;
    129             return otherMember.way.equals(this.way) && otherMember.insideToTheRight == this.insideToTheRight;
     130            if (this == other) return true;
     131            if (other == null || getClass() != other.getClass()) return false;
     132            WayInPolygon that = (WayInPolygon) other;
     133            return insideToTheRight == that.insideToTheRight &&
     134                    Objects.equals(way, that.way);
    130135        }
    131136    }
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r9079 r9371  
    2424import java.util.List;
    2525import java.util.Map;
     26import java.util.Objects;
    2627import java.util.Set;
    2728
     
    677678        @Override
    678679        public boolean equals(Object other) {
    679             if (!(other instanceof SearchSetting))
    680                 return false;
    681             SearchSetting o = (SearchSetting) other;
    682             return o.caseSensitive == this.caseSensitive
    683                     && o.regexSearch == this.regexSearch
    684                     && o.mapCSSSearch == this.mapCSSSearch
    685                     && o.allElements == this.allElements
    686                     && o.mode.equals(this.mode)
    687                     && o.text.equals(this.text);
     680            if (this == other) return true;
     681            if (other == null || getClass() != other.getClass()) return false;
     682            SearchSetting that = (SearchSetting) other;
     683            return caseSensitive == that.caseSensitive &&
     684                    regexSearch == that.regexSearch &&
     685                    mapCSSSearch == that.mapCSSSearch &&
     686                    allElements == that.allElements &&
     687                    Objects.equals(text, that.text) &&
     688                    mode == that.mode;
    688689        }
    689690
    690691        @Override
    691692        public int hashCode() {
    692             return text.hashCode();
     693            return Objects.hash(text, mode, caseSensitive, regexSearch, mapCSSSearch, allElements);
    693694        }
    694695
Note: See TracChangeset for help on using the changeset viewer.