Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.ascape.util
Class Utility

    java.lang.Object
      org.ascape.util.Utility

All Implemented Interfaces:
  java.io.Serializable

    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
Author:
  Miles Parker
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 and padded with zeroes if needed.
`static java.lang.String` | `getClassNameOnly(java.lang.Class c)` Given a class, returns the name of that class without qualifiers.
`static java.awt.Image` | `magnifyImage(java.awt.Image image, double magnificationFactorHeight, double magnificationFactorWidth)` Positively scale an image.
`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 double` | `randomInRange(java.util.Random random, double low, double high)` Generate a double uniformly distributed across some range.
`static int` | `randomInRange(java.util.Random random, int low, int high)` Generate an integer uniformly distributed across some range.
`static boolean` | `randomIs(java.util.Random random)` Returns a random boolean value.
`static int` | `randomToLimit(java.util.Random random, int limit)` Generate an integer uniformly distributed across 0...limit - 1.
`static java.awt.Image` | `reduceImage(java.awt.Image image, double reductionFactorHeight, double reductionFactorWidth)` Negatively scale an image.
`static java.lang.String` | `removeQualifiers(java.lang.String string)` Removes qualifiers such as min and max from string.
`static double` | `tanh(double x)` A function that returns the hyperbolic tangent of its argument.

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)

  Generate an integer uniformly distributed across some range.

  Parameters:
    `random` - the random number stream to use
    `low` - the lowest number (inclusive) that the resulting int might be
    `high` - the hignest number (inclusive) that the resulting int might be
  Returns:
    uniformly distributed pseudorandom int

### randomInRange

    public static final double randomInRange(java.util.Random random,
                                             double low,
                                             double high)

  Generate a double uniformly distributed across some range.

  Parameters:
    `random` - the random number stream to use
    `low` - the lowest number (inclusive) that the resulting double might be
    `high` - the highest number (exclusive) that the resulting double might be
  Returns:
    uniformly distributed pseudo-random double

### randomToLimit

    public static final int randomToLimit(java.util.Random random,
                                          int limit)

  Generate an integer uniformly distributed across 0...limit - 1.

  Parameters:
    `random` - the random number stream to use
    `limit` - the maximum limit (exclusive) of the resulting int
  Returns:
    uniformly distributed pseudo-random 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 and padded with zeroes if needed. 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)

  Given a class, returns the name of that class without qualifiers. e.g. "Color", not "java.awt.Color".

### tanh

    public static double tanh(double x)

  A function that returns the hyperbolic tangent of its argument. Note that this method has its worst precision around |x| = 1.0e-6, but it always provides at least 11 significant digits

  Parameters:
    `x` - the argument

### reduceImage

    public static java.awt.Image reduceImage(java.awt.Image image,
                                             double reductionFactorHeight,
                                             double reductionFactorWidth)

  Negatively scale an image.

  Parameters:
    `image` - The image to be scaled
    `reductionFactorHeight` - Scale amount for height.
    `reductionFactorWidth` - Scale amount for width.
  Returns:
    The scaled image.

### magnifyImage

    public static java.awt.Image magnifyImage(java.awt.Image image,
                                              double magnificationFactorHeight,
                                              double magnificationFactorWidth)

  Positively scale an image.

  Parameters:
    `image` - The image to be scaled
    `magnificationFactorHeight` - Scale amount for height.
    `magnificationFactorWidth` - Scale amount for width.
  Returns:
    The scaled image.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD