Changeset 11392 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Storage.java
r11342 r11392 3 3 4 4 import java.util.AbstractSet; 5 import java.util.Arrays; 5 6 import java.util.Collection; 6 7 import java.util.ConcurrentModificationException; … … 239 240 public synchronized int hashCode() { 240 241 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 } 243 246 } 244 247 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(); 245 259 } 246 260 … … 321 335 int hcode = rehash(ha.getHashCode(key)); 322 336 int bucket = hcode & mask; 323 while ( (entry = data[bucket]) != null) {337 while (bucket < data.length && (entry = data[bucket]) != null) { 324 338 if (ha.equals(key, entry)) 325 339 return bucket; … … 500 514 @Override 501 515 public boolean hasNext() { 516 if (data == null) return false; 502 517 align(); 503 518 return slot < data.length; … … 533 548 @Override 534 549 public boolean hasNext() { 550 if (data == null) return false; 535 551 align(); 536 552 return slot < data.length; -
trunk/test/unit/org/openstreetmap/josm/data/osm/StorageTest.java
r11325 r11392 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import org.junit.Ignore;5 4 import org.junit.Rule; 6 5 import org.junit.Test; … … 9 8 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 10 9 import nl.jqno.equalsverifier.EqualsVerifier; 10 import nl.jqno.equalsverifier.Warning; 11 11 12 12 /** … … 26 26 */ 27 27 @Test 28 @Ignore("not ready")29 28 public void testEqualsContract() { 30 29 EqualsVerifier.forClass(Storage.class).usingGetClass() 31 /*.withPrefabValues(Collection.class, new HashSet<>(Arrays.asList(1)), new HashSet<>(Arrays.asList(2))) 32 .withPrefabValues(AbstractCollection.class, new HashSet<>(Arrays.asList(1)), new HashSet<>(Arrays.asList(2))) 33 .withPrefabValues(Set.class, new HashSet<>(Arrays.asList(1)), new HashSet<>(Arrays.asList(2))) 34 .withPrefabValues(AbstractSet.class, new HashSet<>(Arrays.asList(1)), new HashSet<>(Arrays.asList(2)))*/ 30 .suppress(Warning.NONFINAL_FIELDS) 31 .withIgnoredFields("arrayCopyNecessary", "hash", "mask", "modCount", "safeIterator", "size") 35 32 .withPrefabValues(Hash.class, Storage.<Integer>defaultHash(), Storage.<Boolean>defaultHash()) 36 33 .verify();
Note:
See TracChangeset
for help on using the changeset viewer.