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 */
020package org.apache.directory.server.core.partition.impl.btree.jdbm;
021
022
023import org.apache.directory.server.core.avltree.ArrayTree;
024import 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 */
035public class DupsContainer<V>
036{
037    private final ArrayTree<V> arrayTree;
038    private final BTreeRedirect btreeRedirect;
039
040
041    DupsContainer( ArrayTree<V> arrayTree )
042    {
043        this.arrayTree = arrayTree;
044        btreeRedirect = null;
045    }
046
047
048    DupsContainer( BTreeRedirect btreeRedirect )
049    {
050        arrayTree = null;
051        this.btreeRedirect = btreeRedirect;
052    }
053
054
055    final boolean isBTreeRedirect()
056    {
057        return btreeRedirect != null;
058    }
059
060
061    final boolean isArrayTree()
062    {
063        return arrayTree != null;
064    }
065
066
067    final ArrayTree<V> getArrayTree()
068    {
069        if ( arrayTree == null )
070        {
071            throw new IllegalStateException( I18n.err( I18n.ERR_570 ) );
072        }
073
074        return arrayTree;
075    }
076
077
078    final BTreeRedirect getBTreeRedirect()
079    {
080        if ( btreeRedirect == null )
081        {
082            throw new IllegalStateException( I18n.err( I18n.ERR_571 ) );
083        }
084
085        return btreeRedirect;
086    }
087}