aa6c7d980216234f442e48772c2e7a89bc3af36c
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / TNode.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
20 final class TNode<K, V> extends MainNode<K, V> implements EntryNode<K, V> {
21     final K key;
22     final V value;
23     final int hc;
24
25     TNode(final K key, final V value, final int hc) {
26         this.key = key;
27         this.value = value;
28         this.hc = hc;
29     }
30
31     TNode<K, V> copy() {
32         return new TNode<>(key, value, hc);
33     }
34
35     TNode<K, V> copyTombed() {
36         return new TNode<>(key, value, hc);
37     }
38
39     SNode<K, V> copyUntombed() {
40         return new SNode<>(key, value, hc);
41     }
42
43     @Override
44     int trySize() {
45         return 1;
46     }
47
48     @Override
49     int size(final ImmutableTrieMap<?, ?> ct) {
50         return 1;
51     }
52
53     @Override
54     public K getKey() {
55         return key;
56     }
57
58     @Override
59     public V getValue() {
60         return value;
61     }
62
63     @Override
64     public int hashCode() {
65         return EntryUtil.hash(key, value);
66     }
67
68     @SuppressFBWarnings(value = "EQ_UNUSUAL",  justification = "Equality handled by utility methods")
69     @Override
70     public boolean equals(final Object obj) {
71         return EntryUtil.equal(obj, key, value);
72     }
73
74     @Override
75     public String toString() {
76         return EntryUtil.string(key, value);
77     }
78 }