文字列を判断するクラス

来源:互联网 发布:寻找客户的软件 编辑:程序博客网 时间:2024/05/01 06:54

/**
 * 文字列を判断するクラス<BR>
 *
 * <PRE>
 * 文字列を判断する
 * </PRE>
 *
 * @author TCI xxx 2011/12/23
 *
 */
public final class StringUtil {
    /**
     * 文字列のNullの判断
     *
     * @param _str
     *            文字列
     * @return 文字列のNullの判断の結果
     */
    public static boolean isNull(String _str) {
        return _str == null;
    }

    /**
     * 文字列の空白文字列の判断
     *
     * @param _str
     *            文字列
     * @return 文字列の空白文字列の判断の結果
     */
    public static boolean isBlank(String _str) {
        return "".equals(_str);
    }

    /**
     * 文字列の内容の判断
     *
     * @param _str
     *            文字列
     * @return 文字列の内容の判断の結果
     */
    public static boolean isEmpty(String _str) {
        return isNull(_str) || isBlank(_str);
    }

    /**
     * 2つの文字列の比較
     *
     * @param _str1
     *            文字列1
     * @param _str2
     *            文字列2
     * @return 2つの文字列の比較の結果
     */
    public static boolean isEquals(String _str1, String _str2) {
        boolean equals = false;
        // 2つすべて文字列のNullの判断
        if (isNull(_str1) && isNull(_str2)) {
            return true;
        }
        // 2つ中の一つ文字列のNullの判断
        if (isNull(_str1) || isNull(_str2)) {
            return false;
        }
        // 2つの文字列の比較
        if (_str1.equals(_str2)) {
            equals = true;
        }
        return equals;

    }

    /**
     * Blankに文字列の内容Nullを変換するメソッド
     *
     * @param _str
     *            文字列
     * @return 文字列の内容の書式を変換する結果
     */
    public static String numberFormatNullToBlank(String _str) {
        if (isNull(_str)) {
            return "";
        }
        return _str;
    }
}