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


Ignore:
Timestamp:
2016-12-14T00:52:36+01:00 (7 years ago)
Author:
Don-vip
Message:

sonar - squid:S1206 - "equals(Object obj)" and "hashCode()" should be overridden in pairs (required equalsverifier 2.1.8)

File:
1 edited

Legend:

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

    r11342 r11392  
    33
    44import java.util.AbstractSet;
     5import java.util.Arrays;
    56import java.util.Collection;
    67import java.util.ConcurrentModificationException;
     
    239240    public synchronized int hashCode() {
    240241        int h = 0;
    241         for (T t : this) {
    242             h += hash.getHashCode(t);
     242        if (hash != null) {
     243            for (T t : this) {
     244                h += hash.getHashCode(t);
     245            }
    243246        }
    244247        return h;
     248    }
     249
     250    @Override
     251    public boolean equals(Object obj) {
     252        if (this == obj)
     253            return true;
     254        if (obj == null || getClass() != obj.getClass())
     255            return false;
     256        Storage<?> other = (Storage<?>) obj;
     257        return Arrays.equals(data, other.data)
     258                && hashCode() == obj.hashCode();
    245259    }
    246260
     
    321335        int hcode = rehash(ha.getHashCode(key));
    322336        int bucket = hcode & mask;
    323         while ((entry = data[bucket]) != null) {
     337        while (bucket < data.length && (entry = data[bucket]) != null) {
    324338            if (ha.equals(key, entry))
    325339                return bucket;
     
    500514        @Override
    501515        public boolean hasNext() {
     516            if (data == null) return false;
    502517            align();
    503518            return slot < data.length;
     
    533548        @Override
    534549        public boolean hasNext() {
     550            if (data == null) return false;
    535551            align();
    536552            return slot < data.length;
Note: See TracChangeset for help on using the changeset viewer.