86afdfa15b451b7c7f9c94f8655a9fe04aca0223
[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 cachedSize(final TrieMap<?, ?> ct) {
45         return 1;
46     }
47
48     @Override
49     String string(final int lev) {
50         // ("  " * lev) + "TNode(%s, %s, %x, !)".format(k, v, hc);
51         return "TNode";
52     }
53
54     @Override
55     public K getKey() {
56         return k;
57     }
58
59     @Override
60     public V getValue() {
61         return v;
62     }
63
64     @Override
65     public int hashCode() {
66         return EntryUtil.hash(k, v);
67     }
68
69     @SuppressFBWarnings(value = "EQ_UNUSUAL",  justification = "Equality handled by utility methods")
70     @Override
71     public boolean equals(final Object o) {
72         return EntryUtil.equal(o, k, v);
73     }
74
75     @Override
76     public String toString() {
77         return EntryUtil.string(k, v);
78     }
79 }