首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

通过地图取值List并比较两个两个时间属性排序

2012-09-07 
通过map取值List并比较两个两个时间属性排序??? public static void main(String[] args) {??? ??? Standa

通过map取值List并比较两个两个时间属性排序


??? public static void main(String[] args) {
??? ??? StandardDTO dto1 = new StandardDTO();
??? ??? dto1.setReleaseDate(new Date(2011, 1, 11));
??? ??? dto1.setvId(1);

??? ??? StandardDTO dto2 = new StandardDTO();
??? ??? dto2.setReleaseDate(new Date(2012, 1, 11));
??? ??? dto2.setvId(2);

??? ??? StandardDTO dto3 = new StandardDTO();
??? ??? dto3.setApplyBeginDate(new Date(2012, 1, 11));
??? ??? dto3.setvId(3);

??? ??? StandardDTO dto4 = new StandardDTO();
??? ??? dto4.setApplyBeginDate(new Date(2010, 1, 11));
??? ??? dto4.setvId(4);

??? ??? StandardDTO dto5 = new StandardDTO();
??? ??? dto5.setApplyBeginDate(new Date(2010, 1, 11));
??? ??? dto5.setReleaseDate(new Date(2012, 1, 11));
??? ??? dto5.setvId(5);

??? ??? StandardDTO dto6 = new StandardDTO();
??? ??? dto6.setReleaseDate(new Date(2011, 1, 11));
??? ??? dto6.setApplyBeginDate(new Date(2010, 1, 11));
??? ??? dto6.setvId(6);

??? ??? StandardDTO dto7 = new StandardDTO();

??? ??? StandardDTO dto8 = new StandardDTO();

??? ??? List<StandardDTO> ls = new ArrayList<StandardDTO>();
??? ??? ls.add(dto1);
??? ??? ls.add(dto2);
??? ??? ls.add(dto3);
??? ??? ls.add(dto4);
??? ??? ls.add(dto5);
??? ??? ls.add(dto6);
??? ??? if (CollectionUtils.isNotEmpty(ls)) {
??? ??? ??? Collections.sort(ls, new Comparator<StandardDTO>() {
??? ??? ??? ??? public int compare(StandardDTO arg0, StandardDTO arg1) {
??? ??? ??? ??? ??? if (arg0.getReleaseDate() != null
??? ??? ??? ??? ??? ??? ??? && arg1.getReleaseDate() != null
??? ??? ??? ??? ??? ??? ??? && !arg0.getReleaseDate().equals(
??? ??? ??? ??? ??? ??? ??? ??? ??? arg1.getReleaseDate())) {
??? ??? ??? ??? ??? ??? return arg0.getReleaseDate().compareTo(
??? ??? ??? ??? ??? ??? ??? ??? arg1.getReleaseDate());
??? ??? ??? ??? ??? } else if (arg0.getReleaseDate() != null
??? ??? ??? ??? ??? ??? ??? && arg1.getReleaseDate() == null) {
??? ??? ??? ??? ??? ??? return -1;
??? ??? ??? ??? ??? } else if (arg0.getReleaseDate() == null
??? ??? ??? ??? ??? ??? ??? && arg1.getReleaseDate() != null) {
??? ??? ??? ??? ??? ??? return 1;
??? ??? ??? ??? ??? } else {
??? ??? ??? ??? ??? ??? if (arg0.getApplyBeginDate() != null
??? ??? ??? ??? ??? ??? ??? ??? && arg1.getApplyBeginDate() != null
??? ??? ??? ??? ??? ??? ??? ??? && !arg0.getApplyBeginDate().equals(
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? arg1.getApplyBeginDate())) {
??? ??? ??? ??? ??? ??? ??? return arg0.getApplyBeginDate().compareTo(
??? ??? ??? ??? ??? ??? ??? ??? ??? arg1.getApplyBeginDate());
??? ??? ??? ??? ??? ??? } else if (arg0.getApplyBeginDate() != null
??? ??? ??? ??? ??? ??? ??? ??? && arg1.getApplyBeginDate() == null) {
??? ??? ??? ??? ??? ??? ??? return -1;
??? ??? ??? ??? ??? ??? } else if (arg0.getApplyBeginDate() == null
??? ??? ??? ??? ??? ??? ??? ??? && arg1.getApplyBeginDate() != null) {
??? ??? ??? ??? ??? ??? ??? return 1;
??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? return 0;
??? ??? ??? ??? ??? }
??? ??? ??? ??? }
??? ??? ??? });

??? ??? ??? for (StandardDTO obj : ls) {
??? ??? ??? ??? System.out.println(obj.getvId());
??? ??? ??? }
??? ??? }
??? }

热点排行