zoukankan      html  css  js  c++  java
  • 22 java常用方法

     /**
         * 通过正则获取该目录下满足条件的所有目录
         * @param luceneFilePathRegular  正则目录,如/user/solrindex/正则表达式
         * @return 满足正则表达式的目录集合 list
         */
        public static List<String> fetchDirByRegularLinux(String luceneFilePathRegular){
            List<String> list=new ArrayList<>();
            //分割获取主目录
            int len= luceneFilePathRegular.lastIndexOf(EtlConstants.LINUX_ROUTE_SEGMENT)+1;
            String mainDir=luceneFilePathRegular.substring(0, len);
            String regular=luceneFilePathRegular.substring(len,luceneFilePathRegular.length());
            File dir=new File(mainDir);
            if(dir.exists() && dir.isDirectory()){
                File [] arr= dir.listFiles();
                for (File file : arr) {
                    if (file.exists() && file.isDirectory()) {
                        String fileName = file.getName();
                        if (matchStr(fileName, regular)) {
                            list.add(file.getAbsolutePath()+SolrUtil.INDEX_DIR_SUFFIX);
                        }
                    }
                }
            }
            if(list.size()>0){
                LOGGER.info("通过正则匹配到的Solr目录有:");
                for (String s : list) {
                    LOGGER.info(s);
                }
            }else{
                LOGGER.error("路径{}下,不存在满足正则:{}条件的目录", dir, regular);
            }
            return  list;
        }
        /**
         * @Method Description:按正则表示是匹配字符串
         * @param str
         * @param regular
         * @return
         */
        public static Boolean matchStr(String str, String regular) {
            Pattern pattern = Pattern.compile(regular);
            Matcher matcher = pattern.matcher(str);
            return matcher.matches();
        }
    
        /**
         * base的exponent次方
         * @param base
         * @param exponent
         * @return
         */
        public static int pow(int base,int exponent){
            int result=1;
            for(int i=0;i<exponent;i++){
                result=result*base;
            }
            return result;
        }
    public static final Map<String, Long> DATE_MAP = new HashMap<String, Long>() {
            {
                put("month", 1000 * 60 * 60 * 24L);
                put("day", 1000 * 60 * 60 * 24L);
                put("hour", 1000 * 60 * 60L);
            }
        };
    /**
         * 把字符串转化成指定位数size
         * 不足,前面补充supplementValue
         * 超出,isCutFront为true截取前面的size位
         * @param original
         * @param size
         * @param supplementValue
         * @return
         */
        public static String supplementStringFront(String original,int size,String supplementValue){
            return cutString(original,size,true,supplementValue,true);
        }
        /**
    
         * @param original
         * @param size
         * @param supplementValue
         * @param front
         * @return
         */
        /**
         * 把字符串转化成指定位数size
         * 不足,isFrontSupplement为true,前面补充supplementValue,isFrontSupplement为false,后面补充supplementValue
         * 超出,isCutFront为true截取前面的size位,isCutFront为false,截取后面的size位
         * @param original
         * @param size
         * @param isFrontSupplement
         * @param supplementValue
         * @param isCutFront
         * @return
         */
        public static String cutString(String original,int size,Boolean isFrontSupplement,String supplementValue,Boolean isCutFront){
            int length=original.length();
            String result = null;
            if(length==size){
                result=original;
            }else if(length<size){
                if(isFrontSupplement){
                    result=supplementValue+original;
                    while(result.length()<size){
                        result=supplementValue+result;
                    }
                }else{
                    result=original+supplementValue;
                    while(result.length()<size){
                        result=result+supplementValue;
                    }
                }
            }
            //length>size
            else{
                if(isCutFront){
                    result=original.substring(0,size);
                }else {
                    result=original.substring(original.length()-size,original.length());
                }
            }
            return  result;
        }
  • 相关阅读:
    css3
    ubuntu /mac 终端命令大全
    MarkDown的语法的简要规则
    向github上传一个项目
    datatable 去掉默认功能
    datatable 自定义筛选
    vuex
    es6入门教程
    datatable 指定添加排序,根据列的值来设置颜色
    在ios上块点击出现闪黑底
  • 原文地址:https://www.cnblogs.com/yangh2016/p/6044146.html
Copyright © 2011-2022 走看看