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.api.ldap.model.schema.comparators; 21 22 23 import java.util.UUID; 24 25 import org.slf4j.Logger; 26 import org.slf4j.LoggerFactory; 27 28 29 /** 30 * A comparator for UUID. We simply use the UUID compareTo method. 31 * 32 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 33 */ 34 public class UuidComparator extends SerializableComparator<String> 35 { 36 /** The serial version UID */ 37 private static final long serialVersionUID = 2L; 38 39 /** A logger for this class */ 40 private static final Logger LOG = LoggerFactory.getLogger( UuidComparator.class ); 41 private static final boolean IS_DEBUG = LOG.isDebugEnabled(); 42 43 public static UuidComparator INSTANCE = new UuidComparator( "1.3.6.1.1.16.4" ); 44 45 46 /** 47 * The UUIDComparator constructor. Its OID is the UUIDMatch matching 48 * rule OID. 49 */ 50 public UuidComparator( String oid ) 51 { 52 super( oid ); 53 } 54 55 56 /** 57 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 58 */ 59 public int compare( String uuid1, String uuid2 ) 60 { 61 if ( IS_DEBUG ) 62 { 63 LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 ); 64 } 65 66 // ------------------------------------------------------------------- 67 // Handle some basis cases 68 // ------------------------------------------------------------------- 69 if ( uuid1 == null ) 70 { 71 return ( uuid2 == null ) ? 0 : -1; 72 } 73 74 if ( uuid2 == null ) 75 { 76 return 1; 77 } 78 79 return uuid1.compareTo( uuid2 ); 80 } 81 82 83 /** 84 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 85 */ 86 public int compare( UUID uuid1, UUID uuid2 ) 87 { 88 if ( IS_DEBUG ) 89 { 90 LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 ); 91 } 92 93 // ------------------------------------------------------------------- 94 // Handle some basis cases 95 // ------------------------------------------------------------------- 96 if ( uuid1 == null ) 97 { 98 return ( uuid2 == null ) ? 0 : -1; 99 } 100 101 if ( uuid2 == null ) 102 { 103 return 1; 104 } 105 106 return uuid1.compareTo( uuid2 ); 107 } 108 }