001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License.
018     *
019     */
020    package org.apache.directory.server.core.partition.impl.btree.jdbm;
021    
022    
023    import org.apache.directory.server.core.avltree.ArrayTree;
024    import org.apache.directory.server.i18n.I18n;
025    
026    
027    /**
028     * A wrapper around duplicate key values.  This class wraps either an AvlTree
029     * or a BTreeRedirect.  The AvlTree and BTreeRedirect forms are used for the
030     * two value persistence mechanisms used to implement duplicate keys over JDBM
031     * btrees.  
032     *
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev$
035     */
036    public class DupsContainer<V>
037    {
038        private final ArrayTree<V> arrayTree;
039        private final BTreeRedirect btreeRedirect;
040    
041    
042        DupsContainer( ArrayTree<V> arrayTree )
043        {
044            this.arrayTree = arrayTree;
045            btreeRedirect = null;
046        }
047    
048    
049        DupsContainer( BTreeRedirect btreeRedirect )
050        {
051            arrayTree = null;
052            this.btreeRedirect = btreeRedirect;
053        }
054    
055    
056        final boolean isBTreeRedirect()
057        {
058            return btreeRedirect != null;
059        }
060    
061    
062        final boolean isArrayTree()
063        {
064            return arrayTree != null;
065        }
066    
067    
068        final ArrayTree<V> getArrayTree()
069        {
070            if ( arrayTree == null )
071            {
072                throw new IllegalStateException( I18n.err( I18n.ERR_570 ) );
073            }
074    
075            return arrayTree;
076        }
077    
078    
079        final BTreeRedirect getBTreeRedirect()
080        {
081            if ( btreeRedirect == null )
082            {
083                throw new IllegalStateException( I18n.err( I18n.ERR_571 ) );
084            }
085    
086            return btreeRedirect;
087        }
088    }