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.shared.ldap.model.schema.comparators; 021 022 023import java.io.Serializable; 024 025import org.apache.directory.shared.ldap.model.schema.LdapComparator; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028 029 030/** 031 * A comparator for Strings. 032 * 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 */ 035public class StringComparator extends LdapComparator<String> implements Serializable 036{ 037 /** The serial version UID */ 038 private static final long serialVersionUID = 2L; 039 040 041 /** A logger for this class */ 042 private static final Logger LOG = LoggerFactory.getLogger( StringComparator.class ); 043 044 045 /** 046 * The StringComparator constructor. Its OID is the StringMatch matching 047 * rule OID. 048 */ 049 public StringComparator( String oid ) 050 { 051 super( oid ); 052 } 053 054 055 /** 056 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 057 */ 058 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ES_COMPARING_PARAMETER_STRING_WITH_EQ", 059 justification ="false positive") 060 public int compare( String s1, String s2 ) 061 { 062 LOG.debug( "comparing String objects '{}' with '{}'", s1, s2 ); 063 064 if ( s1 == s2 ) 065 { 066 return 0; 067 } 068 069 // ------------------------------------------------------------------- 070 // Handle some basis cases 071 // ------------------------------------------------------------------- 072 if ( s1 == null ) 073 { 074 return ( s2 == null ) ? 0 : -1; 075 } 076 077 if ( s2 == null ) 078 { 079 return 1; 080 } 081 082 return s1.compareTo( s2 ); 083 } 084}