com.jfinal.kit.StrKit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enjoy Show documentation
Show all versions of enjoy Show documentation
Enjoy is a simple, light, rapid, independent, extensible Java Template Engine.
/**
* Copyright (c) 2011-2019, James Zhan 詹波 ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jfinal.kit;
/**
* StrKit.
*/
public class StrKit {
/**
* 首字母变小写
*/
public static String firstCharToLowerCase(String str) {
char firstChar = str.charAt(0);
if (firstChar >= 'A' && firstChar <= 'Z') {
char[] arr = str.toCharArray();
arr[0] += ('a' - 'A');
return new String(arr);
}
return str;
}
/**
* 首字母变大写
*/
public static String firstCharToUpperCase(String str) {
char firstChar = str.charAt(0);
if (firstChar >= 'a' && firstChar <= 'z') {
char[] arr = str.toCharArray();
arr[0] -= ('a' - 'A');
return new String(arr);
}
return str;
}
/**
* 字符串为 null 或者内部字符全部为 ' ' '\t' '\n' '\r' 这四类字符时返回 true
*/
public static boolean isBlank(String str) {
if (str == null) {
return true;
}
int len = str.length();
if (len == 0) {
return true;
}
for (int i = 0; i < len; i++) {
switch (str.charAt(i)) {
case ' ':
case '\t':
case '\n':
case '\r':
// case '\b':
// case '\f':
break;
default:
return false;
}
}
return true;
}
public static boolean notBlank(String str) {
return !isBlank(str);
}
public static boolean notBlank(String... strings) {
if (strings == null || strings.length == 0) {
return false;
}
for (String str : strings) {
if (isBlank(str)) {
return false;
}
}
return true;
}
public static boolean notNull(Object... paras) {
if (paras == null) {
return false;
}
for (Object obj : paras) {
if (obj == null) {
return false;
}
}
return true;
}
public static String toCamelCase(String stringWithUnderline) {
if (stringWithUnderline.indexOf('_') == -1) {
return stringWithUnderline;
}
stringWithUnderline = stringWithUnderline.toLowerCase();
char[] fromArray = stringWithUnderline.toCharArray();
char[] toArray = new char[fromArray.length];
int j = 0;
for (int i=0; i 0) {
sb.append(separator);
}
sb.append(stringArray[i]);
}
return sb.toString();
}
public static boolean slowEquals(String a, String b) {
byte[] aBytes = (a != null ? a.getBytes() : null);
byte[] bBytes = (b != null ? b.getBytes() : null);
return HashKit.slowEquals(aBytes, bBytes);
}
public static boolean equals(String a, String b) {
return a == null ? b == null : a.equals(b);
}
public static String getRandomUUID() {
return java.util.UUID.randomUUID().toString().replace("-", "");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy