KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > igfay > jfig > JFigUtility


1 package org.igfay.jfig;
2
3 import java.text.SimpleDateFormat JavaDoc;
4
5 import org.apache.log4j.Logger;
6
7 /**
8  * @author conrad4
9  *
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 JavaDoc dateFormat = new java.text.SimpleDateFormat JavaDoc("HH:mm:ss.SSS");
17
18     /**
19      * Utility method for converting a string to an array.
20      * Belongs in a general utility class.
21      *
22      * @param aString
23      * @param token
24      * @return String[]
25      */

26     public static String JavaDoc[] stringToArray(String JavaDoc aString, String JavaDoc token) {
27     
28         java.util.StringTokenizer JavaDoc st = new java.util.StringTokenizer JavaDoc(aString, token);
29         String JavaDoc[] st_array = new String JavaDoc[st.countTokens()];
30         int i = 0;
31         while (st.hasMoreTokens()) {
32             st_array[i] = st.nextToken();
33             i++;
34         }
35         return st_array;
36     }
37
38     /**
39      * Utility method for converting a string to an array.
40      * Belongs in a general utility class.
41      *
42      * @param aString
43      * @param token
44      * @return String[]
45      */

46     public static String JavaDoc[] stringToArray(String JavaDoc aString) {
47         return stringToArray(aString, getTokenForString(aString));
48     }
49
50     /**
51      * Utility method for dynamically determine the token/separator for a string
52      * based on the content of the string
53      * Belongs in a general utility class.
54      *
55      * @param aString
56      * @param token
57      * @return String[]
58      */

59     public static String JavaDoc getTokenForString(String JavaDoc aString) {
60         String JavaDoc[] tokens = {",", ";", ":"};
61         for (int i = 0; i < tokens.length; i++) {
62             if (aString.indexOf(tokens[i]) > -1) {
63                 return tokens[i];
64             }
65         }
66         return " ";
67     }
68
69
70
71
72     /**
73      * Returns the dateFormat.
74      * @return SimpleDateFormat
75      */

76     public static SimpleDateFormat JavaDoc getDateFormat() {
77         return dateFormat;
78     }
79     
80 }
81
Popular Tags