Class SimUtilities

java.lang.Object
repast.simphony.util.SimUtilities

public class SimUtilities extends Object
A collection of utility methods.
Author:
Nick Collier
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Captializes the specified String.
    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 int
    norm(int val, int size)
    Normalize the specified value to the specified size
    static double
    scale(double value, int decimalPlaces)
    Scales a decimal value to the specified number of decimal places.
    static void
    shuffle(double[] array, cern.jet.random.Uniform rng)
    Shuffles the specified double[] using the specifid Uniform rng.
    static void
    shuffle(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
  • Constructor Details

    • SimUtilities

      public SimUtilities()
  • Method Details

    • capitalize

      public static String capitalize(String str)
      Captializes the specified String.
      Parameters:
      str - the String to capitalize.
      Returns:
      the capitalized String.
    • shuffle

      public static void shuffle(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
    • scale

      public static double scale(double value, int decimalPlaces)
      Scales a decimal value to the specified number of decimal places. This uses the BigDecimal class to perform the calculation to attempt to avoid overflows from other scaling methods. A side effect of this is the creation of BigDecimals which slows this down.
      Parameters:
      value - the value to convert
      decimalPlaces - the number of decimal places to keep
      Returns:
      a rounded value