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.api.ldap.model.schema.comparators; 021 022 023import java.util.UUID; 024 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028 029/** 030 * A comparator for UUID. We simply use the UUID compareTo method. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 */ 034public class UuidComparator extends SerializableComparator<String> 035{ 036 /** The serial version UID */ 037 private static final long serialVersionUID = 2L; 038 039 /** A logger for this class */ 040 private static final Logger LOG = LoggerFactory.getLogger( UuidComparator.class ); 041 private static final boolean IS_DEBUG = LOG.isDebugEnabled(); 042 043 public static UuidComparator INSTANCE = new UuidComparator( "1.3.6.1.1.16.4" ); 044 045 046 /** 047 * The UUIDComparator constructor. Its OID is the UUIDMatch matching 048 * rule OID. 049 */ 050 public UuidComparator( String oid ) 051 { 052 super( oid ); 053 } 054 055 056 /** 057 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 058 */ 059 public int compare( String uuid1, String uuid2 ) 060 { 061 if ( IS_DEBUG ) 062 { 063 LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 ); 064 } 065 066 // ------------------------------------------------------------------- 067 // Handle some basis cases 068 // ------------------------------------------------------------------- 069 if ( uuid1 == null ) 070 { 071 return ( uuid2 == null ) ? 0 : -1; 072 } 073 074 if ( uuid2 == null ) 075 { 076 return 1; 077 } 078 079 return uuid1.compareTo( uuid2 ); 080 } 081 082 083 /** 084 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 085 */ 086 public int compare( UUID uuid1, UUID uuid2 ) 087 { 088 if ( IS_DEBUG ) 089 { 090 LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 ); 091 } 092 093 // ------------------------------------------------------------------- 094 // Handle some basis cases 095 // ------------------------------------------------------------------- 096 if ( uuid1 == null ) 097 { 098 return ( uuid2 == null ) ? 0 : -1; 099 } 100 101 if ( uuid2 == null ) 102 { 103 return 1; 104 } 105 106 return uuid1.compareTo( uuid2 ); 107 } 108}