java - Influence the order of digits and charachters in compare method -


i have wicket web application, sorts table rows in following order:

ascending:

  • first charachters (a-z)
  • then numbers (1-9)

now i'm writing webunit test test sorting mechanism, seems switch order of charachters , numbers like:

ascending:

  • first numbers (1-9)
  • then charachters (a-z)

so code fail, when sorting ascending , encounters 2 entries:

  • ...
  • zzz
  • 111
  • ...

my simplyfied sorting code:

protected int compare(string val1, string val2) {         return val1.compareto(val2); } 

what's "java way" of telling test code test order web application produces it? may collator? prefer jre solution on selfwritten comparator on 3rd party library.

you try using rulebasedcollator this:

string rule = "<a,a<b,b<c,c<[...]<'1'<'2'<'3'<'4'[...]"; rulebasedcollator collator = new rulebasedcollator(rule); return collator.compare(val1,val2); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -