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  package org.apache.directory.server.core.partition.impl.btree.jdbm;
21  
22  
23  import org.apache.directory.server.core.avltree.ArrayTree;
24  import org.apache.directory.server.i18n.I18n;
25  
26  
27  /**
28   * A wrapper around duplicate key values.  This class wraps either an AvlTree
29   * or a BTreeRedirect.  The AvlTree and BTreeRedirect forms are used for the
30   * two value persistence mechanisms used to implement duplicate keys over JDBM
31   * btrees.  
32   *
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class DupsContainer<V>
36  {
37      private final ArrayTree<V> arrayTree;
38      private final BTreeRedirect btreeRedirect;
39  
40  
41      DupsContainer( ArrayTree<V> arrayTree )
42      {
43          this.arrayTree = arrayTree;
44          btreeRedirect = null;
45      }
46  
47  
48      DupsContainer( BTreeRedirect btreeRedirect )
49      {
50          arrayTree = null;
51          this.btreeRedirect = btreeRedirect;
52      }
53  
54  
55      final boolean isBTreeRedirect()
56      {
57          return btreeRedirect != null;
58      }
59  
60  
61      final boolean isArrayTree()
62      {
63          return arrayTree != null;
64      }
65  
66  
67      final ArrayTree<V> getArrayTree()
68      {
69          if ( arrayTree == null )
70          {
71              throw new IllegalStateException( I18n.err( I18n.ERR_570 ) );
72          }
73  
74          return arrayTree;
75      }
76  
77  
78      final BTreeRedirect getBTreeRedirect()
79      {
80          if ( btreeRedirect == null )
81          {
82              throw new IllegalStateException( I18n.err( I18n.ERR_571 ) );
83          }
84  
85          return btreeRedirect;
86      }
87  }