关闭

项目中用到的比较好的技术

134人阅读 评论(0) 收藏 举报

 List<model1> list1=getModels1();

 

        return Lists.transform(list1, new Function<model1, mode2>(){

            @Override

            public model2 apply(model1 model) {

                return model1Simplmodel1Convert.convert(mode2);

            }});

   }

   

 

 

/**

 * 按照时间类型倒序

 */

public class TimeComparator implementsComparator<Model> {

         privateint orderflag;

         publicstatic SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");

 

         publicTimeComparator(int orderflag) {

                   this.orderflag= orderflag;

         }

         publicint getOrderflag() {

                   returnorderflag;

         }

 

         publicvoid setOrderflag(int orderflag) {

                   this.orderflag= orderflag;

         }

        

         @Override

         publicint compare(Model o1, Model o2) {

                   Datetime1 = null, time2 = null;

                   try{

                            if(orderflag == 0) {// updateTime

                                     time1= o1.getUpdateTime();

                                     time2= o2.getUpdateTime();

                                     if(time1 == null && time2 != null)

                                               return1;

                                     if(time2 == null && time1 != null)

                                               return-1;

                                     if(time2 == null && time1 == null)

                                               return0;

                            }else if (orderflag == 1) {// createTime

                                     time1= o1.getCreateTime();

                                     time2= o2.getCreateTime();

                                     if(time1 == null && time2 != null)

                                               return1;

                                     if(time2 == null && time1 != null)

                                               return-1;

                                     if(time2 == null && time1 == null)

                                               return0;

                            }else if (orderflag == 2) {// releaseDate

                                     time1= CalendarUtil.parseShortDate(o1.getReleaseDate());

                                     time2= CalendarUtil.parseShortDate(o2.getReleaseDate());

                                     if(time1 == null && time2 != null)

                                               return1;

                                     if(time2 == null && time1 != null)

                                               return-1;

                                     if(time2 == null && time1 == null)

                                               return0;

                            }

                   }catch (Exception e) {

                            return0;

                   }

                   try{

                            return-time1.compareTo(time2);

                   }catch (Exception e) {

                            return0;

                   }

         }

}

 

 

 

 

 

   private List<Model> order(String p, String o,

         List<Model>modelList){

      if ("1".equals(o)&& videoList != null && !videoList.isEmpty()) {

         System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");

         Collections.sort(videoList,newTimeComparator(0)); // 按着修改时间

      }elseif("2".equals(o)&& modelList!= null && !videoList.isEmpty()) {

         System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");

         Collections.sort(modelList,newTimeComparator(1)); // 按着创建时间

      }elseif("3".equals(o)&& videoList != null && ! modelList.isEmpty()) {

         System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");

         Collections.sort(videoList,newTimeComparator(2)); // 按着发布时间

      }

       if(videoList != null && ! modelList.isEmpty()){

          int limit = Integer.valueOf(p);

         int begin = 0;

         int end = Math.min(begin+ limit, videoList.size());

         if(begin > end){

            returnnull;

         }

         returnmodelList.subList(begin, end);

       }

      returnnull;

   }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    文章分类
    最新评论