930 |
930 |
931 @Override |
931 @Override |
932 public synchronized void forEach(BiConsumer<? super K, ? super V> action) { |
932 public synchronized void forEach(BiConsumer<? super K, ? super V> action) { |
933 Objects.requireNonNull(action); // explicit check required in case |
933 Objects.requireNonNull(action); // explicit check required in case |
934 // table is empty. |
934 // table is empty. |
935 Entry<?,?>[] tab = table; |
935 final int expectedModCount = modCount; |
936 for (Entry<?,?> entry : tab) { |
936 |
|
937 Entry<?, ?>[] tab = table; |
|
938 for (Entry<?, ?> entry : tab) { |
937 while (entry != null) { |
939 while (entry != null) { |
938 action.accept((K)entry.key, (V)entry.value); |
940 action.accept((K)entry.key, (V)entry.value); |
939 entry = entry.next; |
941 entry = entry.next; |
|
942 |
|
943 if (expectedModCount != modCount) { |
|
944 throw new ConcurrentModificationException(); |
|
945 } |
940 } |
946 } |
941 } |
947 } |
942 } |
948 } |
943 |
949 |
944 @Override |
950 @Override |
945 public synchronized void replaceAll( |
951 public synchronized void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { |
946 BiFunction<? super K, ? super V, ? extends V> function) { |
952 Objects.requireNonNull(function); // explicit check required in case |
947 Map.super.replaceAll(function); |
953 // table is empty. |
|
954 final int expectedModCount = modCount; |
|
955 |
|
956 Entry<K, V>[] tab = (Entry<K, V>[])table; |
|
957 for (Entry<K, V> entry : tab) { |
|
958 while (entry != null) { |
|
959 entry.value = Objects.requireNonNull( |
|
960 function.apply(entry.key, entry.value)); |
|
961 entry = entry.next; |
|
962 |
|
963 if (expectedModCount != modCount) { |
|
964 throw new ConcurrentModificationException(); |
|
965 } |
|
966 } |
|
967 } |
948 } |
968 } |
949 |
969 |
950 @Override |
970 @Override |
951 public synchronized V putIfAbsent(K key, V value) { |
971 public synchronized V putIfAbsent(K key, V value) { |
952 Objects.requireNonNull(value); |
972 Objects.requireNonNull(value); |
1056 |
1076 |
1057 return newValue; |
1077 return newValue; |
1058 } |
1078 } |
1059 |
1079 |
1060 @Override |
1080 @Override |
1061 public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
1081 public synchronized V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
1062 Objects.requireNonNull(remappingFunction); |
1082 Objects.requireNonNull(remappingFunction); |
1063 |
1083 |
1064 Entry<?,?> tab[] = table; |
1084 Entry<?,?> tab[] = table; |
1065 int hash = hash(key); |
1085 int hash = hash(key); |
1066 int index = (hash & 0x7FFFFFFF) % tab.length; |
1086 int index = (hash & 0x7FFFFFFF) % tab.length; |
1085 } |
1105 } |
1086 return null; |
1106 return null; |
1087 } |
1107 } |
1088 |
1108 |
1089 @Override |
1109 @Override |
1090 public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
1110 public synchronized V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
1091 Objects.requireNonNull(remappingFunction); |
1111 Objects.requireNonNull(remappingFunction); |
1092 |
1112 |
1093 Entry<?,?> tab[] = table; |
1113 Entry<?,?> tab[] = table; |
1094 int hash = hash(key); |
1114 int hash = hash(key); |
1095 int index = (hash & 0x7FFFFFFF) % tab.length; |
1115 int index = (hash & 0x7FFFFFFF) % tab.length; |
1120 |
1140 |
1121 return newValue; |
1141 return newValue; |
1122 } |
1142 } |
1123 |
1143 |
1124 @Override |
1144 @Override |
1125 public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { |
1145 public synchronized V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { |
1126 Objects.requireNonNull(remappingFunction); |
1146 Objects.requireNonNull(remappingFunction); |
1127 |
1147 |
1128 Entry<?,?> tab[] = table; |
1148 Entry<?,?> tab[] = table; |
1129 int hash = hash(key); |
1149 int hash = hash(key); |
1130 int index = (hash & 0x7FFFFFFF) % tab.length; |
1150 int index = (hash & 0x7FFFFFFF) % tab.length; |