View Javadoc
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;
22  
23  
24  /**
25   * A class to store informations on a level. We have to keep :
26   * <ul>
27   * <li>The number of elements to store in this level</li>
28   * <li>A flag that tells if it's a leaf or a node level</li>
29   * <li>The number of pages necessary to store all the elements in a level</li>
30   * <li>The number of elements we can store in a complete page (we may have one or two 
31   * incomplete pages at the end)</li>
32   * <li>A flag that tells if we have some incomplete page at the end</li>
33   * </ul>
34   *
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   */
37  public class LevelInfo<K, V>
38  {
39      /** The level number */
40      private int levelNumber;
41  
42      /** Nb of elements for this level */
43      private int nbElems;
44  
45      /** The number of pages in this level */
46      private int nbPages;
47  
48      /** Nb of elements before we reach an incomplete page */
49      private int nbElemsLimit;
50  
51      /** A flag that tells if the level contains nodes or leaves */
52      private boolean isNode;
53  
54      /** The current page which contains the data until we move it to the resulting BTree */
55      private Page<K, V> currentPage;
56  
57      /** The current position in the currentPage */
58      private int currentPos;
59  
60      /** The number of already added elements for this level */
61      private int nbAddedElems;
62  
63  
64      /**
65       * @return the levelNumber
66       */
67      public int getLevelNumber()
68      {
69          return levelNumber;
70      }
71  
72  
73      /**
74       * @param levelNumber the levelNumber to set
75       */
76      public void setLevelNumber( int levelNumber )
77      {
78          this.levelNumber = levelNumber;
79      }
80  
81  
82      /**
83       * @return the nbElems
84       */
85      public int getNbElems()
86      {
87          return nbElems;
88      }
89  
90  
91      /**
92       * @param nbElems the nbElems to set
93       */
94      public void setNbElems( int nbElems )
95      {
96          this.nbElems = nbElems;
97      }
98  
99  
100     /**
101      * @return the nbPages
102      */
103     public int getNbPages()
104     {
105         return nbPages;
106     }
107 
108 
109     /**
110      * @param nbPages the nbPages to set
111      */
112     public void setNbPages( int nbPages )
113     {
114         this.nbPages = nbPages;
115     }
116 
117 
118     /**
119      * Increment the number of pages
120      */
121     public void incNbPages()
122     {
123         this.nbPages++;
124     }
125 
126 
127     /**
128      * @return the nbElemsLimit
129      */
130     public int getNbElemsLimit()
131     {
132         return nbElemsLimit;
133     }
134 
135 
136     /**
137      * @param nbElemsLimit the nbElemsLimit to set
138      */
139     public void setNbElemsLimit( int nbElemsLimit )
140     {
141         this.nbElemsLimit = nbElemsLimit;
142     }
143 
144 
145     /**
146      * @return the isNode
147      */
148     public boolean isNode()
149     {
150         return isNode;
151     }
152 
153 
154     /**
155      * @param isNode the isNode to set
156      */
157     public void setType( boolean isNode )
158     {
159         this.isNode = isNode;
160     }
161 
162 
163     /**
164      * @return the currentPage
165      */
166     public Page<K, V> getCurrentPage()
167     {
168         return currentPage;
169     }
170 
171 
172     /**
173      * @param currentPage the currentPage to set
174      */
175     public void setCurrentPage( Page<K, V> currentPage )
176     {
177         this.currentPage = currentPage;
178     }
179 
180 
181     /**
182      * @return the currentPos
183      */
184     public int getCurrentPos()
185     {
186         return currentPos;
187     }
188 
189 
190     /**
191      * @param currentPos the currentPos to set
192      */
193     public void setCurrentPos( int currentPos )
194     {
195         this.currentPos = currentPos;
196     }
197 
198 
199     /**
200      * Increment the current position
201      */
202     public void incCurrentPos()
203     {
204         this.currentPos++;
205     }
206 
207 
208     /**
209      * @return the nbAddedElems
210      */
211     public int getNbAddedElems()
212     {
213         return nbAddedElems;
214     }
215 
216 
217     /**
218      * @param nbAddedElems the nbAddedElems to set
219      */
220     public void setNbAddedElems( int nbAddedElems )
221     {
222         this.nbAddedElems = nbAddedElems;
223     }
224 
225 
226     /**
227      * Increment the number of added elements
228      */
229     public void incNbAddedElems()
230     {
231         this.nbAddedElems++;
232     }
233 
234 
235     /** @see Object#toString() */
236     public String toString()
237     {
238         StringBuilder sb = new StringBuilder();
239 
240         if ( isNode )
241         {
242             sb.append( "NodeLevel[" );
243             sb.append( levelNumber );
244             sb.append( "] :" );
245         }
246         else
247         {
248             sb.append( "LeafLevel:" );
249         }
250 
251         sb.append( "\n    nbElems           = " ).append( nbElems );
252         sb.append( "\n    nbPages           = " ).append( nbPages );
253         sb.append( "\n    nbElemsLimit      = " ).append( nbElemsLimit );
254         sb.append( "\n    nbAddedElems      = " ).append( nbAddedElems );
255         sb.append( "\n    currentPos        = " ).append( currentPos );
256         sb.append( "\n    currentPage" );
257         sb.append( "\n        nbKeys : " ).append( currentPage.getNbElems() );
258 
259         return sb.toString();
260     }
261 }