6a72ccaae4fb10d0ab9c4cd91e077a4b135b91a1
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / LNodeEntry.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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19 import java.util.Map.Entry;
20
21 /**
22  * A single entry in {@link LNodeEntries}, implements {@link Entry} in order to prevent instantiation of objects for
23  * iteration.
24  *
25  * @author Robert Varga
26  *
27  * @param <K> the type of key
28  * @param <V> the type of value
29  */
30 abstract class LNodeEntry<K, V> implements Entry<K, V> {
31     private final K key;
32     private final V value;
33
34     LNodeEntry(final K key, final V value) {
35         this.key = key;
36         this.value = value;
37     }
38
39     @Override
40     public final K getKey() {
41         return key;
42     }
43
44     @Override
45     public final V getValue() {
46         return value;
47     }
48
49     @Override
50     public final V setValue(final V value) {
51         throw new UnsupportedOperationException();
52     }
53
54     @Override
55     public final int hashCode() {
56         return EntryUtil.hash(key, value);
57     }
58
59     @SuppressFBWarnings(value = "EQ_UNUSUAL",  justification = "Equality handled by utility methods")
60     @Override
61     public final boolean equals(final Object obj) {
62         return EntryUtil.equal(obj, key, value);
63     }
64
65     @Override
66     public final String toString() {
67         return EntryUtil.string(key, value);
68     }
69 }