Use Objects.requireNonNull instead of Preconditions.checkNotNull
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / AbstractKeySet.java
1 /*
2  * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.opendaylight.yangtools.triemap;
17
18 import static java.util.Objects.requireNonNull;
19
20 import java.util.AbstractSet;
21 import java.util.Collection;
22
23 /**
24  * Abstract base class for key set views of a TrieMap.
25  *
26  * @author Robert Varga
27  *
28  * @param <K> the type of keys
29  */
30 abstract class AbstractKeySet<K> extends AbstractSet<K> {
31     private final TrieMap<K, ?> map;
32
33     AbstractKeySet(final TrieMap<K, ?> map) {
34         this.map = requireNonNull(map);
35     }
36
37     final TrieMap<K, ?> map() {
38         return map;
39     }
40
41     @Override
42     @SuppressWarnings("checkstyle:parameterName")
43     public final boolean add(final K e) {
44         throw new UnsupportedOperationException();
45     }
46
47     @Override
48     @SuppressWarnings("checkstyle:parameterName")
49     public final boolean addAll(final Collection<? extends K> c) {
50         throw new UnsupportedOperationException();
51     }
52
53     @Override
54     @SuppressWarnings("checkstyle:parameterName")
55     public final boolean contains(final Object o) {
56         return map.containsKey(o);
57     }
58
59     @Override
60     public final boolean isEmpty() {
61         return map.isEmpty();
62     }
63
64     @Override
65     public final int size() {
66         return map.size();
67     }
68 }