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