java内部排序

1 public class MergeWorkAssignment implements Comparable<MergeWorkAssignment>
2 实现方法
3 public int compareTo(MergeWorkAssignment o) {
4   return this.getVocabularyName().compareToIgnoreCase(o.getVocabularyName());
5  } 
 1 public class BriefTermExGroupSortBySourceGroup implements Comparator {
 2     public int compare(Object o1, Object o2) {
 3         int result = 0;
 4         long d1 = ((BriefTermExGroup) o1).getPreferred();
 5         long d2 = ((BriefTermExGroup) o2).getPreferred();
 6 
 7         if (d1 > d2) {
 8             result = 1;
 9         } else {
10             if (d1 == d2) {
11                 long group1 = ((BriefTermExGroup) o1).getSourceGroupId();
12                 long group2 = ((BriefTermExGroup) o2).getSourceGroupId();
13                 if (group1 > group2) {
14                     result = 1;
15                 } else {
16                     if (group1 == group2) {
17                         result = 0;
18                     } else {
19                         result = -1;
20                     }
21                 }
22             } else {
23                 result = -1;
24             }
25         }
26         return result;
27     }
28 }

调用:

Collections.sort(vBriefTermExGroup, new BriefTermExGroupSortBySourceGroup());

 1 日期
 2 
 3 package tcweb.config;
 4 
 5 import java.util.Comparator;
 6 import java.util.Date;
 7 
 8 public class VocabularyDateComparator implements Comparator {
 9  public int compare(Object o1, Object o2) {
10   int result=0;
11      Date date1 = ( (Vocabulary) o1).getRegisteredTime();
12      Date date2 = ( (Vocabulary) o2).getRegisteredTime();
13      if (date1 == null)
14             return 1;
15         if (date2 == null)
16             return -1;
17 
18      if(date1 != null && date2 != null){
19       result = date2.compareTo(date1);
20      }
21      return result;
22 
23    }
24 
25 }
 1 数字
 2 
 3 package tcweb.config;
 4 
 5 import java.util.Comparator;
 6 
 7 public class VocabularyTypeCompatarot implements Comparator {
 8  public int compare(Object o1, Object o2) {
 9   int result=0;
10   long d1 = ( (Vocabulary) o1).getVocabularyType();
11     long d2 = ( (Vocabulary) o2).getVocabularyType();
12     if (d1 > d2) {
13      result = 1;
14           } else {
15               if (d1 == d2) {
16                result = 0;
17               } else {
18                result = -1;
19               }
20    }
21     return result;
22  }
23 
24 }

 

java内部排序,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。