net.sourceforge.worldsaver.util
Class MiscMethods

java.lang.Object
  |
  +--net.sourceforge.worldsaver.util.MiscMethods
All Implemented Interfaces:
MiscUtils

public class MiscMethods
extends java.lang.Object
implements MiscUtils

This class provides some useful methods.

Version:
8 Dec 2000
Author:
Andreas Schmitz

Fields inherited from interface net.sourceforge.worldsaver.util.MiscUtils
CONSOLE_WIDTH, NEWLINE, RANDOM
 
Constructor Summary
MiscMethods()
           
 
Method Summary
static int getNumberOfLines(java.lang.String s)
          Returns the number of lines contained in a string.
static java.lang.String[] mergeArrays(java.lang.String[] a, java.lang.String[] b)
          Merges two String arrays, sorts them and removes double Strings.
static java.lang.String[] parseCMDLine(java.lang.String[] a, java.util.Properties p)
          Parses cmdline options.
static void printProgressBar(int stat)
          Prints outa progress bar on stdout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MiscMethods

public MiscMethods()
Method Detail

printProgressBar

public static void printProgressBar(int stat)
Prints outa progress bar on stdout. To use it properly you should create a new thread which contains the code whom status you want to display. Then you can print out the status by calling this method in a loop.
Parameters:
stat - the status (percent completed)

mergeArrays

public static java.lang.String[] mergeArrays(java.lang.String[] a,
                                             java.lang.String[] b)
Merges two String arrays, sorts them and removes double Strings.
Parameters:
a - the first array
b - the second array
Returns:
the new array

getNumberOfLines

public static int getNumberOfLines(java.lang.String s)
Returns the number of lines contained in a string.
Parameters:
s - the string
Returns:
the number of lines

parseCMDLine

public static java.lang.String[] parseCMDLine(java.lang.String[] a,
                                              java.util.Properties p)
Parses cmdline options. The cmdline options should start with `-'. You must provide this method a properties object where the default values should be stored. It must also contain all possible options. You can use switches like `-m', the properties value should then be "true"/"false". Normal cmdline options can have an argument (in the properties should then be any other value than "true"/"false"). The String-array that is returned contains "-false-" if there was a parse error. If not, it contains additional arguments that don't belong to options (like filenames) at the end of the cmdline. Note that a typical key/value pair in the properties object could look like that: "-o","foofile" or "-z","true".
Parameters:
a - the args[] array from the main method
p - the properties containing the defaults
Returns:
an array with additional arguments (null if there are none)