File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package com.munjaon.client.util;
import com.munjaon.client.server.packet.Packet;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public final class MessageUtil {
public static String getDateFormat(String format) {
return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format));
}
/**
* DateFormat : yyyyMMdd
* @return
*/
public static String getDate() {
return getDateFormat("yyyyMMdd");
}
/**
* DateFormat : yyyyMMddHHmmss
* @return
*/
public static String getTime() {
return getDateFormat("yyyyMMddHHmmss");
}
public static String doNumber(String spell){
StringBuilder phoneNumber = new StringBuilder();
if (spell == null){
return phoneNumber.toString();
}
spell = spell.trim();
int spell_Length = spell.length();
if (spell_Length < 1){
return phoneNumber.toString();
}
for (int i=0; i<spell_Length; i++){
char eachChar = spell.charAt(i);
if( 0x30 <= eachChar && eachChar <= 0x39 ){
phoneNumber.append(eachChar);
}
}
return phoneNumber.toString();
}
// 소수점 뒤에 해당하는 자리만큼 자르기
public static String cutFloatNumber(String srcNum, int digit){
String headNum = "";
String tailNum = "";
String retNum = "";
if(!(srcNum == null || srcNum.trim().isEmpty())){
srcNum = srcNum.trim();
int index = srcNum.indexOf(".");
// 소수점 위치가 0보다 큰경우만 처리
if(index > 0){
headNum = srcNum.substring(0, index);
tailNum = srcNum.substring((index + 1));
if (tailNum.isEmpty()) {
tailNum = "0";
}
if(tailNum.length() > digit){
tailNum = tailNum.substring(0, digit);
}
retNum = headNum + "." + tailNum;
}
}
return retNum;
}
// 수신번호 체크하기
public static boolean checkPhone(String src) {
if(src == null || src.trim().length() < 10) {
return false;
}
return src.startsWith("0");
}
// 문자열 공백 제거
public static String trim(String obj) {
return StringUtil.trim(obj);
}
public static boolean isEmptyForMessage(String obj, boolean trimFlag) {
if (trimFlag)
return obj == null || obj.trim().isEmpty();
else
return obj == null || obj.isEmpty();
}
public static boolean isEmptyForMessage(String obj) {
return isEmptyForMessage(obj, false);
}
public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) throws UnsupportedEncodingException {
if (isEmptyForMessage(obj, trimFlag)) {
return true;
}
return obj.getBytes(Packet.AGENT_CHARACTER_SET).length > limitCount;
}
public static boolean isOverByteForMessage(String obj, int limitCount) throws UnsupportedEncodingException {
return isOverByteForMessage(obj, limitCount, false);
}
}