整理器加比较器
我有一个 beans OptionItemDTO 的集合(属性标签和值),我目前正在使用类似的东西按标签排序:
Collections.sort(combo, new LabelComparator())
问题是它不会对重音元音进行排序(我的语言环境是西班牙语)。
根据此文档 http://blogs.oracle.com/CoreJavaTechTips/entry/sorting_strings我必须使用 Collator 类。
但是,如果我使用带有整理器的排序,则无法使用比较器(反之亦然)。有什么想法吗?
提前致谢!
I have a collection of beans OptionItemDTO (properties label and value) and I'm currently using something like this to sort by label:
Collections.sort(combo, new LabelComparator())
The problem is that it does not sort stressed vowels (my locale is spanish).
According to this document http://blogs.oracle.com/CoreJavaTechTips/entry/sorting_strings I must use a Collator class.
But if I use the sort with collator, I can't use the comparator (and vice-versa). Any ideas?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 LabelComparator 应委托给 Collator 来比较 DTO 的标签:
Your LabelComparator should delegate to a Collator to compare the labels of your DTOs:
用于使用 CollationKeys(而不是 Collators)对对象集合进行排序:
我编写了一个小型框架, html" rel="nofollow">http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/text/Localizeds.html
你只需要实现一个 Localizer (或者使您的 POJO 实现 Localized)以提供字符串表示形式:
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
您可以查看一些示例的单元测试:
该库是开源的。
https://sourceforge.net/projects/softsmithy/files/softsmithy/v0.1 1/
I have written a small framework to sort collections of objects with CollationKeys (rather than Collators):
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/text/Localizables.html
You just have to implement a Localizer (or make your POJO 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 have a look at the 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/