mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-13 02:14:52 +00:00
fix[HashMapLongLong]: type conversion error
This commit is contained in:
1 parent
b847f008d6
commit
b6d3103d81
2 files changed
+43
-4
No files matched your search
@@ -74,13 +74,13 @@ public class HashMapLongLong implements Map<Long, Long> {
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
public boolean containsKeyPrimitive(int key) {
|
||||
public boolean containsKeyPrimitive(long key) {
|
||||
return indexOf(key) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return containsKeyPrimitive(ArrayUtils.intValue((Integer) key));
|
||||
return containsKeyPrimitive(ArrayUtils.longValue((Long) key));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,7 +99,7 @@ public class HashMapLongLong implements Map<Long, Long> {
|
||||
|
||||
@Override
|
||||
public Long get(Object key) {
|
||||
var index = indexOf(ArrayUtils.intValue((Integer) key));
|
||||
var index = indexOf(ArrayUtils.longValue((Number) key));
|
||||
return index == -1 ? null : values[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ public class HashMapTest {
|
||||
int dummy1 = 0, dummy2 = 0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
var it = map.entrySet().iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
var next = it.next();
|
||||
dummy1 ^= next.getKey();
|
||||
dummy2 ^= next.getValue();
|
||||
@@ -323,4 +323,43 @@ public class HashMapTest {
|
||||
Assert.assertEquals(dummy2, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intIntEqualsTest() {
|
||||
var map = Map.of(1, 2, 3, 4, 5, 6, Integer.MAX_VALUE, Integer.MIN_VALUE);
|
||||
var myMap = new HashMapIntInt();
|
||||
myMap.putAll(map);
|
||||
Assert.assertEquals(map, myMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intLongEqualsTest() {
|
||||
var map = Map.of(1, 2L, 3, 4L, 5, 6L, Integer.MAX_VALUE, Long.MIN_VALUE);
|
||||
var myMap = new HashMapIntLong();
|
||||
myMap.putAll(map);
|
||||
Assert.assertEquals(map, myMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intShortEqualsTest() {
|
||||
var map = Map.of(1, (short) 2, 3, (short) 4, 5, (short) 6, Integer.MAX_VALUE, Short.MIN_VALUE);
|
||||
var myMap = new HashMapIntShort();
|
||||
myMap.putAll(map);
|
||||
Assert.assertEquals(map, myMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longIntEqualsTest() {
|
||||
var map = Map.of(1L, 2, 3L, 4, 5L, 6, Long.MAX_VALUE, Integer.MIN_VALUE);
|
||||
var myMap = new HashMapLongInt();
|
||||
myMap.putAll(map);
|
||||
Assert.assertEquals(map, myMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longLongEqualsTest() {
|
||||
var map = Map.of(1L, 2L, 3L, 4L, 5L, 6L, Long.MAX_VALUE, Long.MIN_VALUE);
|
||||
var myMap = new HashMapLongLong();
|
||||
myMap.putAll(map);
|
||||
Assert.assertEquals(map, myMap);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user