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; 21 22 23 import java.io.Serializable; 24 25 import org.apache.directory.server.schema.SerializableComparator; 26 27 28 /** 29 * A TupleComparator that compares keys only. 30 * 31 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 32 * @version $Rev: 610243 $ 33 */ 34 public class KeyOnlyComparator<K,V> implements TupleComparator<K,V>, Serializable 35 { 36 private static final long serialVersionUID = 3544956549803161397L; 37 38 private SerializableComparator<K> keyComparator; 39 40 41 public KeyOnlyComparator( SerializableComparator<K> comparator ) 42 { 43 keyComparator = comparator; 44 } 45 46 47 /** 48 * Gets the comparator used to compare keys. May be null in which 49 * case the compareKey method will throw an UnsupportedOperationException. 50 * 51 * @return the comparator for comparing keys. 52 */ 53 public SerializableComparator<K> getKeyComparator() 54 { 55 return keyComparator; 56 } 57 58 59 /** 60 * Will throw an UnsupportedOperationException every time. 61 */ 62 public SerializableComparator<V> getValueComparator() 63 { 64 throw new UnsupportedOperationException(); 65 } 66 67 68 /** 69 * Compares key Object to determine their sorting order returning a 70 * value = to, < or > than 0. 71 * 72 * @param key1 the first key to compare 73 * @param key2 the other key to compare to the first 74 * @return 0 if both are equal, a negative value less than 0 if the first 75 * is less than the second, or a postive value if the first is greater than 76 * the second byte array. 77 */ 78 public int compareKey( K key1, K key2 ) 79 { 80 return keyComparator.compare( key1, key2 ); 81 } 82 83 84 /** 85 * Comparse value Objects to determine their sorting order returning a 86 * value = to, < or > than 0. 87 * 88 * @param value1 the first value to compare 89 * @param value2 the other value to compare to the first 90 * @return 0 if both are equal, a negative value less than 0 if the first 91 * is less than the second, or a postive value if the first is greater than 92 * the second Object. 93 */ 94 public int compareValue( V value1, V value2 ) 95 { 96 throw new UnsupportedOperationException(); 97 } 98 }