|
@@ -29,7 +29,10 @@ import java.util.regex.Pattern;
|
|
|
* @Date 2016-08-18
|
|
|
*/
|
|
|
public class StringUtils {
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 空字符
|
|
|
+ */
|
|
|
public static final String EMPTY = "";
|
|
|
|
|
|
/**
|
|
@@ -37,10 +40,6 @@ public class StringUtils {
|
|
|
*/
|
|
|
public static final char UNDERLINE = '_';
|
|
|
|
|
|
- /**
|
|
|
- * 空字符串
|
|
|
- */
|
|
|
- public static final String EMPTY_STRING = "";
|
|
|
/**
|
|
|
* 占位符
|
|
|
*/
|
|
@@ -92,7 +91,7 @@ public class StringUtils {
|
|
|
*/
|
|
|
public static String camelToUnderline(String param) {
|
|
|
if (isEmpty(param)) {
|
|
|
- return EMPTY_STRING;
|
|
|
+ return EMPTY;
|
|
|
}
|
|
|
int len = param.length();
|
|
|
StringBuilder sb = new StringBuilder(len);
|
|
@@ -117,7 +116,7 @@ public class StringUtils {
|
|
|
*/
|
|
|
public static String underlineToCamel(String param) {
|
|
|
if (isEmpty(param)) {
|
|
|
- return EMPTY_STRING;
|
|
|
+ return EMPTY;
|
|
|
}
|
|
|
int len = param.length();
|
|
|
StringBuilder sb = new StringBuilder(len);
|
|
@@ -263,7 +262,7 @@ public class StringUtils {
|
|
|
*/
|
|
|
public static String concatCapitalize(String concatStr, final String str) {
|
|
|
if (isEmpty(concatStr)) {
|
|
|
- concatStr = EMPTY_STRING;
|
|
|
+ concatStr = EMPTY;
|
|
|
}
|
|
|
int strLen;
|
|
|
if (str == null || (strLen = str.length()) == 0) {
|
|
@@ -306,6 +305,7 @@ public class StringUtils {
|
|
|
}
|
|
|
return object == null ? false : true;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 判断对象是否为空
|
|
@@ -318,79 +318,98 @@ public class StringUtils {
|
|
|
return !checkValNotNull(object);
|
|
|
}
|
|
|
|
|
|
- // endsWith
|
|
|
- //-----------------------------------------------------------------------
|
|
|
+ // endsWith
|
|
|
+ // -----------------------------------------------------------------------
|
|
|
|
|
|
- /**
|
|
|
- * <p>Check if a String ends with a specified suffix.</p>
|
|
|
- *
|
|
|
- * <p><code>null</code>s are handled without exceptions. Two <code>null</code>
|
|
|
- * references are considered to be equal. The comparison is case sensitive.</p>
|
|
|
- *
|
|
|
- * <pre>
|
|
|
- * StringUtils.endsWith(null, null) = true
|
|
|
- * StringUtils.endsWith(null, "abcdef") = false
|
|
|
- * StringUtils.endsWith("def", null) = false
|
|
|
- * StringUtils.endsWith("def", "abcdef") = true
|
|
|
- * StringUtils.endsWith("def", "ABCDEF") = false
|
|
|
- * </pre>
|
|
|
- *
|
|
|
- * @see java.lang.String#endsWith(String)
|
|
|
- * @param str the String to check, may be null
|
|
|
- * @param suffix the suffix to find, may be null
|
|
|
- * @return <code>true</code> if the String ends with the suffix, case sensitive, or
|
|
|
- * both <code>null</code>
|
|
|
- * @since 2.4
|
|
|
- */
|
|
|
- public static boolean endsWith(String str, String suffix) {
|
|
|
- return endsWith(str, suffix, false);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ * Check if a String ends with a specified suffix.
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * <p>
|
|
|
+ * <code>null</code>s are handled without exceptions. Two <code>null</code>
|
|
|
+ * references are considered to be equal. The comparison is case sensitive.
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * <pre>
|
|
|
+ * StringUtils.endsWith(null, null) = true
|
|
|
+ * StringUtils.endsWith(null, "abcdef") = false
|
|
|
+ * StringUtils.endsWith("def", null) = false
|
|
|
+ * StringUtils.endsWith("def", "abcdef") = true
|
|
|
+ * StringUtils.endsWith("def", "ABCDEF") = false
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @see java.lang.String#endsWith(String)
|
|
|
+ * @param str
|
|
|
+ * the String to check, may be null
|
|
|
+ * @param suffix
|
|
|
+ * the suffix to find, may be null
|
|
|
+ * @return <code>true</code> if the String ends with the suffix, case
|
|
|
+ * sensitive, or both <code>null</code>
|
|
|
+ * @since 2.4
|
|
|
+ */
|
|
|
+ public static boolean endsWith(String str, String suffix) {
|
|
|
+ return endsWith(str, suffix, false);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * <p>Case insensitive check if a String ends with a specified suffix.</p>
|
|
|
- *
|
|
|
- * <p><code>null</code>s are handled without exceptions. Two <code>null</code>
|
|
|
- * references are considered to be equal. The comparison is case insensitive.</p>
|
|
|
- *
|
|
|
- * <pre>
|
|
|
- * StringUtils.endsWithIgnoreCase(null, null) = true
|
|
|
- * StringUtils.endsWithIgnoreCase(null, "abcdef") = false
|
|
|
- * StringUtils.endsWithIgnoreCase("def", null) = false
|
|
|
- * StringUtils.endsWithIgnoreCase("def", "abcdef") = true
|
|
|
- * StringUtils.endsWithIgnoreCase("def", "ABCDEF") = false
|
|
|
- * </pre>
|
|
|
- *
|
|
|
- * @see java.lang.String#endsWith(String)
|
|
|
- * @param str the String to check, may be null
|
|
|
- * @param suffix the suffix to find, may be null
|
|
|
- * @return <code>true</code> if the String ends with the suffix, case insensitive, or
|
|
|
- * both <code>null</code>
|
|
|
- * @since 2.4
|
|
|
- */
|
|
|
- public static boolean endsWithIgnoreCase(String str, String suffix) {
|
|
|
- return endsWith(str, suffix, true);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ * Case insensitive check if a String ends with a specified suffix.
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * <p>
|
|
|
+ * <code>null</code>s are handled without exceptions. Two <code>null</code>
|
|
|
+ * references are considered to be equal. The comparison is case
|
|
|
+ * insensitive.
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * <pre>
|
|
|
+ * StringUtils.endsWithIgnoreCase(null, null) = true
|
|
|
+ * StringUtils.endsWithIgnoreCase(null, "abcdef") = false
|
|
|
+ * StringUtils.endsWithIgnoreCase("def", null) = false
|
|
|
+ * StringUtils.endsWithIgnoreCase("def", "abcdef") = true
|
|
|
+ * StringUtils.endsWithIgnoreCase("def", "ABCDEF") = false
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @see java.lang.String#endsWith(String)
|
|
|
+ * @param str
|
|
|
+ * the String to check, may be null
|
|
|
+ * @param suffix
|
|
|
+ * the suffix to find, may be null
|
|
|
+ * @return <code>true</code> if the String ends with the suffix, case
|
|
|
+ * insensitive, or both <code>null</code>
|
|
|
+ * @since 2.4
|
|
|
+ */
|
|
|
+ public static boolean endsWithIgnoreCase(String str, String suffix) {
|
|
|
+ return endsWith(str, suffix, true);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * <p>Check if a String ends with a specified suffix (optionally case insensitive).</p>
|
|
|
- *
|
|
|
- * @see java.lang.String#endsWith(String)
|
|
|
- * @param str the String to check, may be null
|
|
|
- * @param suffix the suffix to find, may be null
|
|
|
- * @param ignoreCase inidicates whether the compare should ignore case
|
|
|
- * (case insensitive) or not.
|
|
|
- * @return <code>true</code> if the String starts with the prefix or
|
|
|
- * both <code>null</code>
|
|
|
- */
|
|
|
- private static boolean endsWith(String str, String suffix, boolean ignoreCase) {
|
|
|
- if (str == null || suffix == null) {
|
|
|
- return (str == null && suffix == null);
|
|
|
- }
|
|
|
- if (suffix.length() > str.length()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- int strOffset = str.length() - suffix.length();
|
|
|
- return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length());
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ * Check if a String ends with a specified suffix (optionally case
|
|
|
+ * insensitive).
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @see java.lang.String#endsWith(String)
|
|
|
+ * @param str
|
|
|
+ * the String to check, may be null
|
|
|
+ * @param suffix
|
|
|
+ * the suffix to find, may be null
|
|
|
+ * @param ignoreCase
|
|
|
+ * inidicates whether the compare should ignore case (case
|
|
|
+ * insensitive) or not.
|
|
|
+ * @return <code>true</code> if the String starts with the prefix or both
|
|
|
+ * <code>null</code>
|
|
|
+ */
|
|
|
+ private static boolean endsWith(String str, String suffix, boolean ignoreCase) {
|
|
|
+ if (str == null || suffix == null) {
|
|
|
+ return (str == null && suffix == null);
|
|
|
+ }
|
|
|
+ if (suffix.length() > str.length()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int strOffset = str.length() - suffix.length();
|
|
|
+ return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length());
|
|
|
+ }
|
|
|
|
|
|
}
|