34 |
|
return map; |
35 |
|
} |
36 |
|
|
37 |
+ |
/** Re-implement Integer.compare for old java versions */ |
38 |
+ |
static int compare(int x, int y) { return x < y ? -1 : x > y ? 1 : 0; } |
39 |
+ |
|
40 |
|
// classes for testing Comparable fallbacks |
41 |
|
static class BI implements Comparable<BI> { |
42 |
|
private final int value; |
43 |
|
BI(int value) { this.value = value; } |
44 |
|
public int compareTo(BI other) { |
45 |
< |
return Integer.compare(value, other.value); |
45 |
> |
return compare(value, other.value); |
46 |
|
} |
47 |
|
public boolean equals(Object x) { |
48 |
|
return (x instanceof BI) && ((BI)x).value == value; |
76 |
|
break; |
77 |
|
} |
78 |
|
if (r == 0) |
79 |
< |
r = Integer.compare(size(), other.size()); |
79 |
> |
r = compare(size(), other.size()); |
80 |
|
return r; |
81 |
|
} |
82 |
|
private static final long serialVersionUID = 0; |
87 |
|
* class are found. |
88 |
|
*/ |
89 |
|
public void testComparableFamily() { |
90 |
< |
ConcurrentHashMap<BI, Boolean> m = new ConcurrentHashMap<>(); |
90 |
> |
ConcurrentHashMap<BI, Boolean> m = |
91 |
> |
new ConcurrentHashMap<BI, Boolean>(); |
92 |
|
for (int i = 0; i < 1000; i++) { |
93 |
|
assertTrue(m.put(new CI(i), true) == null); |
94 |
|
} |
103 |
|
* on Comparable can be inserted and found. |
104 |
|
*/ |
105 |
|
public void testGenericComparable() { |
106 |
< |
ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<>(); |
106 |
> |
ConcurrentHashMap<Object, Boolean> m = |
107 |
> |
new ConcurrentHashMap<Object, Boolean>(); |
108 |
|
for (int i = 0; i < 1000; i++) { |
109 |
|
BI bi = new BI(i); |
110 |
|
BS bs = new BS(String.valueOf(i)); |
127 |
|
* inserted and found. |
128 |
|
*/ |
129 |
|
public void testGenericComparable2() { |
130 |
< |
ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<>(); |
130 |
> |
ConcurrentHashMap<Object, Boolean> m = |
131 |
> |
new ConcurrentHashMap<Object, Boolean>(); |
132 |
|
for (int i = 0; i < 1000; i++) { |
133 |
|
m.put(new ArrayList(Collections.singleton(new BI(i))), true); |
134 |
|
} |
657 |
|
Map x = map5(); |
658 |
|
Map y = serialClone(x); |
659 |
|
|
660 |
< |
assertTrue(x != y); |
660 |
> |
assertNotSame(x, y); |
661 |
|
assertEquals(x.size(), y.size()); |
662 |
|
assertEquals(x, y); |
663 |
|
assertEquals(y, x); |