260407_02_ENH: String, Numeric 유틸 추가
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
//버전 변경은 여기서
|
||||
def commonVer = "beta.1.1.13"
|
||||
def commonVer = "beta.1.1.14"
|
||||
|
||||
group = 'com.kri.common'
|
||||
version = commonVer
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.common.feature.util;
|
||||
|
||||
import static com.kri.common.feature.util.StringUtil.normalizeBlank;
|
||||
|
||||
public final class NumericUtil {
|
||||
|
||||
private NumericUtil() {
|
||||
@@ -34,6 +36,24 @@ public final class NumericUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer parseOnlyInteger(String s) {
|
||||
String ns = normalizeBlank(s);
|
||||
if (ns == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if (ns.matches("^-?\\d+$")) {
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
if (ns.matches("^-?\\d+\\.0+$")) {
|
||||
return Integer.parseInt(ns.substring(0, ns.indexOf('.')));
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static long safeParseLong(String s, short def) {
|
||||
try {
|
||||
return Long.parseLong(s);
|
||||
|
||||
@@ -5,6 +5,8 @@ public final class StringUtil {
|
||||
private StringUtil() {
|
||||
}
|
||||
|
||||
private static final String BASIC_TEXT_REGEX = "^[가-힣a-zA-Z0-9()_\\-\\[\\] ]+$";
|
||||
|
||||
/** null 또는 "" 인지 */
|
||||
public static boolean isNullOrEmpty(String s) {
|
||||
return s == null || s.isEmpty();
|
||||
@@ -19,4 +21,46 @@ public final class StringUtil {
|
||||
public static boolean hasText(String s) {
|
||||
return s != null && !s.isBlank();
|
||||
}
|
||||
|
||||
public static String normalizeBlank(String raw) {
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
String s = raw.trim();
|
||||
return s.isEmpty() ? null : s;
|
||||
}
|
||||
|
||||
public static String normalizeEmail(String raw) {
|
||||
String s = normalizeBlank(raw);
|
||||
return s == null ? null : s.toLowerCase();
|
||||
}
|
||||
|
||||
public static String normalizeOnlyNumber(String raw) {
|
||||
String s = normalizeBlank(raw);
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
String digits = s.replaceAll("[^0-9]", "");
|
||||
return digits.isBlank() ? null : digits;
|
||||
}
|
||||
|
||||
public static boolean isBasicText(String raw){
|
||||
return isBasicText(raw, BASIC_TEXT_REGEX);
|
||||
}
|
||||
|
||||
public static boolean isBasicText(String raw, String regex){
|
||||
String s = normalizeBlank(raw);
|
||||
if (s == null) {
|
||||
return true;
|
||||
}
|
||||
return s.matches(regex);
|
||||
}
|
||||
|
||||
public static boolean isBasicEmail(String raw) {
|
||||
String s = normalizeBlank(raw);
|
||||
if (s == null) {
|
||||
return true;
|
||||
}
|
||||
return s.matches("^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user