ScheduleComparator.java
2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.bsth.data.schedule;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
/**
*
* @ClassName: ScheduleComparator
* @Description: TODO(实际班次排序器)
* @author PanZhao
* @date 2016年8月15日 下午1:53:28
*
*/
public class ScheduleComparator {
/* public static class FCNO implements Comparator<ScheduleRealInfo>{
@Override
public int compare(ScheduleRealInfo s1, ScheduleRealInfo s2) {
return s1.getFcno() - s2.getFcno();
}
}*/
static Map<String, Integer> bcTypeOrderMap = new HashMap<>();
static{
bcTypeOrderMap.put("out", 0);
bcTypeOrderMap.put("normal", 1);
bcTypeOrderMap.put("region", 2);
bcTypeOrderMap.put("major", 3);
bcTypeOrderMap.put("venting", 4);
bcTypeOrderMap.put("ldks", 5);
bcTypeOrderMap.put("in", 6);
}
public static class FCSJ implements Comparator<ScheduleRealInfo>{
@Override
public int compare(ScheduleRealInfo s1, ScheduleRealInfo s2) {
int diff = (int) (s1.getFcsjT() - s2.getFcsjT());
return diff!=0?diff:typeOrder(s1.getBcType()) - typeOrder(s2.getBcType());
}
}
private static int typeOrder(String bcType){
return bcTypeOrderMap.get(bcType)!=null?bcTypeOrderMap.get(bcType):0;
}
public static class DFSJ implements Comparator<ScheduleRealInfo>{
static Logger logger = LoggerFactory.getLogger(DFSJ.class);
@Override
public int compare(ScheduleRealInfo s1, ScheduleRealInfo s2) {
try{
if(!s1.getXlBm().equals(s2.getXlBm()) || !s1.getLpName().equals(s2.getLpName())){
int diff = (int) (s1.getDfsjT() - s2.getDfsjT());
return diff!=0?diff:typeOrder(s1.getBcType()) - typeOrder(s2.getBcType());
}
else{
/**
* 按时刻表发车顺序号
*/
Integer fc1 = s1.getFcno();
Integer fc2 = s2.getFcno();
if(null != fc1 && null != fc2){
return fc1.intValue()==fc2.intValue()?0:fc1.intValue()-fc2.intValue();
}
else{
int diff = (int) (s1.getDfsjT() - s2.getDfsjT());
return diff!=0?diff:typeOrder(s1.getBcType()) - typeOrder(s2.getBcType());
}
}
}catch (Exception e){
logger.error("排序异常", e);
return s1.getDfsjT() - s2.getDfsjT() > 0?1:-1;
}
}
}
public static class DFSJ2 implements Comparator<ScheduleRealInfo>{
@Override
public int compare(ScheduleRealInfo s1, ScheduleRealInfo s2) {
int diff = (int) (s1.getDfsjT() - s2.getDfsjT());
return diff!=0?diff:typeOrder(s1.getBcType()) - typeOrder(s2.getBcType());
}
}
}