01: package org.andromda.utils.beans.comparators;
02:
03: import java.io.Serializable;
04:
05: import java.text.Collator;
06:
07: import java.util.Comparator;
08:
09: /**
10: * Used to sort String values
11: *
12: * @author Chad Brandon
13: */
14: class StringComparator implements Comparator, Serializable {
15: private Collator collator = null;
16:
17: /**
18: * Used to sort String values, both objects are assumed
19: * to be String instances.
20: */
21: public int compare(final Object objectA, final Object objectB) {
22: this .initializeCollator();
23: return collator.compare(objectA, objectB);
24: }
25:
26: /**
27: * Initializes the Collator
28: */
29: private void initializeCollator() {
30: if (this .collator == null) {
31: this .collator = Collator.getInstance();
32:
33: //set to ignore case
34: collator.setStrength(Collator.PRIMARY);
35: }
36: }
37: }
|