Static Public Member Functions | |
static String | diff (Date end, Date start) |
Utility method to write out a time difference as a String. | |
static Date | dateFromString (String timestamp) throws HDException |
Try to set date from a string by matching against some standard formats. | |
static String | getIntForm (Double dbl) |
static String | stripBrackets (String in) |
java.lang.String.replace() won't replace a char with null which is why I have done it this way. | |
static void | toFile (String mystr, String filedir, String filename) |
Writes a String to the specified file. |
Definition at line 19 of file HDUtil.java.
static String diff | ( | Date | end, | |
Date | start | |||
) | [static] |
Utility method to write out a time difference as a String.
start | start time | |
end | end time |
Definition at line 29 of file HDUtil.java.
static Date dateFromString | ( | String | timestamp | ) | throws HDException [static] |
Try to set date from a string by matching against some standard formats.
Definition at line 44 of file HDUtil.java.
00044 { 00045 try { 00046 String[] formats = { 00047 "yyyy-MM-dd HH:mm:ss", 00048 "yyyy.MM.dd HH:mm:ss", 00049 "yyyy/MM/dd HH:mm:ss", 00050 "dd/MM/yyyy HH:mm:ss", 00051 "dd MMM yyyy HH:mm:ss", 00052 "yyyy-MM-dd", 00053 "yyyy.MM.dd", 00054 "yyyy/MM/dd", 00055 "dd/MM/yyyy", 00056 "dd MMM yyyy" 00057 }; 00058 return DateUtils.parseDate(timestamp, formats); 00059 } catch (ParseException e) { 00060 throw new HDException(e); 00061 } 00062 }
static String getIntForm | ( | Double | dbl | ) | [static] |
Definition at line 65 of file HDUtil.java.
00065 { 00066 String dblString = dbl.toString(); 00067 00068 // System.out.println("Input String:"+dblString); 00069 String mString = ""; 00070 int exp = 0; 00071 00072 if (dblString.indexOf("E") > -1) { 00073 //9.0E-4 00074 //1.378E05 00075 exp = Integer.parseInt(dblString.substring(dblString.indexOf("E") + 1)); 00076 dblString = dblString.substring(0, dblString.indexOf("E")); 00077 } 00078 00079 int len = dblString.length(); 00080 00081 if (dblString.indexOf(".") > -1) { 00082 String s = dblString; 00083 00084 while (s.endsWith("0")) { 00085 s = s.substring(0, s.length() - 1); 00086 } 00087 00088 exp = -s.length() + s.indexOf(".") + 1 + exp; 00089 mString = s.substring(0, s.indexOf(".")) + s.substring(s.indexOf(".") + 1); 00090 00091 //System.out.println("Is decimal, mString,exp "+mString+","+exp); 00092 } else { 00093 String s = dblString; 00094 int c = 0; 00095 00096 while (s.endsWith("0") && !s.equals("")) { 00097 c++; 00098 s = s.substring(0, s.length() - 1); 00099 } 00100 00101 mString = s; 00102 exp = c + exp; 00103 00104 //System.out.println("Is not decimal, mString,exp "+mString+","+exp); 00105 } 00106 00107 //System.out.println("Return String "+mString+"E"+exp); 00108 return mString + "E" + exp; 00109 }
static String stripBrackets | ( | String | in | ) | [static] |
java.lang.String.replace() won't replace a char with null which is why I have done it this way.
if (in==null || in.equals("")) return null; String out = in.replace('(',' '); out = out.replace(')',' '); return out.trim();
Definition at line 116 of file HDUtil.java.
00116 { 00117 if (in == null) { 00118 return null; 00119 } 00120 00121 char[] charArray = (in.trim()).toCharArray(); 00122 StringBuffer out = new StringBuffer(); 00123 00124 for (int i = 0; i < charArray.length; i++) { 00125 char test = charArray[i]; 00126 00127 if ((test != '(') && (test != ')') && (test != '*') && (test != '\"') && 00128 (test != '\'')) { 00129 out.append(test); 00130 } 00131 } 00132 00133 return out.toString(); 00134 00140 }
static void toFile | ( | String | mystr, | |
String | filedir, | |||
String | filename | |||
) | [static] |
Writes a String to the specified file.
string | ||
filedir | ||
filename |
Definition at line 149 of file HDUtil.java.
00149 { 00150 try { 00151 File f = new File(filedir, filename); 00152 FileWriter fw = new FileWriter(f); 00153 fw.write(mystr); 00154 fw.close(); 00155 } catch (IOException e) { 00156 System.err.println(e); 00157 } 00158 }