All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.compare.NumericStringComparer

java.lang.Object
   |
   +----sdsu.compare.Comparer
           |
           +----sdsu.compare.NumericStringComparer

public class NumericStringComparer
extends Comparer
A concrete class for comparing strings and strings that are in number format. Assumes that the string representation does not contain leading zeros. Longer strings are larger than shorter strings. If a string contains a decimal point then the number of characters (or digits) to the left of the decimal point is used as the length of the string. If two strings are of equal length than normal strign compare is used. The following comparisons are all true using this comparer
		lessThan( "2", "3" )
lessThan( "22", "3" )
lessThan( "234", "236" )
lessThan( "123a", "123b" )
lessThan( "12.3", "9.8" )
lessThan( "a", "b" )
lessThan( "XX12", "aaaab" )
lessThan( "22.457", "22.6" )
lessThan( "22.4", "22.6333" )
 

Version:
1.0 5 December 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)

Method Index

 o equals(Object, Object)
Returns true if the leftOperand is equal to the rightOperand.
 o getInstance()
Returns a NumericStringComparer object.
 o greaterThan(Object, Object)
Returns true if the leftOperand is greater than the rightOperand.
 o lessThan(Object, Object)
Returns true if the leftOperand is less than the rightOperand.

Methods

 o getInstance
 public static Comparer getInstance()
Returns a NumericStringComparer object.

 o lessThan
 public final boolean lessThan(Object leftOperand,
                               Object rightOperand) throws ClassCastException
Returns true if the leftOperand is less than the rightOperand.

Throws: ClassCastException
If operand objects are not strings. ClassCastException is a RuntimeException, so compiler does not force you to catch this exception.
Overrides:
lessThan in class Comparer
 o greaterThan
 public final boolean greaterThan(Object leftOperand,
                                  Object rightOperand) throws ClassCastException
Returns true if the leftOperand is greater than the rightOperand.

Throws: ClassCastException
If operand objects are not strings objects. ClassCastException is a RuntimeException, so compiler does not force you to catch this exception.
Overrides:
greaterThan in class Comparer
 o equals
 public final boolean equals(Object leftOperand,
                             Object rightOperand) throws ClassCastException
Returns true if the leftOperand is equal to the rightOperand.

Throws: ClassCastException
If operand objects are not Number objects. ClassCastException is a RuntimeException, so compiler does not force you to catch this exception.
Overrides:
equals in class Comparer

All Packages  Class Hierarchy  This Package  Previous  Next  Index