586 |
|
* map is created with a capacity of twice the number of mappings in |
587 |
|
* the given map or 11 (whichever is greater), and a default load factor. |
588 |
|
*/ |
589 |
< |
public <A extends K, B extends V> ConcurrentHashMap(Map<A,B> t) { |
589 |
> |
public ConcurrentHashMap(Map<? extends K, ? extends V> t) { |
590 |
|
this(Math.max((int) (t.size() / DEFAULT_LOAD_FACTOR) + 1, |
591 |
|
11), |
592 |
|
DEFAULT_LOAD_FACTOR, DEFAULT_SEGMENTS); |
1123 |
|
public boolean equals(Object o) { |
1124 |
|
if (!(o instanceof Map.Entry)) |
1125 |
|
return false; |
1126 |
< |
Map.Entry e = (Map.Entry)o; |
1127 |
< |
return eq(getKey(), e.getKey()) && eq(getValue(), e.getValue()); |
1128 |
< |
} |
1126 |
> |
Map.Entry e = (Map.Entry)o; |
1127 |
> |
return eq(getKey(), e.getKey()) && eq(getValue(), e.getValue()); |
1128 |
> |
} |
1129 |
|
|
1130 |
|
public int hashCode() { |
1131 |
|
Object k = getKey(); |
1226 |
|
* is made accessible. |
1227 |
|
*/ |
1228 |
|
static class SimpleEntry<K,V> implements Entry<K,V> { |
1229 |
< |
K key; |
1230 |
< |
V value; |
1229 |
> |
K key; |
1230 |
> |
V value; |
1231 |
|
|
1232 |
< |
public SimpleEntry(K key, V value) { |
1233 |
< |
this.key = key; |
1232 |
> |
public SimpleEntry(K key, V value) { |
1233 |
> |
this.key = key; |
1234 |
|
this.value = value; |
1235 |
< |
} |
1235 |
> |
} |
1236 |
|
|
1237 |
< |
public SimpleEntry(Entry<K,V> e) { |
1238 |
< |
this.key = e.getKey(); |
1237 |
> |
public SimpleEntry(Entry<K,V> e) { |
1238 |
> |
this.key = e.getKey(); |
1239 |
|
this.value = e.getValue(); |
1240 |
< |
} |
1240 |
> |
} |
1241 |
> |
|
1242 |
> |
public K getKey() { |
1243 |
> |
return key; |
1244 |
> |
} |
1245 |
|
|
1246 |
< |
public K getKey() { |
1247 |
< |
return key; |
1248 |
< |
} |
1249 |
< |
|
1250 |
< |
public V getValue() { |
1251 |
< |
return value; |
1252 |
< |
} |
1253 |
< |
|
1254 |
< |
public V setValue(V value) { |
1255 |
< |
V oldValue = this.value; |
1256 |
< |
this.value = value; |
1257 |
< |
return oldValue; |
1258 |
< |
} |
1259 |
< |
|
1260 |
< |
public boolean equals(Object o) { |
1261 |
< |
if (!(o instanceof Map.Entry)) |
1262 |
< |
return false; |
1263 |
< |
Map.Entry e = (Map.Entry)o; |
1264 |
< |
return eq(key, e.getKey()) && eq(value, e.getValue()); |
1265 |
< |
} |
1266 |
< |
|
1267 |
< |
public int hashCode() { |
1268 |
< |
return ((key == null) ? 0 : key.hashCode()) ^ |
1269 |
< |
((value == null) ? 0 : value.hashCode()); |
1270 |
< |
} |
1267 |
< |
|
1268 |
< |
public String toString() { |
1269 |
< |
return key + "=" + value; |
1270 |
< |
} |
1246 |
> |
public V getValue() { |
1247 |
> |
return value; |
1248 |
> |
} |
1249 |
> |
|
1250 |
> |
public V setValue(V value) { |
1251 |
> |
V oldValue = this.value; |
1252 |
> |
this.value = value; |
1253 |
> |
return oldValue; |
1254 |
> |
} |
1255 |
> |
|
1256 |
> |
public boolean equals(Object o) { |
1257 |
> |
if (!(o instanceof Map.Entry)) |
1258 |
> |
return false; |
1259 |
> |
Map.Entry e = (Map.Entry)o; |
1260 |
> |
return eq(key, e.getKey()) && eq(value, e.getValue()); |
1261 |
> |
} |
1262 |
> |
|
1263 |
> |
public int hashCode() { |
1264 |
> |
return ((key == null) ? 0 : key.hashCode()) ^ |
1265 |
> |
((value == null) ? 0 : value.hashCode()); |
1266 |
> |
} |
1267 |
> |
|
1268 |
> |
public String toString() { |
1269 |
> |
return key + "=" + value; |
1270 |
> |
} |
1271 |
|
|
1272 |
|
private static boolean eq(Object o1, Object o2) { |
1273 |
|
return (o1 == null ? o2 == null : o1.equals(o2)); |