package hjp.smart4j.framework.util;import org.apache.commons.lang3.StringUtils;/*** 字符串工具类*/
public final class StringUtil {/*** 字符串分隔符*/public static final String SEPARATOR=String.valueOf((char)29);/*** 判断字符串是否为空*/public static boolean isEmpty(String str) {if (str != null) {str = str.trim();}return StringUtils.isEmpty(str);}/*** 判断字符串是否非空*/public static boolean isNotEmpty(String str) {return !isEmpty(str);}/*** 分割固定格式字符串*/public static String[] splitString(String str,String separator){return StringUtils.splitByWholeSeparator(str,separator);}
}

StringUtil

package hjp.smart4j.framework.util;import org.apache.commons.lang3.ArrayUtils;/*** 数组工具类*/
public final class ArrayUtil {/*** 判断数组是否非空*/public static boolean isNotEmpty(Object[] array){return !ArrayUtils.isEmpty(array);}/*** 判断数组是否为空*/public static boolean isEmpty(Object[] array){return ArrayUtils.isEmpty(array);}}

ArrayUtil

package hjp.smart4j.framework.util;import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;import java.util.Collection;
import java.util.Map;/*** 集合工具类*/
public final class CollectionUtil {/*** 判断Collection是否为空*/public static boolean isEmpty(Collection<?> collection) {return CollectionUtils.isEmpty(collection);}/*** 判断Collection是否非空*/public static boolean isNotEmpty(Collection<?> collection) {return !isEmpty(collection);}/*** 判断Map是否为空*/public static boolean isEmpty(Map<?, ?> map) {return MapUtils.isEmpty(map);}/*** 判断Map是否非空*/public static boolean isNotEmpty(Map<?, ?> map) {return !isEmpty(map);}
}

CollectionUtil

package hjp.smart4j.framework.util;/*** 转型操作工具类*/
public final class CastUtil {/*** 转为String型*/public static String castString(Object obj) {return CastUtil.castString(obj, "");}/*** 转为String型(提供默认值)*/public static String castString(Object obj, String defaultValue) {return obj != null ? String.valueOf(obj) : defaultValue;}/*** 转为double型*/public static double castDouble(Object obj) {return CastUtil.castDouble(obj, 0);}/*** 转为double型(指定默认值)*/public static double castDouble(Object obj, double defaultValue) {double doubleValue = defaultValue;if (obj != null) {String strVlaue = castString(obj);if (StringUtil.isNotEmpty(strVlaue)) {try {doubleValue = Double.parseDouble(strVlaue);} catch (NumberFormatException e) {doubleValue = defaultValue;}}}return doubleValue;}/*** 转为long型*/public static long castLong(Object obj) {return castLong(obj, 0);}/*** 转为long型(提供默认值)*/public static long castLong(Object obj, long defaultValue) {long longValue = defaultValue;if (obj != null) {String strValue = castString(obj);if (StringUtil.isNotEmpty(strValue)) {try {longValue = Long.parseLong(strValue);} catch (NumberFormatException e) {longValue = defaultValue;}}}return longValue;}/*** 转为int型*/public static int castInt(Object obj) {return castInt(obj, 0);}/*** 转为int型(提供默认值)*/public static int castInt(Object obj, int defaultValue) {int intValue = defaultValue;if (obj != null) {String strValue = castString(obj);if (StringUtil.isNotEmpty(strValue)) {try {intValue = Integer.parseInt(strValue);} catch (NumberFormatException e) {intValue = defaultValue;}}}return intValue;}/*** 转为boolean型*/public static boolean castBoolean(Object obj) {return castBoolean(obj, false);}/*** 转为boolean型(提供默认值)*/public static boolean castBoolean(Object obj, boolean defaultValue) {boolean booleanValue = defaultValue;if (obj != null) {booleanValue = Boolean.parseBoolean(castString(obj));}return booleanValue;}
}

CastUtil

package hjp.smart4j.framework.util;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.net.URLDecoder;
import java.net.URLEncoder;/*** 编码与解码操作工具类*/
public final class CodecUtil {private static final Logger LOGGER = LoggerFactory.getLogger(CodecUtil.class);/*** 将URL编码*/public static String encodeURL(String source) {String target;try {target = URLEncoder.encode(source, "UTF-8");} catch (Exception e) {LOGGER.error("encode url failure", e);throw new RuntimeException(e);}return target;}/*** 将URL解码*/public static String decodeURL(String source) {String target;try {target = URLDecoder.decode(source, "UTF-8");} catch (Exception e) {LOGGER.error("decode url failure", e);throw new RuntimeException(e);}return target;}}

CodecUtil

字符串工具类、数组工具类、集合工具类、转型操作工具类、编码与解码操作工具类...相关推荐

  1. java list排序工具类_java 之 Collections集合工具类排序

    数组有工具类Arrays,集合也有一个工具类Collections. sort方法: sort(List list):根据其元素natural ordering对制定的列表进行排序 sort(List ...

  2. 宽字符编码和解码通用类[CodeWidthChartUtility]

    在做jsonp传递的时候遇到一个问题,当有特殊字符或中文的时候就会导致数据错误或者是乱码,刚开始有js的编码和解码和正则,都比较麻烦,现在找到了一种合适的解决方案,宽字符编码,js端会自动解析,能处理 ...

  3. URL编码和解码 C++类URL编码和解码使用技巧

    想了解C++类URL编码和解码使用技巧的相关内容吗,在本文为您仔细讲解URL编码和解码的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:URL编码,解码,下面大家一起来学习吧. 在项目开发过 ...

  4. 小汤学编程之JAVA基础day11——集合框架:List/Set/Map集合、Collections集合工具类、泛型、TreeMap和TreeSet

    一.集合的特点 二.继承结构图 三.List集合 1.特点     2.ArrayList类     3.LinkedList类     4.两者的对比     5.集合的遍历 四.Set集合 1.特 ...

  5. 将类数组转换成数组的方法

    类数组的概念: 类数组(ArrayLike)是指:和"数组"类似,有length属性,并且可以通过下标进行访问内部的元素且在写法上跟数组一样,但是不能直接使用数组方法.比如argu ...

  6. JavaScript什么是类数组?

    JavaScript怎么让类数组使用上数组的方法? 什么是类数组? 类数组的组成 类数组的定义 数组丰富的内建方法有哪些? 如何让类数组使用上数组丰富的内建方法? 如果你想进一步的了解为什么可以这么做 ...

  7. js 类数组转成真正的数组的方法

    一.类数组与数组的区别 相同点: 都有 length 属性,都可以用下标访问每一个元素 不同点: 数组的类型是 Array ,类数组的类似是 Object 类数组不具备数组所具备的所有方法 类数组只能 ...

  8. 【EventBus】事件通信框架 ( 订阅类-订阅方法缓存集合 | 事件类型-订阅者集合 | 订阅对象-事件类型集合 )

    文章目录 前言 一.订阅类-订阅方法缓存集合 二.事件类型-订阅者集合 三.订阅对象-事件类型集合 前言 首先声明几个数据结构 , 参考 [EventBus]EventBus 源码解析 ( 注册订阅者 ...

  9. 如何编码和解码base64字符串?

    本文翻译自:How do I encode and decode a base64 string? How do I return a base64 encoded string given a st ...

最新文章

  1. 洛谷 P2867 [USACO06NOV]大广场Big Square
  2. Dom4J读写xml
  3. selenium动态网页爬虫复习
  4. 从网络到分布式-负载均衡
  5. python代码翻译器-10 行代码,Python 教你自制屏幕翻译工具,有逼格!!
  6. 通过docker-composer启动容器nginx,并完成spring.boot的web站点端口转发
  7. ios app上传图片与文件到服务器,iOS开发之上传图片视频到服务器
  8. 【气动学】基于matlab GUI外弹道仿真系统【含Matlab源码 1044期】
  9. C++代码实现 生成器模式
  10. 大三上学期学期总结及百度实习感受
  11. 为什么我说“设计模式”的设计理念是误人子弟?
  12. TCP快速连接(tfo,TCP fastopen)
  13. Linux中存储设备的命名规则
  14. Efforts should be valuable
  15. 清华大学刘知远组:文本分类任务中,将知识融入Prompt-tuning过程
  16. 手机音频AMR格式DIY转换不求人
  17. C语言编程优化运行速度
  18. QQ/微信防撤回插件
  19. LeetCode 137.Single Number II 只出现一次的数字 II
  20. C语言%运算:a%b

热门文章

  1. ASP.NET MVC标记最新的发布新闻或文章
  2. s:if 标签 字符串比较 正确用法和错误用法
  3. [正能量系列]赋闲的程序员(三)
  4. android 中处理崩溃异常并重启程序
  5. IT人的自我导向型学习:学习的1个理念和2个心态
  6. 扫盲 about session,Bean,网关等
  7. 今天mtk笔试,没信心了
  8. TypeReference -- 让Jackson Json在List/Map中识别自己的Object
  9. [Bzoj2282]消防(二分答案+树的直径)
  10. preact源码学习(2)