Reputation: 362
I have a Wicket web application, that sorts table rows in the following order:
Ascending:
Now i'm writing a webunit test to test the sorting mechanism, but it seems to switch the order of characters and numbers like:
Ascending:
So this code will fail, when sorting ascending and it encounters the two entries:
My simplified sorting code:
protected int compare(String val1, String val2) {
return val1.compareTo(val2);
}
What's the "java way" of telling my test code to test the order like my web application produces it?
May be something like Collator
? I would prefer a JRE solution over a selfwritten Comparator
over a 3rd party library.
Upvotes: 0
Views: 42
Reputation: 96
You could try using a RuleBasedCollator like this:
String rule = "<a,A<b,B<c,C<[...]<'1'<'2'<'3'<'4'[...]";
RuleBasedCollator collator = new RuleBasedCollator(rule);
return collator.compare(val1,val2);
Upvotes: 2