package com.xcesys.extras.core.util.excel;
import java.util.Collection;
import java.util.Map;
/**
*
* @author sun
*
*/
public class StringUtils {
StringUtils() {
}
if (isEmpty(o)) {
return o.toString();
}
return "";
}
public static boolean isEmpty
(Object object
) {
if (object != null) {
return true;
}
return false;
}
public static <T, S extends T> T defaultIfNull(T object, S defaultValue) {
return object == null ? defaultValue : object;
}
/**
* @return 将str转换为Long类型,空或异常则返回null
*/
try {
return isBlank
(str
) ? null : Long.
parseLong(str
);
}
return null;
}
/**
* @return 判断是否为null或空字符串或由空白符构成
*/
public static boolean isBlank
(String str
) {
return str == null || "".equals(str.trim());
}
/**
* @return 将str转换为Double类型,空或异常则返回null
*/
try {
return isBlank
(str
) ? null : Double.
parseDouble(str
);
}
return null;
}
public static String bytesToString
(byte[] bytes
) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
if ((bytes[i] & 0xff) < 16) {
sb.append("0");
}
sb.
append(Long.
toString(bytes
[i
] & 0xff,
16));
}
return sb.toString();
}
public static long serialVersionUID
(String svnRevision
) {
try {
return Long.
parseLong(svnRevision.
replaceAll("\\D",
""));
return 0L;
}
}
if (name.
length() == 1 || (name.
length() > 1 && !Character.
isUpperCase(name.
charAt(1)))) {
return name.substring(0, 1).toLowerCase() + name.substring(1);
}
return name;
}
@SuppressWarnings({"rawtypes" })
public static boolean IsNullOrEmpty
(Object v
) {
if (IsNull(v)) {
} else if (v
instanceof String) {
return ((String) v
).
trim().
length() == 0;
} else if (v
instanceof Map) {
return ((Map) v
).
size() == 0;
} else if (v.getClass().isArray()) {
return ((Object[]) v
).
length == 0;
}
}
public static boolean IsNull
(Object v
) {
return v == null;
}
public static boolean IsInteger
(Object v
) {
if ("".equals(s)) {
return false;
}
if ((s != null) && ("".equals(s)))
return s.matches("^[0-9]*$");
return true;
}
public static int toInteger
(Object v
) {
if (IsInteger(v)) {
return Integer.
valueOf(toString
(v
));
} else {
return 0;
}
}
public static int toInteger
(String v
) {
if (IsInteger(v)) {
return Integer.
valueOf(toString
(v
));
} else {
return 1;
}
}
}