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

Class ToolRegex

common/src/main/java/pro/tools/data/text/ToolRegex.java:29–375  ·  view source on GitHub ↗

正则相关工具 @author SeanDragon

Source from the content-addressed store, hash-verified

27 * @author SeanDragon
28 */
29public final class ToolRegex {
30
31 private ToolRegex() {
32 throw new UnsupportedOperationException("我是工具类,别初始化我。。。");
33 }
34
35 /**
36 * 判断是否为整数(包括负数)
37 *
38 * @param input
39 * 要判断的数字
40 *
41 * @return 是返回true, 否则返回false
42 */
43 public static boolean isInteger(CharSequence input) {
44 return isNumber(0, input);
45 }
46
47 /**
48 * 判断是否为小数(包括整数,包括负数)
49 *
50 * @param input
51 * 要判断的数字
52 *
53 * @return 是返回true, 否则返回false
54 */
55 public static boolean isDecimal(CharSequence input) {
56 return isNumber(1, input);
57 }
58
59
60 /**
61 * 判断是否为数字
62 *
63 * @param type
64 * 判断类型, 整数为0, 小数为1
65 * @param str
66 * 要判断的数字
67 *
68 * @return 是返回true, 否则返回false
69 */
70 private static boolean isNumber(int type, CharSequence str) {
71 if (ToolStr.isBlank(str.toString())) {
72 return false;
73 }
74 int points = 0;
75 int chr;
76 for (int i = str.length(); --i >= 0; ) {
77 chr = str.charAt(i);
78 // 判断数字
79 if (chr < 48 || chr > 57) {
80 // 判断 - 号
81 if (i == 0 && chr == 45) {
82 return true;
83 }
84 // 判断 . 号
85 if (i >= 0 && chr == 46 && type == 1) {
86 if (++points <= 1) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected