A sensible, albeit inefficient, definition of #remove in terms of the iterator method of #entrySet. If you override #entrySet, you may wish to override #remove to forward to this implementation. Alternately, you may wish to override #remove with {@
(@Nullable Object key)
| 168 | */ |
| 169 | |
| 170 | @Beta |
| 171 | protected V standardRemove(@Nullable Object key) { |
| 172 | Iterator<Entry<K, V>> entryIterator = entrySet().iterator(); |
| 173 | while (entryIterator.hasNext()) { |
| 174 | Entry<K, V> entry = entryIterator.next(); |
| 175 | if (Objects.equal(entry.getKey(), key)) { |
| 176 | V value = entry.getValue(); |
| 177 | entryIterator.remove(); |
| 178 | return value; |
| 179 | } |
| 180 | } |
| 181 | return null; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * A sensible definition of {@link #clear} in terms of the {@code iterator} |