Commit 80ff848d authored by Quxl's avatar Quxl

x

parent c9886ad7
......@@ -14,44 +14,42 @@ import org.dom4j.Element;
public class StringUtil {
public static Double toDouble(String value) {
Double res;
if(value==null||value.equals("")) {
res = 0.0;
}else {
res = Double.valueOf(value);
if (value == null || value.equals("")) {
return null;
} else {
return Double.valueOf(value);
}
return res;
}
public static String prependZero(int Num, int length) {
return prependZero(Num+"", length);
return prependZero(Num + "", length);
}
public static String prependZero(String Num, int length) {
String prepend = "";
for(int i=Num.length(); i<length; i++) {
for (int i = Num.length(); i < length; i++) {
prepend = prepend + "0";
}
return prepend + Num;
}
public static Element getDataElement(String xml, String eName) {
Document doc = null;
Element el = null;
try {
doc = DocumentHelper.parseText(xml);
doc = DocumentHelper.parseText(xml);
Element root = doc.getRootElement();
el = root.element(eName);
} catch (DocumentException e) {
e.printStackTrace();
}
e.printStackTrace();
}
return el;
}
public static String join(String sign, String before, String after, String def, List<String> strs) {
return join(sign, before, after, def, strs.toArray(new String[strs.size()]));
}
public static String join(String sign, String before, String after, String def, String[] strs) {
if (strs == null || strs.length == 0) {
return def == null ? "" : def;
......@@ -59,30 +57,34 @@ public class StringUtil {
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < strs.length; i++) {
String str = String.valueOf(strs[i]);
sb.append((i == 0 && before != null) ? before : "").append(str == null ? "" : str).append(i < strs.length - 1 ? (sign == null ? "" : sign) : "").append((i == strs.length - 1 && after != null) ? after : "");
sb.append((i == 0 && before != null) ? before : "").append(str == null ? "" : str)
.append(i < strs.length - 1 ? (sign == null ? "" : sign) : "")
.append((i == strs.length - 1 && after != null) ? after : "");
}
return String.valueOf(sb);
}
}
public static String join(String str, String sign, int count, String before, String after) {
if (str == null || count == 0) {
return "";
} else {
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < count; i++) {
sb.append(i == 0 && before != null ? before : "").append(str).append(i < count - 1 ? (sign == null ? "" : sign) : "").append(i == count - 1 && after != null ? after : "");
sb.append(i == 0 && before != null ? before : "").append(str)
.append(i < count - 1 ? (sign == null ? "" : sign) : "")
.append(i == count - 1 && after != null ? after : "");
}
return String.valueOf(sb);
}
}
public static String format(Object no, String format) {
String strno = String.valueOf(no);
Integer index = format.length() - strno.length();
return format.substring(0, index) + strno;
}
public static String readText(String path) throws IOException {
BufferedReader br = null;
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment