Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
*
* @param str string
* @return whether the string is null or empty
*/
public static boolean isNullOrEmpty(String str) {
return str == null || str.isEmpty();
}
/**
* If the string is null or empty, this returns default string.
*
* If not, this returns original string.
*
*
*
* @param str original string
* @param defaultValue default string
* @return original string or default string
*/
public static String ifNullOrEmpty(String str, String defaultValue) {
return isNullOrEmpty(str) ? defaultValue : str;
}
/**
* If the string is null or empty, this returns default string.
*
* If not, this returns original string.
*
*
*
* @param str string
* @return whether the string is null or blank
*/
public static boolean isNullOrBlank(String str) {
return str == null || str.trim().isEmpty();
}
/**
* If the string is null or blank, this returns default string.
*
* If not, this returns original string.
*
*
*
* @param str original string
* @param defaultValue default string
* @return original string or default string
*/
public static String ifNullOrBlank(String str, String defaultValue) {
return isNullOrBlank(str) ? defaultValue : str;
}
/**
* If the string is null or blank, this returns default string.
*
* If not, this returns original string.
*
*
*
* @param len targeted string length;
* If it is less than the length of origin string,
* this returns it as it is.
* @param origin string that needs to be padded
* @return padded string
* @see #repeat(String, int)
*/
public static String padStart(int len, String origin) {
return padStart(len, origin, String.valueOf(WHITE_SPACE));
}
/**
* Fills the start of string with another string.
*
*
*
* @param len targeted string length;
* If it is less than the length of origin string,
* this returns it as it is.
* @param origin string that needs to be padded
* @param appendix string to be appended to origin string
* @return padded string
* @see #repeat(String, int)
*/
public static String padStart(int len, String origin, String appendix) {
int originLen = origin.length();
if (originLen >= len) return origin;
return repeat(appendix, len - originLen) + origin;
}
/**
* Fills the end of string with whitespace.
*
*
*
* @param len targeted string length;
* If it is less than the length of origin string,
* this returns it as it is.
* @param origin string that needs to be padded
* @return padded string
* @see #repeat(String, int)
*/
public static String padEnd(int len, String origin) {
return padEnd(len, origin, String.valueOf(WHITE_SPACE));
}
/**
* Fills the end of string with another string.
*
*
*
* @param len targeted string length;
* If it is less than the length of origin string,
* this returns it as it is.
* @param origin string that needs to be padded
* @param appendix string to be appended to origin string
* @return padded string
* @see #repeat(String, int)
*/
public static String padEnd(int len, String origin, String appendix) {
int originLen = origin.length();
if (originLen >= len) return origin;
return origin + repeat(appendix, len - originLen);
}
/**
* Gets the number of strings to be found at origin string.
*
* @param origin origin string
* @param keyword string to be found
* @return count of inclusions
*/
public static int countOf(String origin, String keyword) {
int keywordLen = keyword.length();
int count = 0;
for (int i = origin.indexOf(keyword); i >= 0; i = origin.indexOf(keyword, i + keywordLen)) {
count++;
}
return count;
}
/**
* Reverses all the characters in a string.
*
* @param str string to be reversed
* @return reversed string
* @see StringBuilder#reverse
*/
public static String reverse(String str) {
if (str == null) return null;
return new StringBuilder(str).reverse().toString();
}
/**
* 가장 마지막에 일치하는 문구를 원하는 문구로 대체한다.
*
*
*
* @param amount amount number
* @return formatted number with comma
*/
public static String formatComma(long amount) {
return new DecimalFormat("###,###,###,###,###,###,###").format(amount);
}
/**
* Replicates a string as many times as you want.
*
*
*
* @param str string to be repeated
* @param cnt repetition count
* @return repeated string
*/
public static String repeat(String str, int cnt) {
return String.join("", Collections.nCopies(cnt, str));
}
/**
* Replicates a character as many times as you want.
*
*