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 by Character values
11: *
12: * @author Chad Brandon
13: */
14: class CharacterComparator implements Comparator, Serializable {
15: private Collator collator = null;
16:
17: /**
18: * Used to sort Character values, both objects are assumed to be assignable
19: * to java.util.Character
20: */
21: public int compare(Object objectA, Object objectB) {
22: Character aAsCharacter = (Character) objectA;
23: Character bAsCharacter = (Character) objectB;
24: this .initializeCollator();
25: return collator.compare(Character.toString(aAsCharacter
26: .charValue()), Character.toString(bAsCharacter
27: .charValue()));
28: }
29:
30: /**
31: * Initializes the Collator
32: */
33: private void initializeCollator() {
34: if (this .collator == null) {
35: this .collator = Collator.getInstance();
36:
37: //set to ignore case
38: collator.setStrength(Collator.PRIMARY);
39: }
40: }
41: }
|