I have a set of beans OptionItemDTO (property label and value), and currently I'm using something like this to sort by label:
Collections.sort(combo, new LabelComparator())
The problem is that it does not sort stressed vowels (my language is Spanish).
According to this document http://blogs.oracle.com/CoreJavaTechTips/entry/sorting_strings I have to use the Collator class.
But if I use collator sorting, I cannot use a comparator (and vice versa). Any ideas?
Thanks in advance!
Your LabelComparator must delegate the Collator to compare the labels of your DTOs:
public int compare(OptionItemDTO dto1, OptionItemDTO dto2) { return collator.compare(dto1.getLabel(), dto2.getLabel()); }
I wrote a small structure for sorting collections of objects with CollationKeys (and not with Collators):
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/text/Localizables.html
You just need to implement a localizer (or do a POJO to implement Localizable) to provide a string representation:
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/text/Localizer.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/text/Localizable.html
You can take a look at unit tests for some samples:
http://softsmithy.hg.sourceforge.net/hgweb/softsmithy/lib/main-golden/file/5c4db802573b/lib-core/src/test/java/org/softsmithy/lib/text/LocalizablesTest.java
The library is open source.
https://sourceforge.net/projects/softsmithy/files/softsmithy/v0.1/
<dependency> <groupId>org.softsmithy.lib</groupId> <artifactId>lib-core</artifactId> <version>0.1</version> </dependency>
Source: https://habr.com/ru/post/902762/More articles:Rabl Collection Collection - ruby | fooobar.comget and configure macro and folder shortcuts in Python - pythonChange the language in which Geocoder.geocode () returns the results - javascript.NET Programming Tasks Requiring Local Administrator Rights - .netUnclear javascript snippet - javascriptCan XSLT do everything CSS can do? - xmlHow to (completely) convert a query string to a JSON object? - jsonThis content cannot be displayed in frame - IE 8 application - Facebook - internet-explorer-8How to convert a query string or map of a JSON object to a separate JSON object using jQuery? - jsonPerl Authen :: OATH and Google Authenticator - incompatible? - perlAll Articles