码迷,mamicode.com
首页 > 编程语言 > 详细

java内部排序

时间:2014-06-18 10:45:39      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:cWeb   style   class   blog   code   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内部排序,布布扣,bubuko.com

java内部排序

标签:cWeb   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/lightning95/p/3793116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!