1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20
21 package org.apache.directory.mavibot.btree.managed;
22
23
24 import java.io.IOException;
25
26
27 /**
28 * A class containing utility methods to be used internally.
29 *
30 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31 */
32 @SuppressWarnings("all")
33 /* No qualifier */class InternalUtil
34 {
35
36 /**
37 * Sets the multi-value container(a.k.a dupsContainer) of the key at the given position.
38 *
39 * This method will not update the existing value of 'dupsPos'. To change this value
40 * use {@link #changeNextDupsContainer(ParentPos, BTree)} or {@link #changePrevDupsContainer(ParentPos, BTree)}
41 *
42 * @param parentPos the parent position object
43 * @param btree the BTree
44 */
45 public static void setDupsContainer( ParentPos parentPos, BTree btree )
46 {
47 if ( !btree.isAllowDuplicates() )
48 {
49 return;
50 }
51
52 if ( parentPos.dupsContainer == null )
53 {
54 Leaf leaf = ( Leaf ) ( parentPos.page );
55 ValueHolder valueHolder = leaf.values[parentPos.pos];
56
57 }
58 }
59
60
61 /**
62 * Sets the multi-value container(a.k.a dupsContainer) of the key at the given position
63 * and resets the 'dupsPos' to zero. This is mostly used by Cursor while navigating using
64 * next()
65 *
66 * @param parentPos the parent position object
67 * @param btree the BTree
68 */
69 public static void changeNextDupsContainer( ParentPos parentPos, BTree btree ) throws IOException
70 {
71 if ( !btree.isAllowDuplicates() )
72 {
73 return;
74 }
75
76 if ( parentPos.pos < parentPos.page.getNbElems() )
77 {
78 Leaf leaf = ( Leaf ) ( parentPos.page );
79 ValueHolder valueHolder = leaf.values[parentPos.pos];
80 }
81 }
82
83
84 /**
85 * Sets the multi-value container(a.k.a dupsContainer) of the key at the index below the given position( i.e pos - 1)
86 * and resets the 'dupsPos' to the number of elements present in the multi-value container.
87 * This is used by Cursor while navigating using prev()
88 *
89 * @param parentPos the parent position object
90 * @param btree the BTree
91 */
92 public static void changePrevDupsContainer( ParentPos parentPos, BTree btree ) throws IOException
93 {
94 if ( !btree.isAllowDuplicates() )
95 {
96 return;
97 }
98
99 int index = parentPos.pos - 1;
100
101 if ( index >= 0 )
102 {
103 Leaf leaf = ( Leaf ) ( parentPos.page );
104 ValueHolder valueHolder = leaf.values[index];
105 }
106 }
107
108
109 /**
110 * Same as @see #changePrevDupsContainer(ParentPos, BTree) but with a different name
111 * to make it sound semantically right when used inside {@link BTreeFactory#getPathToRightMostLeaf(BTree)}
112 */
113 public static void setLastDupsContainer( ParentPos parentPos, BTree btree ) throws IOException
114 {
115 changePrevDupsContainer( parentPos, btree );
116 }
117 }