uchicago.src.sim.util
Class SimUtilities

java.lang.Object
  extended by uchicago.src.sim.util.SimUtilities

public class SimUtilities
extends java.lang.Object

Static Utility methods for RePast simulations.

Version:
$Revision: 1.13 $ $Date: 2005/03/14 00:10:37 $
Author:
Nick Collier

Field Summary
static java.lang.String newLine
           
 
Method Summary
static java.lang.String capitalize(java.lang.String str)
          Captializes the specified String.
static java.io.File getDataFile(java.lang.String filename)
          Gets a file based on a certain name.
static java.lang.String getDataFileName(java.lang.String filename)
          Gets a filename based on a certain name.
static double[] getPointFromHeadingAndDistance(int heading, int distance)
          Gets an x, y coordinate as a double[] of length 2, given a heading (0-359) and a distance.
static void logException(java.lang.String msg, java.lang.Exception ex)
          Logs the specified message and exception to .
static int norm(int val, int size)
          Normalize the specified value to the specified size
static void showError(java.lang.String msg, java.lang.Exception ex)
          Displays an error message on the screen and prints the message and the exception message and stack trace to a .
static void showMessage(java.lang.String msg)
          Displays a message in a dialog box.
static void shuffle(double[] array, cern.jet.random.Uniform rng)
          Shuffles the specified double[] using the specifid Uniform rng.
static void shuffle(java.util.List list)
          Shuffles the specified list using Random.uniform.
static void shuffle(java.util.List list, cern.jet.random.Uniform rng)
          Shuffles the specified list using the specifid Uniform rng.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newLine

public static final java.lang.String newLine
Method Detail

capitalize

public static java.lang.String capitalize(java.lang.String str)
Captializes the specified String.

Parameters:
str - the String to capitalize.
Returns:
the capitalized String.

getDataFile

public static java.io.File getDataFile(java.lang.String filename)
Gets a file based on a certain name. The way this works is it checks the current directory for the file, then data/, demos/data/, repast/demos/data/, demos/, for the file. This is useful especially for demos that will be in the demos/ directory and ran through the Repast GUI.

Parameters:
filename - the name of the file to get
Returns:
a file object corresponding to the filename or null if the file wasn't found

getDataFileName

public static java.lang.String getDataFileName(java.lang.String filename)
Gets a filename based on a certain name. The way this works is it checks the current directory for the file, then data/, demos/data/, repast/demos/data/, demos/, for the file. This is useful especially for demos that will be in the demos/ directory and ran through the Repast GUI.

Parameters:
filename - the name of the file to get
Returns:
a String corresponding to the absolute path of the file or null if the file wasn't found

shuffle

public static void shuffle(java.util.List list)
Shuffles the specified list using Random.uniform. This list is shuffled by iterating backwards through the list and swapping the current item with a randomly chosen item. This randomly chosen item will occur before the current item in the list.

Parameters:
list - the list to shuffle
See Also:
Random

shuffle

public static void shuffle(java.util.List list,
                           cern.jet.random.Uniform rng)
Shuffles the specified list using the specifid Uniform rng. This list is shuffled by iterating backwards through the list and swapping the current item with a randomly chosen item. This randomly chosen item will occur before the current item in the list.

Parameters:
list - the List to shuffle
rng - the random number generator to use for the shuffle

shuffle

public static void shuffle(double[] array,
                           cern.jet.random.Uniform rng)
Shuffles the specified double[] using the specifid Uniform rng. This list is shuffled by iterating backwards through the list and swapping the current item with a randomly chosen item. This randomly chosen item will occur before the current item in the list.

Parameters:
array - the double[] to shuffle
rng - the random number generator to use for the shuffle

getPointFromHeadingAndDistance

public static double[] getPointFromHeadingAndDistance(int heading,
                                                      int distance)
Gets an x, y coordinate as a double[] of length 2, given a heading (0-359) and a distance. The point of origin is 0, 0 and the returned coordinate is relative to this distance. (An agent can calculate a new coordinate by adding the returned coordinates to its own x, y values.) This assumes that north = 0 degrees, east = 90 and so on.

Parameters:
heading - the heading in degrees
distance - the distance to travel along the heading
Returns:
a double[] with the calculated coordinate

norm

public static int norm(int val,
                       int size)
Normalize the specified value to the specified size

Parameters:
val - the value to normalize
size - the size to normalize the value to
Returns:
the normalized value

showMessage

public static void showMessage(java.lang.String msg)
Displays a message in a dialog box.


showError

public static void showError(java.lang.String msg,
                             java.lang.Exception ex)
Displays an error message on the screen and prints the message and the exception message and stack trace to a ./repast_error.log


logException

public static void logException(java.lang.String msg,
                                java.lang.Exception ex)
Logs the specified message and exception to ./repast.log.

Parameters:
msg - the message to log
ex - the exception to log