package me.zhyd.oauth.utils; import java.nio.charset.StandardCharsets; import java.util.concurrent.ThreadLocalRandom; /** * @author yadong.zhang (yadong.zhang0415(a)gmail.com) * @since 1.0.0 */ public class StringUtils { public static boolean isEmpty(String str) { return null == str || str.isEmpty(); } public static boolean isNotEmpty(String str) { return !isEmpty(str); } /** * 如果给定字符串{@code str}中不包含{@code appendStr},则在{@code str}后追加{@code appendStr}; * 如果已包含{@code appendStr},则在{@code str}后追加{@code otherwise} * * @param str 给定的字符串 * @param appendStr 需要追加的内容 * @param otherwise 当{@code appendStr}不满足时追加到{@code str}后的内容 * @return 追加后的字符串 */ public static String appendIfNotContain(String str, String appendStr, String otherwise) { if (isEmpty(str) || isEmpty(appendStr)) { return str; } if (str.contains(appendStr)) { return str.concat(otherwise); } return str.concat(appendStr); } }