9cdfb974d0b0644a3c7e3be619347a473c6ded57
[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 k;
22     final V v;
23     final int hc;
24
25     TNode (final K k, final V v, final int hc) {
26         this.k = k;
27         this.v = v;
28         this.hc = hc;
29     }
30
31     TNode<K, V> copy () {
32         return new TNode<>(k, v, hc);
33     }
34
35     TNode<K, V> copyTombed () {
36         return new TNode<>(k, v, hc);
37     }
38
39     SNode<K, V> copyUntombed () {
40         return new SNode<>(k, v, 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     String string(final int lev) {
55         // ("  " * lev) + "TNode(%s, %s, %x, !)".format(k, v, hc);
56         return "TNode";
57     }
58
59     @Override
60     public K getKey() {
61         return k;
62     }
63
64     @Override
65     public V getValue() {
66         return v;
67     }
68
69     @Override
70     public int hashCode() {
71         return EntryUtil.hash(k, v);
72     }
73
74     @SuppressFBWarnings(value = "EQ_UNUSUAL",  justification = "Equality handled by utility methods")
75     @Override
76     public boolean equals(final Object o) {
77         return EntryUtil.equal(o, k, v);
78     }
79
80     @Override
81     public String toString() {
82         return EntryUtil.string(k, v);
83     }
84 }