net.slashie.util
Class Util

java.lang.Object
  extended by net.slashie.util.Util

public class Util
extends java.lang.Object

Various utilities to make things easier.

Author:
Santiago Zapata

Constructor Summary
Util()
           
 
Method Summary
static int abs(int a)
          Returns the absolute value of a number.
static boolean chance(int p)
          Tells if a random percent roll is at or below a certain number.
static int greater(int a, int b)
          Compares two numbers and returns the larger of them.
static java.util.Vector page(java.util.Vector source, int elementsOnPage, int pageNumber)
           
static int rand(int low, int hi)
          Used to get a random number within a range, with all numbers being equally likely.
static java.lang.Object randomElementOf(java.util.ArrayList array)
           
static int randomElementOf(int[] array)
           
static java.lang.Object randomElementOf(java.lang.Object[] array)
           
static java.lang.String randomElementOf(java.lang.String[] array)
           
static java.lang.Object randomElementOf(java.util.Vector array)
           
static int sign(int n)
          Gives an indication of the sign (negative or positive) of a specific number.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

rand

public static int rand(int low,
                       int hi)
Used to get a random number within a range, with all numbers being equally likely.

Parameters:
low - low end of range
hi - high end of range
Returns:
randomly chosen number

greater

public static int greater(int a,
                          int b)
Compares two numbers and returns the larger of them. If they are equal, returns the second number.

Parameters:
a -
b -
Returns:
larger number

abs

public static int abs(int a)
Returns the absolute value of a number.

Parameters:
a - number to be used
Returns:
absolute value of a

chance

public static boolean chance(int p)
Tells if a random percent roll is at or below a certain number.

Parameters:
p - number to test
Returns:
true if random roll is less than or equal to p

page

public static java.util.Vector page(java.util.Vector source,
                                    int elementsOnPage,
                                    int pageNumber)

randomElementOf

public static java.lang.String randomElementOf(java.lang.String[] array)
Parameters:
array -
Returns:
a randomly chosen element of array

randomElementOf

public static int randomElementOf(int[] array)
Parameters:
array -
Returns:
a randomly chosen element of array

randomElementOf

public static java.lang.Object randomElementOf(java.util.Vector array)
Parameters:
array -
Returns:
a randomly chosen element of array

randomElementOf

public static java.lang.Object randomElementOf(java.util.ArrayList array)
Parameters:
array -
Returns:
a randomly chosen element of array

randomElementOf

public static java.lang.Object randomElementOf(java.lang.Object[] array)
Parameters:
array -
Returns:
a randomly chosen element of array

sign

public static int sign(int n)
Gives an indication of the sign (negative or positive) of a specific number.

Parameters:
n - number specified
Returns:
1 if positive, -1 if negative, 0 if n==0