com.golden.gamedev.util
Class Utility

java.lang.Object
  |
  +--com.golden.gamedev.util.Utility

public class Utility
extends Object

Utility class for array enlargement/shrinkment, array mixed, calculate random value, and other methods that categorized in general methods.


Method Summary
static String[] compactStrings(String[] s)
          Compacting String s to occupy less memory.
static Object cut(Object src, int position)
          The original array is not changed, it creates a whole new array.
static Object expand(Object src, int increase)
          Expands an array of object by specified size, src can not null.
static Object expand(Object src, int increase, boolean bottom)
          Expands an array of object by specified size, src can not null.
static Object expand(Object src, int increase, boolean bottom, Class type)
          Expands an array of Class type object by specified size, src can be null.
static int getRandom(int lowerBound, int upperBound)
          Returns random number, range from lowerbound to upperbound.
static Random getRandomObject()
          Returns pre-defined Random object.
static int[] getShiftOperator(int num)
           
static void mixElements(Object src)
           
static int shiftDivide(int num, int[] shift)
          Working, but makes no sense, not benchmark yet, divide num by shift.
static int shiftMultiply(int num, int[] shift)
          Working, but makes no sense, not benchmark yet, multiply num by shift.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

cut

public static Object cut(Object src,
                         int position)
The original array is not changed, it creates a whole new array.


expand

public static Object expand(Object src,
                            int increase,
                            boolean bottom)
Expands an array of object by specified size, src can not null.
The original array is not changed, it creates a whole new array.

Parameters:
src - the array to expands, could be an array of primitive or an array of Object.
Returns:
The expanded array

expand

public static Object expand(Object src,
                            int increase)
Expands an array of object by specified size, src can not null.
The new expanded object will be at the bottom of the returned array (last index).

Parameters:
src - the array to expands, could be an array of primitive or an array of Object.
Returns:
The expanded array

expand

public static Object expand(Object src,
                            int increase,
                            boolean bottom,
                            Class type)
Expands an array of Class type object by specified size, src can be null.


mixElements

public static void mixElements(Object src)

getRandomObject

public static Random getRandomObject()
Returns pre-defined Random object.


getRandom

public static int getRandom(int lowerBound,
                            int upperBound)
Returns random number, range from lowerbound to upperbound.

Returns:
random number

compactStrings

public static String[] compactStrings(String[] s)
Compacting String s to occupy less memory. Use this with a big array of String to save up memory.
For example FileUtil.fileRead(File) method returns compact string.

Parameters:
s - an array of String to be compacted.
Returns:
Compacted String

shiftDivide

public static int shiftDivide(int num,
                              int[] shift)
Working, but makes no sense, not benchmark yet, divide num by shift.

Parameters:
num - the number to divide
shift -
See Also:
getShiftOperator(int)

shiftMultiply

public static int shiftMultiply(int num,
                                int[] shift)
Working, but makes no sense, not benchmark yet, multiply num by shift.

Parameters:
num - the number to divide
shift -
See Also:
getShiftOperator(int)

getShiftOperator

public static int[] getShiftOperator(int num)