2 * (C) Copyright 2017 Pantheon Technologies, s.r.o. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.opendaylight.yangtools.triemap;
18 import static com.google.common.base.Preconditions.checkArgument;
20 import java.util.Iterator;
21 import java.util.Map.Entry;
24 * Support for EntrySet operations required by the Map interface.
26 * @param <K> the type of keys
27 * @param <V> the type of values
29 final class MutableEntrySet<K, V> extends AbstractEntrySet<K, V> {
30 MutableEntrySet(final TrieMap<K, V> map) {
35 @SuppressWarnings("checkstyle:parameterName")
36 public boolean add(final Entry<K, V> e) {
37 final K k = e.getKey();
38 checkArgument(k != null);
39 final V v = e.getValue();
40 checkArgument(v != null);
42 final V prev = map().putIfAbsent(k, v);
43 return prev == null || !v.equals(prev);
52 public Iterator<Entry<K, V>> iterator() {
53 return map().iterator();
57 @SuppressWarnings("checkstyle:parameterName")
58 public boolean remove(final Object o) {
59 if (!(o instanceof Entry)) {
63 final Entry<?, ?> e = (Entry<?, ?>) o;
64 final Object key = e.getKey();
68 final Object value = e.getValue();
73 return map().remove(key, value);