org.hecl
Class Compare

java.lang.Object
  extended by org.hecl.Compare

public class Compare
extends java.lang.Object

The Compare class exists to compare things in different ways.

Version:
1.0
Author:
David N. Welton

Field Summary
static int NUMCOMPARE
           
static int PROCCOMPARE
           
static int STRINGCOMPARE
           
 
Constructor Summary
Compare()
           
 
Method Summary
static int compareProc(Thing a, Thing b, Interp interp, Thing sortproc)
          The compareProc method takes two things to compare, an interpreter, andthe name of a proc to compare the two things with.
static int compareString(Thing a, Thing b)
          compareString compares two Things as strings.
static boolean same(Thing t1, Thing t2)
          same checks if two Things as the same.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUMCOMPARE

public static final int NUMCOMPARE
See Also:
Constant Field Values

STRINGCOMPARE

public static final int STRINGCOMPARE
See Also:
Constant Field Values

PROCCOMPARE

public static final int PROCCOMPARE
See Also:
Constant Field Values
Constructor Detail

Compare

public Compare()
Method Detail

same

public static boolean same(Thing t1,
                           Thing t2)
same checks if two Things as the same. In case the parameters are ObjectThings, they are the same only if they are identical, for all other Things this function calls compareString to check for sameness.

This subtle difference in comparison is necessary since ObjectThing.toString() may yield the same string representation even when the objects are different (happens i.e. on Nokia 6630 for instances of javax.microeditoion.lcdui.Command.

Parameters:
t1 - a Thing value
t2 - a Thing value
Returns:
boolean indicating sameness.

compareString

public static int compareString(Thing a,
                                Thing b)
compareString compares two Things as strings. This can't fail, because all Things may be represented as strings.

Parameters:
a - a Thing value
b - a Thing value
Returns:
an int value
Throws:
HeclException

compareProc

public static int compareProc(Thing a,
                              Thing b,
                              Interp interp,
                              Thing sortproc)
                       throws HeclException
The compareProc method takes two things to compare, an interpreter, andthe name of a proc to compare the two things with. It puts together a codething, runs it, and returns the result: 0 if the two things are equal, -1 if A is "less than" B, and 1 if 1 if A is "greater than" B.

Parameters:
a - a Thing value
b - a Thing value
interp - an Interp value
sortproc - a Thing value
Returns:
an int value
Throws:
HeclException - if an error occurs