e845816c776f2dd28da7c0cd00c5548b61f41d4a
[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 final class TNode<K, V> extends MainNode<K, V> implements EntryNode<K, V> {
19     final K k;
20     final V v;
21     final int hc;
22
23     TNode (final K k, final V v, final int hc) {
24         this.k = k;
25         this.v = v;
26         this.hc = hc;
27     }
28
29     TNode<K, V> copy () {
30         return new TNode<>(k, v, hc);
31     }
32
33     TNode<K, V> copyTombed () {
34         return new TNode<>(k, v, hc);
35     }
36
37     SNode<K, V> copyUntombed () {
38         return new SNode<>(k, v, hc);
39     }
40
41     @Override
42     int cachedSize(final TrieMap<?, ?> ct) {
43         return 1;
44     }
45
46     @Override
47     String string(final int lev) {
48         // ("  " * lev) + "TNode(%s, %s, %x, !)".format(k, v, hc);
49         return "TNode";
50     }
51
52     @Override
53     public K getKey() {
54         return k;
55     }
56
57     @Override
58     public V getValue() {
59         return v;
60     }
61
62     @Override
63     public int hashCode() {
64         return EntryUtil.hash(k, v);
65     }
66
67     @Override
68     public boolean equals(final Object o) {
69         return EntryUtil.equal(o, k, v);
70     }
71
72     @Override
73     public String toString() {
74         return EntryUtil.string(k, v);
75     }
76 }