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;
021
022
023import org.apache.directory.api.ldap.model.schema.comparators.SerializableComparator;
024
025
026/**
027 * A TupleComparator that compares keys only.
028 * 
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 */
031public class KeyOnlyComparator<K, V> implements TupleComparator<K, V>
032{
033    private static final long serialVersionUID = 3544956549803161397L;
034
035    private SerializableComparator<K> keyComparator;
036
037
038    public KeyOnlyComparator( SerializableComparator<K> comparator )
039    {
040        keyComparator = comparator;
041    }
042
043
044    /**
045     * Gets the comparator used to compare keys.  May be null in which
046     * case the compareKey method will throw an UnsupportedOperationException.
047     *
048     * @return the comparator for comparing keys.
049     */
050    public SerializableComparator<K> getKeyComparator()
051    {
052        return keyComparator;
053    }
054
055
056    /**
057     * Will throw an UnsupportedOperationException every time.
058     */
059    public SerializableComparator<V> getValueComparator()
060    {
061        throw new UnsupportedOperationException();
062    }
063
064
065    /**
066     * Compares key Object to determine their sorting order returning a
067     * value = to, &lt; or &gt; than 0.
068     *
069     * @param key1 the first key to compare
070     * @param key2 the other key to compare to the first
071     * @return 0 if both are equal, a negative value less than 0 if the first
072     * is less than the second, or a positive value if the first is greater than
073     * the second byte array.
074     */
075    public int compareKey( K key1, K key2 )
076    {
077        return keyComparator.compare( key1, key2 );
078    }
079
080
081    /**
082     * Comparse value Objects to determine their sorting order returning a
083     * value = to, &lt; or &gt; than 0.
084     *
085     * @param value1 the first value to compare
086     * @param value2 the other value to compare to the first
087     * @return 0 if both are equal, a negative value less than 0 if the first
088     * is less than the second, or a positive value if the first is greater than
089     * the second Object.
090     */
091    public int compareValue( V value1, V value2 )
092    {
093        throw new UnsupportedOperationException();
094    }
095}