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.io.Serializable; 024 025import org.apache.directory.api.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 /** A logger for this class */ 041 private static final Logger LOG = LoggerFactory.getLogger( StringComparator.class ); 042 043 044 /** 045 * The StringComparator constructor. Its OID is the StringMatch matching 046 * rule OID. 047 * 048 * @param oid The Comparator's OID 049 */ 050 public StringComparator( String oid ) 051 { 052 super( oid ); 053 } 054 055 056 /** 057 * {@inheritDoc} 058 */ 059 public int compare( String s1, String s2 ) 060 { 061 LOG.debug( "comparing String objects '{}' with '{}'", s1, s2 ); 062 063 if ( s1 == s2 ) 064 { 065 return 0; 066 } 067 068 // ------------------------------------------------------------------- 069 // Handle some basis cases 070 // ------------------------------------------------------------------- 071 if ( s1 == null ) 072 { 073 return -1; 074 } 075 076 if ( s2 == null ) 077 { 078 return 1; 079 } 080 081 return s1.compareTo( s2 ); 082 } 083}