1 |
package dk.daoas.daoadresseservice.util; |
package dk.daoas.daoadresseservice.util; |
2 |
|
|
3 |
|
import java.io.Serializable; |
4 |
|
|
5 |
import java.util.Arrays; |
import java.util.Arrays; |
6 |
import java.util.Collections; |
import java.util.Collections; |
7 |
import java.util.Comparator; |
import java.util.Comparator; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
public class NaturalOrderComparator<T> implements Comparator<T> |
public class NaturalOrderComparator<T> implements Comparator<T>, Serializable |
37 |
{ |
{ |
38 |
int compareRight(String a, String b) |
private static final long serialVersionUID = 1L; |
39 |
|
|
40 |
|
int compareRight(String a, String b) |
41 |
{ |
{ |
42 |
int bias = 0; |
int bias = 0; |
43 |
int ia = 0; |
int ia = 0; |
181 |
"pic 5 something", "pic 6", "pic 7", "pic100", "pic100a", "pic120", "pic121", |
"pic 5 something", "pic 6", "pic 7", "pic100", "pic100a", "pic120", "pic121", |
182 |
"pic02000", "tom", "x2-g8", "x2-y7", "x2-y08", "x8-y8" }; |
"pic02000", "tom", "x2-g8", "x2-y7", "x2-y08", "x8-y8" }; |
183 |
|
|
184 |
List orig = Arrays.asList(strings); |
List<String> orig = Arrays.asList(strings); |
185 |
|
|
186 |
System.out.println("Original: " + orig); |
System.out.println("Original: " + orig); |
187 |
|
|
188 |
List scrambled = Arrays.asList(strings); |
List<String> scrambled = Arrays.asList(strings); |
189 |
Collections.shuffle(scrambled); |
Collections.shuffle(scrambled); |
190 |
|
|
191 |
System.out.println("Scrambled: " + scrambled); |
System.out.println("Scrambled: " + scrambled); |
192 |
|
|
193 |
Collections.sort(scrambled, new NaturalOrderComparator()); |
Collections.sort(scrambled, new NaturalOrderComparator<String>()); |
194 |
|
|
195 |
System.out.println("Sorted: " + scrambled); |
System.out.println("Sorted: " + scrambled); |
196 |
} |
} |
|
} |
|
197 |
|
} |