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

Java 7: use Objects.equals and Objects.hash

Location:
trunk/src/org/openstreetmap/josm/command/conflict
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java

    r8914 r9371  
    55
    66import java.util.Collection;
     7import java.util.Objects;
    78
    89import javax.swing.Icon;
     
    8990    @Override
    9091    public int hashCode() {
    91         final int prime = 31;
    92         int result = super.hashCode();
    93         result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
    94         return result;
     92        return Objects.hash(super.hashCode(), conflict);
    9593    }
    9694
    9795    @Override
    9896    public boolean equals(Object obj) {
    99         if (this == obj)
    100             return true;
    101         if (!super.equals(obj))
    102             return false;
    103         if (getClass() != obj.getClass())
    104             return false;
    105         ConflictAddCommand other = (ConflictAddCommand) obj;
    106         if (conflict == null) {
    107             if (other.conflict != null)
    108                 return false;
    109         } else if (!conflict.equals(other.conflict))
    110             return false;
    111         return true;
     97        if (this == obj) return true;
     98        if (obj == null || getClass() != obj.getClass()) return false;
     99        if (!super.equals(obj)) return false;
     100        ConflictAddCommand that = (ConflictAddCommand) obj;
     101        return Objects.equals(conflict, that.conflict);
    112102    }
    113103}
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java

    r8914 r9371  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.util.Objects;
    57
    68import org.openstreetmap.josm.Main;
     
    8486    @Override
    8587    public int hashCode() {
    86         final int prime = 31;
    87         int result = super.hashCode();
    88         result = prime * result + ((resolvedConflicts == null) ? 0 : resolvedConflicts.hashCode());
    89         return result;
     88        return Objects.hash(super.hashCode(), resolvedConflicts);
    9089    }
    9190
    9291    @Override
    9392    public boolean equals(Object obj) {
    94         if (this == obj)
    95             return true;
    96         if (!super.equals(obj))
    97             return false;
    98         if (getClass() != obj.getClass())
    99             return false;
    100         ConflictResolveCommand other = (ConflictResolveCommand) obj;
    101         if (resolvedConflicts == null) {
    102             if (other.resolvedConflicts != null)
    103                 return false;
    104         } else if (!resolvedConflicts.equals(other.resolvedConflicts))
    105             return false;
    106         return true;
     93        if (this == obj) return true;
     94        if (obj == null || getClass() != obj.getClass()) return false;
     95        if (!super.equals(obj)) return false;
     96        ConflictResolveCommand that = (ConflictResolveCommand) obj;
     97        return Objects.equals(resolvedConflicts, that.resolvedConflicts);
    10798    }
    10899}
  • trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java

    r8910 r9371  
    55
    66import java.util.Collection;
     7import java.util.Objects;
    78
    89import javax.swing.Icon;
     
    7677    @Override
    7778    public int hashCode() {
    78         final int prime = 31;
    79         int result = super.hashCode();
    80         result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
    81         result = prime * result + ((decision == null) ? 0 : decision.hashCode());
    82         return result;
     79        return Objects.hash(super.hashCode(), conflict, decision);
    8380    }
    8481
    8582    @Override
    8683    public boolean equals(Object obj) {
    87         if (this == obj)
    88             return true;
    89         if (!super.equals(obj))
    90             return false;
    91         if (getClass() != obj.getClass())
    92             return false;
    93         CoordinateConflictResolveCommand other = (CoordinateConflictResolveCommand) obj;
    94         if (conflict == null) {
    95             if (other.conflict != null)
    96                 return false;
    97         } else if (!conflict.equals(other.conflict))
    98             return false;
    99         if (decision != other.decision)
    100             return false;
    101         return true;
     84        if (this == obj) return true;
     85        if (obj == null || getClass() != obj.getClass()) return false;
     86        if (!super.equals(obj)) return false;
     87        CoordinateConflictResolveCommand that = (CoordinateConflictResolveCommand) obj;
     88        return Objects.equals(conflict, that.conflict) &&
     89                decision == that.decision;
    10290    }
    10391}
  • trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java

    r8910 r9371  
    55
    66import java.util.Collection;
     7import java.util.Objects;
    78import java.util.Set;
    89
     
    9192    @Override
    9293    public int hashCode() {
    93         final int prime = 31;
    94         int result = super.hashCode();
    95         result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
    96         result = prime * result + ((decision == null) ? 0 : decision.hashCode());
    97         return result;
     94        return Objects.hash(super.hashCode(), conflict, decision);
    9895    }
    9996
    10097    @Override
    10198    public boolean equals(Object obj) {
    102         if (this == obj)
    103             return true;
    104         if (!super.equals(obj))
    105             return false;
    106         if (getClass() != obj.getClass())
    107             return false;
    108         DeletedStateConflictResolveCommand other = (DeletedStateConflictResolveCommand) obj;
    109         if (conflict == null) {
    110             if (other.conflict != null)
    111                 return false;
    112         } else if (!conflict.equals(other.conflict))
    113             return false;
    114         if (decision != other.decision)
    115             return false;
    116         return true;
     99        if (this == obj) return true;
     100        if (obj == null || getClass() != obj.getClass()) return false;
     101        if (!super.equals(obj)) return false;
     102        DeletedStateConflictResolveCommand that = (DeletedStateConflictResolveCommand) obj;
     103        return Objects.equals(conflict, that.conflict) &&
     104                decision == that.decision;
    117105    }
    118106}
  • trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java

    r8910 r9371  
    66
    77import java.util.Collection;
     8import java.util.Objects;
    89
    910import javax.swing.Icon;
     
    6768    @Override
    6869    public int hashCode() {
    69         final int prime = 31;
    70         int result = super.hashCode();
    71         result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
    72         return result;
     70        return Objects.hash(super.hashCode(), conflict);
    7371    }
    7472
    7573    @Override
    7674    public boolean equals(Object obj) {
    77         if (this == obj)
    78             return true;
    79         if (!super.equals(obj))
    80             return false;
    81         if (getClass() != obj.getClass())
    82             return false;
    83         ModifiedConflictResolveCommand other = (ModifiedConflictResolveCommand) obj;
    84         if (conflict == null) {
    85             if (other.conflict != null)
    86                 return false;
    87         } else if (!conflict.equals(other.conflict))
    88             return false;
    89         return true;
     75        if (this == obj) return true;
     76        if (obj == null || getClass() != obj.getClass()) return false;
     77        if (!super.equals(obj)) return false;
     78        ModifiedConflictResolveCommand that = (ModifiedConflictResolveCommand) obj;
     79        return Objects.equals(conflict, that.conflict);
    9080    }
    9181}
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r8510 r9371  
    66import java.util.Collection;
    77import java.util.List;
     8import java.util.Objects;
    89
    910import javax.swing.Icon;
     
    9899    @Override
    99100    public int hashCode() {
    100         final int prime = 31;
    101         int result = super.hashCode();
    102         result = prime * result + ((mergedMembers == null) ? 0 : mergedMembers.hashCode());
    103         result = prime * result + ((my == null) ? 0 : my.hashCode());
    104         result = prime * result + ((their == null) ? 0 : their.hashCode());
    105         return result;
     101        return Objects.hash(super.hashCode(), my, their, mergedMembers);
    106102    }
    107103
    108104    @Override
    109105    public boolean equals(Object obj) {
    110         if (this == obj)
    111             return true;
    112         if (!super.equals(obj))
    113             return false;
    114         if (getClass() != obj.getClass())
    115             return false;
    116         RelationMemberConflictResolverCommand other = (RelationMemberConflictResolverCommand) obj;
    117         if (mergedMembers == null) {
    118             if (other.mergedMembers != null)
    119                 return false;
    120         } else if (!mergedMembers.equals(other.mergedMembers))
    121             return false;
    122         if (my == null) {
    123             if (other.my != null)
    124                 return false;
    125         } else if (!my.equals(other.my))
    126             return false;
    127         if (their == null) {
    128             if (other.their != null)
    129                 return false;
    130         } else if (!their.equals(other.their))
    131             return false;
    132         return true;
     106        if (this == obj) return true;
     107        if (obj == null || getClass() != obj.getClass()) return false;
     108        if (!super.equals(obj)) return false;
     109        RelationMemberConflictResolverCommand that = (RelationMemberConflictResolverCommand) obj;
     110        return Objects.equals(my, that.my) &&
     111                Objects.equals(their, that.their) &&
     112                Objects.equals(mergedMembers, that.mergedMembers);
    133113    }
    134114}
  • trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java

    r8910 r9371  
    66import java.util.Collection;
    77import java.util.List;
     8import java.util.Objects;
    89
    910import javax.swing.Icon;
     
    103104    @Override
    104105    public int hashCode() {
    105         final int prime = 31;
    106         int result = super.hashCode();
    107         result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
    108         result = prime * result + ((mergeItems == null) ? 0 : mergeItems.hashCode());
    109         return result;
     106        return Objects.hash(super.hashCode(), conflict, mergeItems);
    110107    }
    111108
    112109    @Override
    113110    public boolean equals(Object obj) {
    114         if (this == obj)
    115             return true;
    116         if (!super.equals(obj))
    117             return false;
    118         if (getClass() != obj.getClass())
    119             return false;
    120         TagConflictResolveCommand other = (TagConflictResolveCommand) obj;
    121         if (conflict == null) {
    122             if (other.conflict != null)
    123                 return false;
    124         } else if (!conflict.equals(other.conflict))
    125             return false;
    126         if (mergeItems == null) {
    127             if (other.mergeItems != null)
    128                 return false;
    129         } else if (!mergeItems.equals(other.mergeItems))
    130             return false;
    131         return true;
     111        if (this == obj) return true;
     112        if (obj == null || getClass() != obj.getClass()) return false;
     113        if (!super.equals(obj)) return false;
     114        TagConflictResolveCommand that = (TagConflictResolveCommand) obj;
     115        return Objects.equals(conflict, that.conflict) &&
     116                Objects.equals(mergeItems, that.mergeItems);
    132117    }
    133118}
  • trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java

    r8910 r9371  
    66
    77import java.util.Collection;
     8import java.util.Objects;
    89
    910import javax.swing.Icon;
     
    7677    @Override
    7778    public int hashCode() {
    78         final int prime = 31;
    79         int result = super.hashCode();
    80         result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
    81         return result;
     79        return Objects.hash(super.hashCode(), conflict);
    8280    }
    8381
    8482    @Override
    8583    public boolean equals(Object obj) {
    86         if (this == obj)
    87             return true;
    88         if (!super.equals(obj))
    89             return false;
    90         if (getClass() != obj.getClass())
    91             return false;
    92         VersionConflictResolveCommand other = (VersionConflictResolveCommand) obj;
    93         if (conflict == null) {
    94             if (other.conflict != null)
    95                 return false;
    96         } else if (!conflict.equals(other.conflict))
    97             return false;
    98         return true;
     84        if (this == obj) return true;
     85        if (obj == null || getClass() != obj.getClass()) return false;
     86        if (!super.equals(obj)) return false;
     87        VersionConflictResolveCommand that = (VersionConflictResolveCommand) obj;
     88        return Objects.equals(conflict, that.conflict);
    9989    }
    10090}
  • trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java

    r8910 r9371  
    66import java.util.Collection;
    77import java.util.List;
     8import java.util.Objects;
    89
    910import javax.swing.Icon;
     
    7576    @Override
    7677    public int hashCode() {
    77         final int prime = 31;
    78         int result = super.hashCode();
    79         result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
    80         result = prime * result + ((mergedNodeList == null) ? 0 : mergedNodeList.hashCode());
    81         return result;
     78        return Objects.hash(super.hashCode(), conflict, mergedNodeList);
    8279    }
    8380
    8481    @Override
    8582    public boolean equals(Object obj) {
    86         if (this == obj)
    87             return true;
    88         if (!super.equals(obj))
    89             return false;
    90         if (getClass() != obj.getClass())
    91             return false;
    92         WayNodesConflictResolverCommand other = (WayNodesConflictResolverCommand) obj;
    93         if (conflict == null) {
    94             if (other.conflict != null)
    95                 return false;
    96         } else if (!conflict.equals(other.conflict))
    97             return false;
    98         if (mergedNodeList == null) {
    99             if (other.mergedNodeList != null)
    100                 return false;
    101         } else if (!mergedNodeList.equals(other.mergedNodeList))
    102             return false;
    103         return true;
     83        if (this == obj) return true;
     84        if (obj == null || getClass() != obj.getClass()) return false;
     85        if (!super.equals(obj)) return false;
     86        WayNodesConflictResolverCommand that = (WayNodesConflictResolverCommand) obj;
     87        return Objects.equals(conflict, that.conflict) &&
     88                Objects.equals(mergedNodeList, that.mergedNodeList);
    10489    }
    10590}
Note: See TracChangeset for help on using the changeset viewer.