260219_01_ENH: 유틸 분리 및 StringUtil 생성
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//버전 변경은 여기서
|
//버전 변경은 여기서
|
||||||
def commonVer = "beta.1.0.64"
|
def commonVer = "beta.1.0.66"
|
||||||
|
|
||||||
group = 'com.kri.common'
|
group = 'com.kri.common'
|
||||||
version = commonVer
|
version = commonVer
|
||||||
|
|||||||
@@ -4,44 +4,10 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public final class CommonUtil {
|
public final class CommonUtil {
|
||||||
|
|
||||||
|
private CommonUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
public static String uuid32() {
|
public static String uuid32() {
|
||||||
return UUID.randomUUID().toString().replace("-", "");
|
return UUID.randomUUID().toString().replace("-", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNumeric(String s) {
|
|
||||||
if (s == null || s.isBlank()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
|
||||||
char c = s.charAt(i);
|
|
||||||
if (c < '0' || c > '9') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static short safeParseShort(String s, short def) {
|
|
||||||
try {
|
|
||||||
return Short.parseShort(s);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int safeParseInt(String s, short def) {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(s);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long safeParseLong(String s, short def) {
|
|
||||||
try {
|
|
||||||
return Long.parseLong(s);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/main/java/com/kri/common/util/NumericUtil.java
Normal file
45
src/main/java/com/kri/common/util/NumericUtil.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package com.kri.common.util;
|
||||||
|
|
||||||
|
public final class NumericUtil {
|
||||||
|
|
||||||
|
private NumericUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNumeric(String s) {
|
||||||
|
if (s == null || s.isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
if (c < '0' || c > '9') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static short safeParseShort(String s, short def) {
|
||||||
|
try {
|
||||||
|
return Short.parseShort(s);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int safeParseInt(String s, short def) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(s);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long safeParseLong(String s, short def) {
|
||||||
|
try {
|
||||||
|
return Long.parseLong(s);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
src/main/java/com/kri/common/util/StringUtil.java
Normal file
22
src/main/java/com/kri/common/util/StringUtil.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package com.kri.common.util;
|
||||||
|
|
||||||
|
public final class StringUtil {
|
||||||
|
|
||||||
|
private StringUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** null 또는 "" 인지 */
|
||||||
|
public static boolean isNullOrEmpty(String s) {
|
||||||
|
return s == null || s.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** null 또는 공백(whitespace)만 있는지 ("" 포함) - Java 11+ */
|
||||||
|
public static boolean isNullOrBlank(String s) {
|
||||||
|
return s == null || s.isBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (옵션) 반대 버전도 같이 두면 실무에서 더 편함 */
|
||||||
|
public static boolean hasText(String s) {
|
||||||
|
return s != null && !s.isBlank();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user