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;
22 import java.util.Spliterator;
25 * Support for EntrySet operations required by the Map interface.
27 * @param <K> the type of keys
28 * @param <V> the type of values
30 final class MutableEntrySet<K, V> extends AbstractEntrySet<K, V> {
31 MutableEntrySet(final TrieMap<K, V> map) {
36 @SuppressWarnings("checkstyle:parameterName")
37 public boolean add(final Entry<K, V> e) {
38 final K k = e.getKey();
39 checkArgument(k != null);
40 final V v = e.getValue();
41 checkArgument(v != null);
43 final V prev = map().putIfAbsent(k, v);
44 return prev == null || !v.equals(prev);
53 public Iterator<Entry<K, V>> iterator() {
54 return map().iterator();
58 @SuppressWarnings("checkstyle:parameterName")
59 public boolean remove(final Object o) {
60 if (!(o instanceof Entry)) {
64 final Entry<?, ?> e = (Entry<?, ?>) o;
65 final Object key = e.getKey();
69 final Object value = e.getValue();
74 return map().remove(key, value);
78 int characteristics() {
79 return Spliterator.DISTINCT | Spliterator.CONCURRENT | Spliterator.NONNULL;