MCPcopy Create free account
hub / github.com/SeanDragon/protools / ToolFormat

Class ToolFormat

common/src/main/java/pro/tools/format/ToolFormat.java:9–82  ·  view source on GitHub ↗

格式化工具,数字、字符串、Object类型之间的常用转换 Created by Administrator on 2016/3/7. @author Steven Duan @version 1.0

Source from the content-addressed store, hash-verified

7 * @version 1.0
8 */
9public final class ToolFormat {
10
11 private ToolFormat() {
12 throw new UnsupportedOperationException("我是工具类,别初始化我。。。");
13 }
14
15 /**
16 * 判断是否为空 ,
17 *
18 * @param arg
19 * 要判断的值
20 *
21 * @return 为空返回true, 否则返回false
22 */
23 public static boolean isEmpty(Object arg) {
24 return toStringTrim(arg).length() == 0;
25 }
26
27 /**
28 * Object 转换成 String 为null 返回空字符,使用:toString(值,默认值[选填])
29 *
30 * @param args
31 * 参数序列
32 *
33 * @return 返回转换后的String
34 */
35 public static String toString(Object... args) {
36 String def = "";
37 if (args != null) {
38 if (args.length > 1) {
39 def = toString(args[args.length - 1]);
40 }
41 Object obj = args[0];
42 if (obj == null) {
43 return def;
44 }
45 return obj.toString();
46 } else {
47 return def;
48 }
49 }
50
51 /**
52 * Object 转换成 String[去除所以空格]; 为null 返回空字符,使用:toStringTrim(值,默认值[选填])
53 *
54 * @param args
55 * 参数序列
56 *
57 * @return 返回转换后的String
58 */
59 public static String toStringTrim(Object... args) {
60 String str = toString(args);
61 return str.replaceAll("\\s*", "");
62 }
63
64 /**
65 * 获取人性化的异常信息
66 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected