非空判断工具类

package com.common.utils;


import com.common.pojo.ResResultDto;

import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;

/**
 * @author  nachuan
 * 判断 String int  Collection 是否为空
 */
public class EmptyUtils implements Serializable {
    /**
     * 获取String不为空
     * @param cs
     * @return
     */
    public static boolean isNotEmpty(CharSequence  cs) {
      return  !isEmpty(cs);
    }
    /**
     * 获取String为空
     * @param cs
     * @return
     */
    public static boolean isEmpty(CharSequence cs) {
        int strLen;
        if (cs != null && (strLen = cs.length()) != 0) {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }
            return true;
        } else {
            return true;
        }
    }
    /**
     * 获取interger不为空
     * @param integer
     * @return
     */
    public static boolean isNotEmpty(Integer integer) {
        if (integer != null && isNotEmpty(integer.toString())) {
            return true;
        }else {
            return false;
        }
    }
    /**
     * 获取interger为空
     * @param integer
     *
     * @return
     */
    public static boolean isEmpty(Integer integer) {
        boolean b = isEmpty(integer.toString());
        if (integer == null ||(integer != null && b)) {
            return true;
        }else {
            return false;
        }
    }
    /**
     * 获取集合类是否不为空
     * @param collection
     * @return
     */
    public static boolean isNotEmpty(Collection<?> collection) {
        return  !isEmpty(collection);


    }
    /**
     * 获取集合类是否为空
     * @param collection
     * @return
     */
    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();

    }

    /**
     * 获取集合类是否为空
     * @param str
     * @return
     */
    public static ResResultDto str2num(String str) {
        ResResultDto dto = new ResResultDto();
        if (EmptyUtils.isNotEmpty(str)) {
            Integer integer = null;
            try {
                integer = Integer.valueOf(str);
                dto.setStatus(0);
                dto.setMsg("强转成功");
                dto.setObj(integer);
                return dto;
            } catch (NumberFormatException e) {
                e.printStackTrace();
                dto.setMsg("强转异常,参数非法,不是数字类型");
                dto.setStatus(2001);
                return dto;
            }
        }else {
            dto.setMsg("参数为空");
            dto.setStatus(5001);
            return dto;
        }


    }

   
    public static String trimAll(String str ){
        return str.trim()
                .replaceAll("[ *| *| *|//s*]*", "")
                .replaceAll("^[ *| *| *|//s*]*", "")
                .replaceAll("[ *| *| *|//s*]*$", "");
    }

    public static String addOrderStr2Select(String s) {
        s = s.toLowerCase().replaceAll(" +"," ");
        String[] s2 = s.split(" ");
        String orderStr = "";
        for (int i = 0; i < s2.length; i++) {
            if (Objects.equals("by", s2[i])) {
                orderStr = s2[i+1];
                if (Objects.equals(",",s2[i+2])){

                }


                break;
            }

        }
        return s.replace("select","select " + orderStr + "," );
    }

}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值