Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.comparators
Class StringComparator

java.lang.Object
  extended by com.citra.comparators.StringComparator
All Implemented Interfaces:
Serializable, Comparator

public class StringComparator
extends Object
implements Comparator, Serializable

This class compares two strings lexicographically.

The case sensitivity can be controlled with StringComparator.setCaseSensitive(boolean).

See Also:
Serialized Form

Field Summary
protected  boolean caseSensitive
          a boolean flag indicating the case-sensitivity of the String comparator.
 
Constructor Summary
StringComparator()
          Creates a case-insensitive String comparator.
StringComparator(boolean caseSensitivity)
          Creates a String comparator.
 
Method Summary
 int compare(Object o1, Object o2)
          Compares its two arguments for order as defined by compare of the Comparator interface.
 boolean isCaseSensitive()
          Determines if this comparator is case sensitive.
 void setCaseSensitive(boolean caseSensitivity)
          Sets the case sensitivity of this string comparator.
 
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

caseSensitive

protected boolean caseSensitive
a boolean flag indicating the case-sensitivity of the String comparator.

Constructor Detail

StringComparator

public StringComparator()
Creates a case-insensitive String comparator.


StringComparator

public StringComparator(boolean caseSensitivity)
Creates a String comparator.

The case sensitivity is determined by the caseSensitivity parameter.

Parameters:
caseSensitivity - the case sensitivity of the comparator.
Method Detail

compare

public int compare(Object o1,
                   Object o2)
Compares its two arguments for order as defined by compare of the Comparator interface. o1 and o2 must be Strings, otherwise this method throws a ClassCastException.

This method casts both objects to Strings and compares them using compareTo or compareToIgnoreCase of the String class.

Specified by:
compare in interface Comparator
Parameters:
o1 - the first object to be compared.
o2 - the second object to be compared.
Returns:
a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.

isCaseSensitive

public boolean isCaseSensitive()
Determines if this comparator is case sensitive.

Returns:
true if the comparator is case sensitive.

setCaseSensitive

public void setCaseSensitive(boolean caseSensitivity)
Sets the case sensitivity of this string comparator.

Parameters:
caseSensitivity - the case sensitivity

Copyright © 2011 Citra Technologies. All Rights Reserved.