bb.util
Class CaseInsensitiveComparator

java.lang.Object
  extended by bb.util.CaseInsensitiveComparator
All Implemented Interfaces:
Serializable, Comparator<String>

public class CaseInsensitiveComparator
extends Object
implements Comparator<String>, Serializable

Imposes an ordering on Strings that is inconsistent with equals; see compare for details.

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer
See Also:
Serialized Form

Nested Class Summary
static class CaseInsensitiveComparator.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private static long serialVersionUID
           
 
Constructor Summary
CaseInsensitiveComparator()
           
 
Method Summary
 int compare(String s1, String s2)
          Converts s1 and s2 to lower case and then returns s1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

CaseInsensitiveComparator

public CaseInsensitiveComparator()
Method Detail

compare

public int compare(String s1,
                   String s2)
            throws IllegalArgumentException
Converts s1 and s2 to lower case and then returns s1.compareTo(s2). So, the result is consistent with equalsIgnoreCase but is inconsistent with equals.

Specified by:
compare in interface Comparator<String>
Throws:
IllegalArgumentException - if s1 or s2 is null