StringUtils.java 1.1 KB
Newer Older
智布道's avatar
智布道 已提交
1 2
package me.zhyd.oauth.utils;

3 4 5
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ThreadLocalRandom;

智布道's avatar
智布道 已提交
6 7
/**
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
8
 * @since 1.0.0
智布道's avatar
智布道 已提交
9 10 11 12 13 14 15 16 17 18
 */
public class StringUtils {

    public static boolean isEmpty(String str) {
        return null == str || str.isEmpty();
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

    /**
     * 如果给定字符串{@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);
    }

智布道's avatar
智布道 已提交
39
}