Changeset 11394 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-12-14T04:19:09+01:00 (7 years ago)
Author:
Don-vip
Message:

simplify preference settings equals handling (already performed by AbstractList.equals / AbstractMap.equals) - fixes squid:S1206 and findbugs HE_EQUALS_NO_HASHCODE warnings

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/ListListSetting.java

    r10235 r11394  
    55import java.util.Collection;
    66import java.util.Collections;
    7 import java.util.Iterator;
    87import java.util.List;
    9 
    10 import org.openstreetmap.josm.tools.Utils;
    118
    129/**
     
    3936        }
    4037        return new ListListSetting(null);
    41     }
    42 
    43     @Override
    44     public boolean equalVal(List<List<String>> otherVal) {
    45         if (value == null)
    46             return otherVal == null;
    47         if (otherVal == null)
    48             return false;
    49         if (value.size() != otherVal.size())
    50             return false;
    51         Iterator<List<String>> itA = value.iterator();
    52         Iterator<List<String>> itB = otherVal.iterator();
    53         while (itA.hasNext()) {
    54             if (!Utils.equalCollection(itA.next(), itB.next()))
    55                 return false;
    56         }
    57         return true;
    5838    }
    5939
     
    9272        return new ListListSetting(null);
    9373    }
    94 
    95     @Override
    96     public boolean equals(Object other) {
    97         if (!(other instanceof ListListSetting))
    98             return false;
    99         return equalVal(((ListListSetting) other).getValue());
    100     }
    10174}
  • trunk/src/org/openstreetmap/josm/data/preferences/ListSetting.java

    r10235 r11394  
    66import java.util.Collections;
    77import java.util.List;
    8 
    9 import org.openstreetmap.josm.tools.Utils;
    108
    119/**
     
    3331
    3432    @Override
    35     public boolean equalVal(List<String> otherVal) {
    36         return Utils.equalCollection(value, otherVal);
    37     }
    38 
    39     @Override
    4033    public ListSetting copy() {
    4134        return ListSetting.create(value);
     
    5649        return new ListSetting(null);
    5750    }
    58 
    59     @Override
    60     public boolean equals(Object other) {
    61         if (!(other instanceof ListSetting))
    62             return false;
    63         return equalVal(((ListSetting) other).getValue());
    64     }
    6551}
  • trunk/src/org/openstreetmap/josm/data/preferences/MapListSetting.java

    r10235 r11394  
    44import java.util.ArrayList;
    55import java.util.Collections;
    6 import java.util.Iterator;
    76import java.util.LinkedHashMap;
    87import java.util.List;
    98import java.util.Map;
    10 import java.util.Map.Entry;
    11 import java.util.Objects;
    129
    1310/**
     
    2421        super(value);
    2522        consistencyTest();
    26     }
    27 
    28     @Override
    29     public boolean equalVal(List<Map<String, String>> otherVal) {
    30         if (value == null)
    31             return otherVal == null;
    32         if (otherVal == null)
    33             return false;
    34         if (value.size() != otherVal.size())
    35             return false;
    36         Iterator<Map<String, String>> itA = value.iterator();
    37         Iterator<Map<String, String>> itB = otherVal.iterator();
    38         while (itA.hasNext()) {
    39             if (!equalMap(itA.next(), itB.next()))
    40                 return false;
    41         }
    42         return true;
    43     }
    44 
    45     private static boolean equalMap(Map<String, String> a, Map<String, String> b) {
    46         if (a == null)
    47             return b == null;
    48         if (b == null)
    49             return false;
    50         if (a.size() != b.size())
    51             return false;
    52         for (Entry<String, String> e : a.entrySet()) {
    53             if (!Objects.equals(e.getValue(), b.get(e.getKey())))
    54                 return false;
    55         }
    56         return true;
    5723    }
    5824
     
    9157        return new MapListSetting(null);
    9258    }
    93 
    94     @Override
    95     public boolean equals(Object other) {
    96         if (!(other instanceof MapListSetting))
    97             return false;
    98         return equalVal(((MapListSetting) other).getValue());
    99     }
    10059}
  • trunk/src/org/openstreetmap/josm/data/preferences/Setting.java

    r9821 r11394  
    2525     * @return true if the values are equal
    2626     */
    27     boolean equalVal(T otherVal);
     27    default boolean equalVal(T otherVal) {
     28        return getValue() == null ? (otherVal == null) : getValue().equals(otherVal);
     29    }
    2830
    2931    /**
  • trunk/src/org/openstreetmap/josm/data/preferences/StringSetting.java

    r9759 r11394  
    1616
    1717    @Override
    18     public boolean equalVal(String otherVal) {
    19         if (value == null)
    20             return otherVal == null;
    21         return value.equals(otherVal);
    22     }
    23 
    24     @Override
    2518    public StringSetting copy() {
    2619        return new StringSetting(value);
     
    3629        return new StringSetting(null);
    3730    }
    38 
    39     @Override
    40     public boolean equals(Object other) {
    41         if (!(other instanceof StringSetting))
    42             return false;
    43         return equalVal(((StringSetting) other).getValue());
    44     }
    4531}
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r11374 r11394  
    4242import java.util.List;
    4343import java.util.Locale;
    44 import java.util.Objects;
    4544import java.util.concurrent.Executor;
    4645import java.util.concurrent.ForkJoinPool;
     
    524523    public static boolean equalsEpsilon(double a, double b) {
    525524        return Math.abs(a - b) <= EPSILON;
    526     }
    527 
    528     /**
    529      * Determines if two collections are equal.
    530      * @param a first collection
    531      * @param b second collection
    532      * @return {@code true} if collections are equal, {@code false} otherwise
    533      * @since 9217
    534      */
    535     public static boolean equalCollection(Collection<?> a, Collection<?> b) {
    536         if (a == null) return b == null;
    537         if (b == null) return false;
    538         if (a.size() != b.size()) return false;
    539         Iterator<?> itA = a.iterator();
    540         Iterator<?> itB = b.iterator();
    541         while (itA.hasNext()) {
    542             if (!Objects.equals(itA.next(), itB.next()))
    543                 return false;
    544         }
    545         return true;
    546525    }
    547526
Note: See TracChangeset for help on using the changeset viewer.