summaryrefslogtreecommitdiff
path: root/java/src/OS.java
blob: c17fd6d07f296f57a51142b577b83fe7fbae00b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*************************************************
 *
 * = PACKAGE
 *    JACE.OS
 *
 * = FILENAME
 *    OS.java
 *
 *@author Prashant Jain
 *
 *************************************************/
package JACE.OS;

import java.util.StringTokenizer;

/**
 * <hr>
 * <h2>SYNOPSIS</h2>
 *<blockquote>
 *     Methods to extend the capabilities of the Java runtime system.
 *</blockquote>
 *
 * <h2>DESCRIPTION</h2>
 *<blockquote>
 * This non-instantiable class contains little <q>utility functions</q>
 * that should have been in Java to begin with :-)
 *</blockquote>
 */
public class OS
{
  /**
   * Create an array of Strings from a single String using <delim> as
   * the delimiter.
   *@param args the String to break up to make an array of Strings
   *@param delim the delimeter to use to break the String up
   *@return an array containing the original String broken up
   */
  public static String [] createStringArray (String args, String delim)
  {
    // First determine the number of arguments
    int count = 0;
    StringTokenizer tokens = new StringTokenizer (args, delim);
    while (tokens.hasMoreTokens ())
      {
	tokens.nextToken ();
	count++;
      }
    if (count == 0)
      return null;
    
    // Create argument array
    String [] argArray = new String [count];
    int index = 0;
    tokens = new StringTokenizer (args, " ");
    while (tokens.hasMoreTokens ())
      {
	argArray [index] = tokens.nextToken ();
	index++;
      }

    // Assert index == count
    if (index != count)
      return null;
    else
      return argArray;    
  }

  // Default private constructor to avoid instantiation
  private OS ()
  {
  }
}