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