gishur.core
Class StdComparitor

java.lang.Object
  |
  +--gishur.core.StdComparitor
All Implemented Interfaces:
Comparitor, java.io.Serializable
Direct Known Subclasses:
LineComparitor, PointComparitor

public class StdComparitor
extends java.lang.Object
implements Comparitor, java.io.Serializable

Standard Comparitor type. Compares numbers, strings, characters, boolean-values and Items. New Comparitors should be derived from this class. The most important method compare(Object,Object) is best overridden in the following way:

 public short compare(Object o1,Object o2) {
  ... // call own compare-methods with 'return...', e.g.
  if ((o1 instanceof MyObject) && (o2 instanceOf MyObject))
   return compare((MyObject)o1,(MyObject)o2);
  // calls a method which compares MyObject-objects and finishes this method
  return super.compare(o1,o2); // try to perform other comparisons and throw an
                               // Exception, if all trials fail
 }
 

Version:
1.3
Author:
Thomas Wolf
See Also:
Serialized Form

Fields inherited from interface gishur.core.Comparitor
BIGGER, EQUAL, SMALLER
 
Constructor Summary
StdComparitor()
           
 
Method Summary
 short compare(java.lang.Boolean b1, java.lang.Boolean b2)
          Compares two java.lang.Boolean-objects.
 short compare(java.lang.Character c1, java.lang.Character c2)
          Compares two Character-objects using their charValue()-method.
 short compare(java.lang.Number n1, java.lang.Number n2)
          Compares two java.lang.Numbers.
 short compare(java.lang.Object o1, java.lang.Object o2)
          Overrides Comparitor.compare(Object,Object).
 short compare(java.lang.String s1, java.lang.String s2)
          Compares two Strings using the compareTo(String) -method of class String in package java.lang.
 short compareHash(java.lang.Object o1, java.lang.Object o2)
          Compares two objects using their hash-codes.
 java.lang.String toString()
          Overrids java.lang.Object.toString().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StdComparitor

public StdComparitor()
Method Detail

toString

public java.lang.String toString()
Overrids java.lang.Object.toString().
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

compare

public short compare(java.lang.String s1,
                     java.lang.String s2)
Compares two Strings using the compareTo(String) -method of class String in package java.lang.
Parameters:
s1,s2 - two Strings to compare
Returns:
a comparison-constant (Comparitor.BIGGER, Comparitor.SMALLER or Comparitor.EQUAL)

compare

public short compare(java.lang.Character c1,
                     java.lang.Character c2)
Compares two Character-objects using their charValue()-method.
Parameters:
c1,c2 - Character-objects to compare
Returns:
a comparison-constant (Comparitor.BIGGER, Comparitor.SMALLER or Comparitor.EQUAL)

compare

public short compare(java.lang.Number n1,
                     java.lang.Number n2)
Compares two java.lang.Numbers.
Parameters:
n1,n2 - Number-objects to compare.
Returns:
a comparison-constant (Comparitor.BIGGER, Comparitor.SMALLER or Comparitor.EQUAL)

compare

public short compare(java.lang.Boolean b1,
                     java.lang.Boolean b2)
Compares two java.lang.Boolean-objects. false is supposed to be 'smaller' than true.
Parameters:
b1,b2 - two Boolean-values to compare.
Returns:
a comparison-constant (Comparitor.BIGGER, Comparitor.SMALLER or Comparitor.EQUAL)

compareHash

public short compareHash(java.lang.Object o1,
                         java.lang.Object o2)
Compares two objects using their hash-codes.
Parameters:
o1,o2 - two Objects to compare
Returns:
a comparison-constant (Comparitor.BIGGER, Comparitor.SMALLER or Comparitor.EQUAL)

compare

public short compare(java.lang.Object o1,
                     java.lang.Object o2)
Overrides Comparitor.compare(Object,Object). If an argument is of type KeyValueHolder, its key will be compared to the other object. If both arguments are null, Comparitor.EQUAL will be returned, if only one argument is null, it will be supposed to be the smaller one. If no argument is null the method checks the type of the arguments and calls the matching compare-method.
Specified by:
compare in interface Comparitor
Parameters:
o1,o2 - two objects to compare
Returns:
a comparison-constant (Comparitor.BIGGER, Comparitor.SMALLER or Comparitor.EQUAL)
See Also:
Comparitor.compare(java.lang.Object, java.lang.Object)