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 java.util.Objects.requireNonNull;
20 import java.util.AbstractSet;
21 import java.util.Map.Entry;
22 import java.util.Spliterator;
23 import java.util.Spliterators;
26 * Abstract base class for implementing {@link TrieMap} entry sets.
28 * @author Robert Varga
30 * @param <K> the type of entry keys
31 * @param <V> the type of entry values
33 abstract class AbstractEntrySet<K, V> extends AbstractSet<Entry<K, V>> {
34 private final TrieMap<K, V> map;
36 AbstractEntrySet(final TrieMap<K, V> map) {
37 this.map = requireNonNull(map);
40 final TrieMap<K, V> map() {
45 @SuppressWarnings("checkstyle:parameterName")
46 public final boolean contains(final Object o) {
47 if (!(o instanceof Entry)) {
51 final Entry<?, ?> e = (Entry<?, ?>) o;
52 final Object key = e.getKey();
57 final V v = map.get(key);
58 return v != null && v.equals(e.getValue());
62 public final int size() {
67 public final Spliterator<Entry<K, V>> spliterator() {
68 // TODO: this is backed by an Iterator, we should be able to do better
69 return Spliterators.spliterator(map.immutableIterator(), Long.MAX_VALUE, characteristics());
72 abstract int characteristics();