1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 字符串工具类 数组工具类 集合工具类 转型操作工具类 编码与解码操作工具类...

字符串工具类 数组工具类 集合工具类 转型操作工具类 编码与解码操作工具类...

时间:2019-02-22 22:10:26

相关推荐

字符串工具类 数组工具类 集合工具类 转型操作工具类 编码与解码操作工具类...

package hjp.smart4j.framework.util;import mons.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 mons.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 mons.collections4.CollectionUtils;import mons.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 .URLDecoder;import .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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。