edu.nrao.sss.sort
Class StringSortKey

java.lang.Object
  extended by edu.nrao.sss.sort.SortKey<String>
      extended by edu.nrao.sss.sort.StringSortKey
All Implemented Interfaces:
Orderable
Direct Known Subclasses:
ReflectiveStringSortKey

public abstract class StringSortKey
extends SortKey<String>

A sort key for Strings.

The most common way to extend this class is to subclass it into a class that also implements Comparator. The main job of the subclass is to provide the strings to this parent class. Example:

   /**
    * Sorts persons based on their names (surname then given names).
    */
   public class PersonNameKey extends StringSortKey
     implements Comparator<Person>
   {
     public int compare(Person p1, Person p2)
     {
       return compareObjects(p1.getNameLastFirst(), p2.getNameLastFirst());
     }
   }

Clients of the example PersonNameKey class are able to configure that comparator via the setOrder and setIgnoreCase methods, something they cannot do with the plain Comparator interface. They may then place instances of this class in a CompoundComparator.

Version Info:

$Revision: 593 $
$Date: 2007-05-07 15:54:14 -0600 (Mon, 07 May 2007) $
$Author: dharland $

Since:
2007-05-03
Author:
David M. Harland

Constructor Summary
protected StringSortKey()
          Helps create a new, case-sensitive, instance.
 
Method Summary
protected  int compareAscending(String o1, String o2)
          Uses the natural ordering of String and the value of this key's ignoreCase property.
protected  int compareNatural(String o1, String o2)
          Uses the natural ordering of String and the value of this key's ignoreCase property.
 void setIgnoreCase(boolean ignore)
          Tells this key to either consider or ignore case when comparing strings.
 
Methods inherited from class edu.nrao.sss.sort.SortKey
compareObjects, compareObjects, getOrder, nullOrdering, objectsAreEqual, setOrder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringSortKey

protected StringSortKey()
Helps create a new, case-sensitive, instance.

Method Detail

setIgnoreCase

public void setIgnoreCase(boolean ignore)
Tells this key to either consider or ignore case when comparing strings.

Parameters:
ignore - a value of true will instruct this key to ignore case when comparing strings.

compareNatural

protected int compareNatural(String o1,
                             String o2)
Uses the natural ordering of String and the value of this key's ignoreCase property.

Specified by:
compareNatural in class SortKey<String>

compareAscending

protected int compareAscending(String o1,
                               String o2)
Uses the natural ordering of String and the value of this key's ignoreCase property.

Specified by:
compareAscending in class SortKey<String>


Copyright © 2009. All Rights Reserved.