zoukankan      html  css  js  c++  java
  • ListUtil常用操作

        /**
         * 获取列表总页数
         */
        public static <T> int getListPages(List<T> list,int pageNum,int pageSize ){
            if (isNull(list)){
                return 0;
            }
            BaseQuery baseQuery=new BaseQuery();
            baseQuery.setPageNum(pageNum);
            baseQuery.setPageSize(pageSize);
            //list的大小
            int total = list.size();
            baseQuery.setTotal(total);
            return baseQuery.getPages();
        }
    
    
    
    
        /**
         * 对列表进行分页,索引左边包括,右边不包括
         */
        public static <T> List<T> subListByPage(List<T> list,int pageNum,int pageSize ){
            if (isNull(list)){
                return Collections.emptyList();
            }
            BaseQuery baseQuery=new BaseQuery();
            baseQuery.setPageNum(pageNum);
            baseQuery.setPageSize(pageSize);
            //list的大小
            int total = list.size();
            //对list进行截取
            return list.subList(baseQuery.getStartPosition(),total-baseQuery.getStartPosition()>baseQuery.getPageSize()?baseQuery.getStartPosition()+baseQuery.getPageSize():total);
        }
    
        /**
         * 对列表进行索引截取,索引左边包括,右边不包括
         */
        public static <T> List<T> subListByPosition(List<T> list,BaseQuery baseQuery){
    
            if (isNull(list)){
                baseQuery.setTotal(0);
                return Collections.emptyList();
            }
            //设置列表总条数
            int total = list.size();
            baseQuery.setTotal(total);
    
            if ((baseQuery.getStartIndex()-1)>=total){
                return Collections.emptyList();
            }
            //对list进行截取
            return list.subList(baseQuery.getStartIndex()-1,baseQuery.getEndIndex()>total?total:baseQuery.getEndIndex());
        }
    
    
        /**
         *对列表字段进行比较排序
         */
        public static <T> void sortByField(List<T> dtoList,String fieldName,String order) {
            int compare=1;
            if ("desc".equals(order)){
                compare=-1;
            }
            int finalCompare = compare;
    
            Collections.sort(dtoList, new Comparator<T>() {
                @Override
                public int compare(T o1, T o2) {
                    PropertyDescriptor pd1 = null;
                    PropertyDescriptor pd2 = null;
                    Object value1 =null;
                    Object value2 =null;
                    try {
                        pd1 = new PropertyDescriptor(fieldName, o1.getClass());
                        value1 = pd1.getReadMethod().invoke(o1, null);
    
                        pd2 = new PropertyDescriptor(fieldName, o2.getClass());
                        value2 = pd2.getReadMethod().invoke(o2, null);
    
                    } catch (IntrospectionException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
    
                     if (value1.getClass().equals(Double.class)){
                        System.out.println(2);
                        if ((Double)value1 > (Double)value2) {
                            return finalCompare;
                        } else if ((Double)value1 < (Double)value2) {
                            return -finalCompare;
                        }
                    }else if (value1.getClass().equals(Integer.class)){
                        System.out.println(4);
                        if ((Integer)value1 > (Integer)value2) {
                            return finalCompare;
                        } else if ((Integer)value1 < (Integer)value2) {
                            return -finalCompare;
                        }
                    }
                    return 0;
                }
            });
        }
  • 相关阅读:
    11-基于CPCI的中频功率放大收发板
    10-基于TMS320C6678+XC7K325T的6U CPCI Full Camera Link图像处理平台
    141-FMC141-4路 250Msps/16bits ADC, FMC板卡
    125-FMC125-两路125Msps AD,两路160Msps DA FMC子卡模块
    164-基于TI DSP TMS320C6455和Altera FPGA EP2S130的Full CameraLink PDS150接口板卡
    北京太速科技有限公司 layout 事业部
    20-基于 DSP TMS320C6455的6U CPCI高速信号处理板卡
    64-基于TMS320C6455、XC5VSX95T 的6U CPCI无线通信处理平台
    18-基于双TMS320C6678 DSP的3U VPX的信号处理平台
    202-基于TI DSP TMS320C6678、Xilinx K7 FPGA XC72K325T的高速数据处理核心板
  • 原文地址:https://www.cnblogs.com/kesimin/p/9547669.html
Copyright © 2011-2022 走看看