1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.maps.entity;
17
18 import java.util.Comparator;
19
20 public class LocationSort implements Comparator<Location> {
21
22 public int compare(Location loc1, Location loc2) {
23 String cmp1 = loc1.getName();
24 String cmp2 = loc2.getName();
25 for (int cmp1pos = 0; cmp1pos < cmp1.length(); cmp1pos++) {
26 char chr1 = cmp1.charAt(cmp1pos);
27 if (cmp1pos < cmp2.length()) {
28
29 char chr2 = cmp2.charAt(cmp1pos);
30 boolean chr1IsDigit = Character.isDigit(chr1);
31 boolean chr2IsDigit = Character.isDigit(chr2);
32 if (chr1IsDigit && chr2IsDigit) {
33
34 if (chr1 != chr2) {
35 return chr1 - chr2;
36 }
37 } else if (chr1IsDigit && !chr2IsDigit) {
38
39 return 1;
40 } else if (!chr1IsDigit && chr2IsDigit) {
41 return -1;
42 } else {
43
44 if (chr1 != chr2) {
45 return chr1 - chr2;
46 }
47 }
48 } else {
49
50 return 1;
51 }
52 }
53 if (cmp2.length() > cmp1.length()) {
54
55 return -1;
56 }
57 return 0;
58 }
59
60 }