我有以下集合:
Collection<AgentSummaryDTO> agentDtoList = new ArrayList<AgentSummaryDTO>();
Run Code Online (Sandbox Code Playgroud)
哪里AgentSummaryDTO是这样的:
public class AgentSummaryDTO implements Serializable {
private Long id;
private String agentName;
private String agentCode;
private String status;
private Date createdDate;
private Integer customerCount;
}
Run Code Online (Sandbox Code Playgroud)
现在我必须agentDtoList根据customerCount字段对集合进行排序,如何实现这一目标?
我有这个代码.它用法语和俄语正确排序.我使用Locale.US,它似乎是正确的.这个解决方案适用于所有语言吗?它适用于其他语言吗?例如:中国人,韩国人,日本人......如果没有,有什么更好的解决方案?
public class CollationTest {
public static void main(final String[] args) {
final Collator collator = Collator.getInstance(Locale.US);
final SortedSet<String> set = new TreeSet<String>(collator);
set.add("abîmer");
set.add("abîmé");
set.add("aberrer");
set.add("abhorrer");
set.add("aberrance");
set.add("abécédaire");
set.add("abducteur");
set.add("abdomen");
set.add("??????????????-?????????????????");
set.add("???????");
set.add("????????");
set.add("?????????????");
set.add("???????");
set.add("???????");
set.add("???????");
set.add("???????");
for(final String s : set) {
System.out.println(s);
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新: 对不起,我不要求这个集合必须包含所有语言.我的意思是这个集包含一种语言,并在每种语言中正确排序.
public class CollationTest {
public static void main(final String[] args) {
final Collator collator = Collator.getInstance(Locale.US);
final SortedSet<String> set = new TreeSet<String>(collator);
// Sorting in French.
set.clear();
set.add("abîmer");
set.add("abîmé"); …Run Code Online (Sandbox Code Playgroud) 有没有办法使这个方法适当通用并取消警告?
/**
* <p>Sort a collection by a certain "value" in its entries. This value is retrieved using
* the given <code>valueFunction</code> which takes an entry as argument and returns
* its value.</p>
*
* <p>Example:</p>
* <pre>// sort tiles by number
*Collects.sortByValue(tileList, true, new Function<Integer,NormalTile>() {
* public Integer call(NormalTile t) {
* return t.getNumber();
* }
*});</pre>
*
* @param list The collection.
* @param ascending Whether to sort ascending (<code>true</code>) or descending (<code>false</code>).
* @param valueFunction The …Run Code Online (Sandbox Code Playgroud)