1 17 package org.apache.ldap.server.db; 18 19 20 import org.apache.ldap.common.util.BigIntegerComparator; 21 import org.apache.ldap.server.schema.SerializableComparator; 22 23 24 30 public class IndexComparator implements TupleComparator 31 { 32 private static final long serialVersionUID = 3257283621751633459L; 33 34 private static final SerializableComparator BIG_INTEGER_COMPARATOR = 35 new SerializableComparator( "1.2.6.1.4.1.18060.1.1.1.2.2" ) 36 { 37 private static final long serialVersionUID = 3690478030414165816L; 38 39 public int compare( Object o1, Object o2 ) 40 { 41 return BigIntegerComparator.INSTANCE.compare( o1, o2 ); 42 } 43 }; 44 45 private final boolean isForwardMap; 46 47 private final SerializableComparator keyComp; 48 49 50 57 public IndexComparator( SerializableComparator keyComp, boolean isForwardMap ) 58 { 59 this.keyComp = keyComp; 60 this.isForwardMap = isForwardMap; 61 } 62 63 64 70 public SerializableComparator getKeyComparator() 71 { 72 if ( isForwardMap ) 73 { 74 return keyComp; 75 } 76 77 return BIG_INTEGER_COMPARATOR; 78 } 79 80 81 87 public SerializableComparator getValueComparator() 88 { 89 if ( isForwardMap ) 90 { 91 return BIG_INTEGER_COMPARATOR; 92 } 93 94 return keyComp; 95 } 96 97 98 108 public int compareKey( Object key1, Object key2 ) 109 { 110 return getKeyComparator().compare( key1, key2 ); 111 } 112 113 114 124 public int compareValue( Object value1, Object value2 ) 125 { 126 return getValueComparator().compare( value1, value2 ); 127 } 128 } 129 | Popular Tags |