feat : db polling 맵핑 및 공통, enum 추가
parent
2737b5c51c
commit
31c528abb4
@ -1,10 +1,49 @@
|
||||
package com.worker.util.common;
|
||||
|
||||
import com.worker.util.common.commEnum.DateTimePatternEnum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class CommonUtils {
|
||||
|
||||
/**
|
||||
* 글자 최대수 제한
|
||||
* */
|
||||
public static String truncate(String input, int maxLength) {
|
||||
if (input == null) return null;
|
||||
return input.length() > maxLength ? input.substring(0, maxLength) : input;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 글자 최대수 제한
|
||||
* */
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
package com.worker.util.common.commEnum;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public enum DateTimePatternEnum {
|
||||
DATETIME_FULL("\\d{4}[-/.]\\d{2}[-/.]\\d{2} \\d{2}:\\d{2}:\\d{2}", true),
|
||||
DATE_ONLY("\\d{4}[-/.]\\d{2}[-/.]\\d{2}", true),
|
||||
TIME_ONLY("\\d{2}:\\d{2}:\\d{2}", true);
|
||||
|
||||
|
||||
private final Pattern pattern;
|
||||
private final boolean formatted;
|
||||
|
||||
DateTimePatternEnum(String regex, boolean formatted) {
|
||||
this.pattern = Pattern.compile(regex);
|
||||
this.formatted = formatted;
|
||||
}
|
||||
|
||||
public String format(String raw) {
|
||||
return formatted ? raw.replaceAll("[^0-9]", "") : raw;
|
||||
}
|
||||
|
||||
/** 리스트 추출 */
|
||||
public List<String> extractList(String text) {
|
||||
if (text == null) return List.of();
|
||||
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
List<String> result = new ArrayList<>();
|
||||
while (matcher.find()) {
|
||||
result.add(format(matcher.group()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/** 첫 번째 항목만 추출 (없으면 null) */
|
||||
public String extractFirst(String text) {
|
||||
if (text == null) return null;
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
return matcher.find() ? format(matcher.group()) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue