ProgramixGenericLib v5.0.1

com.programix.collections
Class GeneralStringComparator

java.lang.Object
  extended by com.programix.collections.GeneralStringComparator
All Implemented Interfaces:
Comparator<String>

public final class GeneralStringComparator
extends Object
implements Comparator<String>

Comparator that can be used to compare String's in many different ways. Instances are immutable (everything must be specified during construction).

Author:
Paul Hyde

Nested Class Summary
static class GeneralStringComparator.CharSort
          Defines how the characters of the string should be considered when being compared to other String's.
static class GeneralStringComparator.LengthTreatment
          Defines how the length of the string should be considered when being compared to other String's.
static class GeneralStringComparator.NullTreatment
          Defines how null references should be treated when being compared to String's.
 
Constructor Summary
GeneralStringComparator()
          Defaults to case insensitive ascending, null less than all, no special length treatment, and all strings trimmed before comparing.
GeneralStringComparator(GeneralStringComparator.CharSort charSort, GeneralStringComparator.NullTreatment nullTreatment, GeneralStringComparator.LengthTreatment lengthTreatment, boolean trimBeforeCompare)
           
 
Method Summary
 int compare(String obj1, String obj2)
           
 GeneralStringComparator.CharSort getCharSort()
           
 GeneralStringComparator.LengthTreatment getLengthTreatment()
           
 GeneralStringComparator.NullTreatment getNullTreatment()
           
 boolean isTrimBeforeCompare()
           
 
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
 

Constructor Detail

GeneralStringComparator

public GeneralStringComparator(GeneralStringComparator.CharSort charSort,
                               GeneralStringComparator.NullTreatment nullTreatment,
                               GeneralStringComparator.LengthTreatment lengthTreatment,
                               boolean trimBeforeCompare)

GeneralStringComparator

public GeneralStringComparator()
Defaults to case insensitive ascending, null less than all, no special length treatment, and all strings trimmed before comparing.

Equivalent to:

 this(CharSort.CASE_INSENSITIVE_ASC,
      NullTreatment.LESS_THAN_ALL,
      LengthTreatment.NONE,
      true);
 

Method Detail

getCharSort

public GeneralStringComparator.CharSort getCharSort()

getLengthTreatment

public GeneralStringComparator.LengthTreatment getLengthTreatment()

getNullTreatment

public GeneralStringComparator.NullTreatment getNullTreatment()

isTrimBeforeCompare

public boolean isTrimBeforeCompare()

compare

public int compare(String obj1,
                   String obj2)
Specified by:
compare in interface Comparator<String>

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.