KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > Utils


1 package discRack;
2
3 import java.util.*;
4 import java.awt.*;
5
6 /**
7  * Contains a few static methods.
8  *
9  * @author Sasa Bojanic
10  * @version 1.0
11  */

12 public class Utils {
13
14    /**
15     * Take the given string and chop it up into a series
16     * of strings on given boundries. This is useful
17     * for trying to get an array of strings out of the
18     * resource file.
19     */

20    public static String JavaDoc[] tokenize(String JavaDoc input,String JavaDoc boundary) {
21       if (input==null) input="";
22       Vector v = new Vector();
23       StringTokenizer t = new StringTokenizer(input,boundary);
24       String JavaDoc cmd[];
25
26       while (t.hasMoreTokens())
27          v.addElement(t.nextToken());
28       cmd = new String JavaDoc[v.size()];
29       for (int i = 0; i < cmd.length; i++)
30          cmd[i] = (String JavaDoc)v.elementAt(i);
31
32       return cmd;
33    }
34
35    /** Returns the class name without package. */
36    public static String JavaDoc getUnqualifiedClassName (Class JavaDoc cls) {
37       String JavaDoc name=cls.getName();
38       int lastDot=name.lastIndexOf(".");
39       if (lastDot>=0) {
40          name=name.substring(lastDot+1,name.length());
41       }
42       return name;
43    }
44
45 }
Popular Tags