mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: fix AbstractSet.hashCode
This commit is contained in:
parent
51603695f4
commit
10415b356e
|
@ -15,8 +15,6 @@
|
|||
*/
|
||||
package org.teavm.classlib.java.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class TAbstractSet<E> extends TAbstractCollection<E> implements TSet<E> {
|
||||
public TAbstractSet() {
|
||||
super();
|
||||
|
@ -67,6 +65,13 @@ public abstract class TAbstractSet<E> extends TAbstractCollection<E> implements
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(toArray());
|
||||
int result = 0;
|
||||
for (TIterator<E> iter = iterator(); iter.hasNext();) {
|
||||
E e = iter.next();
|
||||
if (e != null) {
|
||||
result += e.hashCode();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -121,4 +122,16 @@ public class SetTest {
|
|||
assertNull("Iterator did not return all of expected elements", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeTest() {
|
||||
Set<String> a = new LinkedHashSet<>();
|
||||
a.add("foo");
|
||||
a.add("bar");
|
||||
Set<String> b = new LinkedHashSet<>();
|
||||
b.add("bar");
|
||||
b.add("foo");
|
||||
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user