Fix/suppress checkstyle warnings
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / AbstractEntrySet.java
1 /*
2  * (C) Copyright 2017 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 com.google.common.base.Preconditions.checkNotNull;
19
20 import java.util.AbstractSet;
21 import java.util.Map.Entry;
22
23 /**
24  * Abstract base class for implementing {@link TrieMap} entry sets.
25  *
26  * @author Robert Varga
27  *
28  * @param <K> the type of entry keys
29  * @param <V> the type of entry values
30  */
31 abstract class AbstractEntrySet<K, V> extends AbstractSet<Entry<K, V>> {
32     private final TrieMap<K, V> map;
33
34     AbstractEntrySet(final TrieMap<K, V> map) {
35         this.map = checkNotNull(map);
36     }
37
38     final TrieMap<K, V> map() {
39         return map;
40     }
41
42     @Override
43     @SuppressWarnings("checkstyle:parameterName")
44     public final boolean contains(final Object o) {
45         if (!(o instanceof Entry)) {
46             return false;
47         }
48
49         final Entry<?, ?> e = (Entry<?, ?>) o;
50         final Object key = e.getKey();
51         if (key == null) {
52             return false;
53         }
54
55         final V v = map.get(key);
56         return v != null && v.equals(e.getValue());
57     }
58
59     @Override
60     public final int size() {
61         return map.size();
62     }
63 }