01: package org.igfay.jfig;
02:
03: import java.text.SimpleDateFormat;
04:
05: import org.apache.log4j.Logger;
06:
07: /**
08: * @author conrad4
09: *
10: * Utility class with a few methods used by the Config objects. Therese really
11: * belong in more generic utility class. They are only here for expedienty.
12: */
13: public class JFigUtility {
14:
15: private static Logger log = Logger.getLogger(JFig.class);
16: private static SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(
17: "HH:mm:ss.SSS");
18:
19: /**
20: * Utility method for converting a string to an array.
21: * Belongs in a general utility class.
22: *
23: * @param aString
24: * @param token
25: * @return String[]
26: */
27: public static String[] stringToArray(String aString, String token) {
28:
29: java.util.StringTokenizer st = new java.util.StringTokenizer(
30: aString, token);
31: String[] st_array = new String[st.countTokens()];
32: int i = 0;
33: while (st.hasMoreTokens()) {
34: st_array[i] = st.nextToken();
35: i++;
36: }
37: return st_array;
38: }
39:
40: /**
41: * Utility method for converting a string to an array.
42: * Belongs in a general utility class.
43: *
44: * @param aString
45: * @param token
46: * @return String[]
47: */
48: public static String[] stringToArray(String aString) {
49: return stringToArray(aString, getTokenForString(aString));
50: }
51:
52: /**
53: * Utility method for dynamically determine the token/separator for a string
54: * based on the content of the string
55: * Belongs in a general utility class.
56: *
57: * @param aString
58: * @param token
59: * @return String[]
60: */
61: public static String getTokenForString(String aString) {
62: String[] tokens = { ",", ";", ":" };
63: for (int i = 0; i < tokens.length; i++) {
64: if (aString.indexOf(tokens[i]) > -1) {
65: return tokens[i];
66: }
67: }
68: return " ";
69: }
70:
71: /**
72: * Returns the dateFormat.
73: * @return SimpleDateFormat
74: */
75: public static SimpleDateFormat getDateFormat() {
76: return dateFormat;
77: }
78:
79: }
|