Commit 80ff848d authored by Quxl's avatar Quxl

x

parent c9886ad7
...@@ -14,44 +14,42 @@ import org.dom4j.Element; ...@@ -14,44 +14,42 @@ import org.dom4j.Element;
public class StringUtil { public class StringUtil {
public static Double toDouble(String value) { public static Double toDouble(String value) {
Double res; if (value == null || value.equals("")) {
if(value==null||value.equals("")) { return null;
res = 0.0; } else {
}else { return Double.valueOf(value);
res = Double.valueOf(value);
} }
return res;
} }
public static String prependZero(int Num, int length) { public static String prependZero(int Num, int length) {
return prependZero(Num+"", length); return prependZero(Num + "", length);
} }
public static String prependZero(String Num, int length) { public static String prependZero(String Num, int length) {
String prepend = ""; String prepend = "";
for(int i=Num.length(); i<length; i++) { for (int i = Num.length(); i < length; i++) {
prepend = prepend + "0"; prepend = prepend + "0";
} }
return prepend + Num; return prepend + Num;
} }
public static Element getDataElement(String xml, String eName) { public static Element getDataElement(String xml, String eName) {
Document doc = null; Document doc = null;
Element el = null; Element el = null;
try { try {
doc = DocumentHelper.parseText(xml); doc = DocumentHelper.parseText(xml);
Element root = doc.getRootElement(); Element root = doc.getRootElement();
el = root.element(eName); el = root.element(eName);
} catch (DocumentException e) { } catch (DocumentException e) {
e.printStackTrace(); e.printStackTrace();
} }
return el; return el;
} }
public static String join(String sign, String before, String after, String def, List<String> strs) { 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()])); 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) { public static String join(String sign, String before, String after, String def, String[] strs) {
if (strs == null || strs.length == 0) { if (strs == null || strs.length == 0) {
return def == null ? "" : def; return def == null ? "" : def;
...@@ -59,30 +57,34 @@ public class StringUtil { ...@@ -59,30 +57,34 @@ public class StringUtil {
StringBuffer sb = new StringBuffer(""); StringBuffer sb = new StringBuffer("");
for (int i = 0; i < strs.length; i++) { for (int i = 0; i < strs.length; i++) {
String str = String.valueOf(strs[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); return String.valueOf(sb);
} }
} }
public static String join(String str, String sign, int count, String before, String after) { public static String join(String str, String sign, int count, String before, String after) {
if (str == null || count == 0) { if (str == null || count == 0) {
return ""; return "";
} else { } else {
StringBuffer sb = new StringBuffer(""); StringBuffer sb = new StringBuffer("");
for (int i = 0; i < count; i++) { 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); return String.valueOf(sb);
} }
} }
public static String format(Object no, String format) { public static String format(Object no, String format) {
String strno = String.valueOf(no); String strno = String.valueOf(no);
Integer index = format.length() - strno.length(); Integer index = format.length() - strno.length();
return format.substring(0, index) + strno; return format.substring(0, index) + strno;
} }
public static String readText(String path) throws IOException { public static String readText(String path) throws IOException {
BufferedReader br = null; BufferedReader br = null;
try { 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