edu.brook.ascape.util
Class Utility

java.lang.Object
  |
  +--edu.brook.ascape.util.Utility

public class Utility
extends java.lang.Object
implements java.io.Serializable

An class encapsulating various common utility functions. For now, just has some random number helper functions and a set of series for 2D arrays.

Since:
1.0
Version:
1.0
See Also:
Serialized Form

Field Summary
static int[][][] uniqueSeries
          A quick set of unique series up to 4 nodes.
 
Constructor Summary
Utility()
           
 
Method Summary
static java.lang.String formatElapsedMillis(long time)
          Formats a time in milleseconds (typically elapsed time) into a string with format "[d'd'] hh:mm:ss.mmmm".
static java.lang.String formatToString(double num, int decPlaces)
          Returns the supplied number formatted as a string with the given number of decimal places fixed.
static java.lang.String getClassNameOnly(java.lang.Class c)
           
static void notImplemented()
          Reports standard error and any other desired behavior when the user attempts to use an unimplemented method.
static java.lang.String orderedQualifiers(java.lang.String string)
          Removes qualifiers such as min and max from string, placing an appropriate order token at the end of the string.
static java.lang.String padStringLeft(java.lang.String string, int size)
          Pads the string with spaces on the left to the supplied size.
static java.lang.String padStringLeftWithZeros(java.lang.String string, int size)
          Pads the string with spaces on the left to the supplied size.
static java.lang.String padStringRight(java.lang.String string, int size)
          Pads the string with spaces on the right to the supplied size.
static int randomInRange(java.util.Random random, int low, int high)
          Returns an integer distributed across some range as the supplied integer is uniformally distributed across the full range of integers.
static boolean randomIs(java.util.Random random)
          Returns a random boolean value.
static int randomToLimit(java.util.Random random, int limit)
          Returns an integer distributed across 0...high - 1 as the supplied integer is distributed across the full range of integers.
static java.lang.String removeQualifiers(java.lang.String string)
          Removes qualifiers such as min and max from string.
static boolean test()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uniqueSeries

public static final int[][][] uniqueSeries
A quick set of unique series up to 4 nodes. Used to randomly traverse a list using a non-repeating path.
Constructor Detail

Utility

public Utility()
Method Detail

randomInRange

public static final int randomInRange(java.util.Random random,
                                      int low,
                                      int high)
Returns an integer distributed across some range as the supplied integer is uniformally distributed across the full range of integers. Used for returning a random integer between two values.
Parameters:
random - the random number stream to use
low - the lowest number (inclusive) that the resulting int might be
low - the hignest number (inclusive) that the resulting int might be

randomToLimit

public static final int randomToLimit(java.util.Random random,
                                      int limit)
Returns an integer distributed across 0...high - 1 as the supplied integer is distributed across the full range of integers. Used for returning a random integer between two values.
Parameters:
random - the random number stream to use
limit - the maximum limit (exclusize) of the rusulting int

randomIs

public static final boolean randomIs(java.util.Random random)
Returns a random boolean value.
Parameters:
random - the random number stream to use

notImplemented

public static void notImplemented()
Reports standard error and any other desired behavior when the user attempts to use an unimplemented method.

formatElapsedMillis

public static java.lang.String formatElapsedMillis(long time)
Formats a time in milleseconds (typically elapsed time) into a string with format "[d'd'] hh:mm:ss.mmmm". For example, 00:00:02.3328, or 1d 02:12:03.3521. Note that time will be downcast to an int, but this should not really be a problem!

removeQualifiers

public static java.lang.String removeQualifiers(java.lang.String string)
Removes qualifiers such as min and max from string.
Parameters:
string - the string to remove qualifiers from

orderedQualifiers

public static java.lang.String orderedQualifiers(java.lang.String string)
Removes qualifiers such as min and max from string, placing an appropriate order token at the end of the string. Useful for sorting items into user readable order.
Parameters:
string - the string to remove qualifiers from

padStringRight

public static java.lang.String padStringRight(java.lang.String string,
                                              int size)
Pads the string with spaces on the right to the supplied size. If the string is larger than the supplied number of spaces it is truncated.
Parameters:
string - the string to pad
size - the size to pad (or truncate) the string to

padStringLeft

public static java.lang.String padStringLeft(java.lang.String string,
                                             int size)
Pads the string with spaces on the left to the supplied size. If the string is larger than the supplied number of spaces it is truncated.
Parameters:
string - the string to pad
size - the size to pad (or truncate) the string to

padStringLeftWithZeros

public static java.lang.String padStringLeftWithZeros(java.lang.String string,
                                                      int size)
Pads the string with spaces on the left to the supplied size. If the string is larger than the supplied number of spaces it is truncated.
Parameters:
string - the string to pad
size - the size to pad (or truncate) the string to

formatToString

public static java.lang.String formatToString(double num,
                                              int decPlaces)
Returns the supplied number formatted as a string with the given number of decimal places fixed. For example, formatToString(23.436765, 2) would return "23.44".
Parameters:
num - the number to format
decPlaces - the number of places to display

getClassNameOnly

public static java.lang.String getClassNameOnly(java.lang.Class c)

test

public static boolean test()

(c) 1998-2000 The Brookings Insitution
Webpage