50 |
|
* overestimates and underestimates within an order of magnitude do |
51 |
|
* not usually have much noticeable impact. |
52 |
|
* |
53 |
+ |
* <p>This class implements all of the <em>optional</em> methods |
54 |
+ |
* of the {@link Map} and {@link Iterator} interfaces. |
55 |
+ |
* |
56 |
|
* <p> Like {@link java.util.Hashtable} but unlike {@link |
57 |
|
* java.util.HashMap}, this class does NOT allow <tt>null</tt> to be |
58 |
|
* used as a key or value. |
544 |
|
|
545 |
|
/** |
546 |
|
* Constructs a new, empty map with a default initial capacity, |
547 |
< |
* load factor, and number of concurrencyLevel. |
547 |
> |
* load factor, and concurrencyLevel. |
548 |
|
*/ |
549 |
|
public ConcurrentHashMap() { |
550 |
|
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_SEGMENTS); |
598 |
|
public int size() { |
599 |
|
int[] mc = new int[segments.length]; |
600 |
|
for (;;) { |
601 |
< |
int sum = 0; |
601 |
> |
long sum = 0; |
602 |
|
int mcsum = 0; |
603 |
|
for (int i = 0; i < segments.length; ++i) { |
604 |
|
sum += segments[i].count; |
614 |
|
} |
615 |
|
} |
616 |
|
} |
617 |
< |
if (check == sum) |
618 |
< |
return sum; |
617 |
> |
if (check == sum) { |
618 |
> |
if (sum > Integer.MAX_VALUE) |
619 |
> |
return Integer.MAX_VALUE; |
620 |
> |
else |
621 |
> |
return (int)sum; |
622 |
> |
} |
623 |
|
} |
624 |
|
} |
625 |
|
|
633 |
|
* this table. |
634 |
|
* @throws NullPointerException if the key is |
635 |
|
* <tt>null</tt>. |
629 |
– |
* @see #put(Object, Object) |
636 |
|
*/ |
637 |
|
public V get(Object key) { |
638 |
|
int hash = hash(key); // throws NullPointerException if key null |
648 |
|
* <tt>equals</tt> method; <tt>false</tt> otherwise. |
649 |
|
* @throws NullPointerException if the key is |
650 |
|
* <tt>null</tt>. |
645 |
– |
* @see #contains(Object) |
651 |
|
*/ |
652 |
|
public boolean containsKey(Object key) { |
653 |
|
int hash = hash(key); // throws NullPointerException if key null |
696 |
|
|
697 |
|
/** |
698 |
|
* Legacy method testing if some key maps into the specified value |
699 |
< |
* in this table. This operation is more expensive than the |
700 |
< |
* <tt>containsKey</tt> method. |
696 |
< |
* |
697 |
< |
* <p> Note that this method is identical in functionality to |
698 |
< |
* <tt>containsValue</tt>, This method exists solely to ensure |
699 |
> |
* in this table. This method is identical in functionality to |
700 |
> |
* {@link #containsValue}, and exists solely to ensure |
701 |
|
* full compatibility with class {@link java.util.Hashtable}, |
702 |
|
* which supported this method prior to introduction of the |
703 |
< |
* collections framework. |
703 |
> |
* Java Collections framework. |
704 |
|
|
705 |
|
* @param value a value to search for. |
706 |
|
* @return <tt>true</tt> if and only if some key maps to the |
708 |
|
* determined by the <tt>equals</tt> method; |
709 |
|
* <tt>false</tt> otherwise. |
710 |
|
* @throws NullPointerException if the value is <tt>null</tt>. |
709 |
– |
* @see #containsKey(Object) |
710 |
– |
* @see #containsValue(Object) |
711 |
– |
* @see Map |
711 |
|
*/ |
712 |
|
public boolean contains(Object value) { |
713 |
|
return containsValue(value); |
727 |
|
* or <tt>null</tt> if it did not have one. |
728 |
|
* @throws NullPointerException if the key or value is |
729 |
|
* <tt>null</tt>. |
731 |
– |
* @see Object#equals(Object) |
732 |
– |
* @see #get(Object) |
730 |
|
*/ |
731 |
|
public V put(K key, V value) { |
732 |
|
if (value == null) |
779 |
|
* @param t Mappings to be stored in this map. |
780 |
|
*/ |
781 |
|
public void putAll(Map<? extends K, ? extends V> t) { |
782 |
< |
Iterator<Map.Entry<? extends K, ? extends V>> it = t.entrySet().iterator(); |
786 |
< |
while (it.hasNext()) { |
782 |
> |
for (Iterator<Map.Entry<? extends K, ? extends V>> it = (Iterator<Map.Entry<? extends K, ? extends V>>) t.entrySet().iterator(); it.hasNext(); ) { |
783 |
|
Entry<? extends K, ? extends V> e = it.next(); |
784 |
|
put(e.getKey(), e.getValue()); |
785 |
|
} |
913 |
|
*/ |
914 |
|
public Set<Map.Entry<K,V>> entrySet() { |
915 |
|
Set<Map.Entry<K,V>> es = entrySet; |
916 |
< |
return (es != null) ? es : (entrySet = new EntrySet()); |
916 |
> |
return (es != null) ? es : (entrySet = (Set<Map.Entry<K,V>>) (Set) new EntrySet()); |
917 |
|
} |
918 |
|
|
919 |
|
|
921 |
|
* Returns an enumeration of the keys in this table. |
922 |
|
* |
923 |
|
* @return an enumeration of the keys in this table. |
924 |
< |
* @see Enumeration |
929 |
< |
* @see #elements() |
930 |
< |
* @see #keySet() |
931 |
< |
* @see Map |
924 |
> |
* @see #keySet |
925 |
|
*/ |
926 |
|
public Enumeration<K> keys() { |
927 |
|
return new KeyIterator(); |
933 |
|
* sequentially. |
934 |
|
* |
935 |
|
* @return an enumeration of the values in this table. |
936 |
< |
* @see java.util.Enumeration |
944 |
< |
* @see #keys() |
945 |
< |
* @see #values() |
946 |
< |
* @see Map |
936 |
> |
* @see #values |
937 |
|
*/ |
938 |
|
public Enumeration<V> elements() { |
939 |
|
return new ValueIterator(); |