BUG-7464: Fix MainNode.cachedSize()
[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 java.util.AbstractMap.SimpleImmutableEntry;
19 import java.util.Map.Entry;
20
21 final class TNode<K, V> extends MainNode<K, V> implements KVNode<K, V> {
22     final K k;
23     final V v;
24     final int hc;
25
26     TNode (final K k, final V v, final int hc) {
27         this.k = k;
28         this.v = v;
29         this.hc = hc;
30     }
31
32     TNode<K, V> copy () {
33         return new TNode<>(k, v, hc);
34     }
35
36     TNode<K, V> copyTombed () {
37         return new TNode<>(k, v, hc);
38     }
39
40     SNode<K, V> copyUntombed () {
41         return new SNode<>(k, v, hc);
42     }
43
44     @Override
45     public Entry<K, V> kvPair () {
46         return new SimpleImmutableEntry<>(k, v);
47     }
48
49     @Override
50     int cachedSize(final TrieMap<K, V> ct) {
51         return 1;
52     }
53
54     @Override
55     String string(final int lev) {
56         // ("  " * lev) + "TNode(%s, %s, %x, !)".format(k, v, hc);
57         return "TNode";
58     }
59 }