|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.util.Utility
public class Utility
Utility class provides general functions, such as array enlargement/shrinkment operation, array mixed, randomize, and other functions that categorized as common functions.
Method Summary | |
---|---|
static String[] |
compactStrings(String[] s)
Compacting String s to occupy less memory. |
static Object |
cut(Object src,
int position)
Cuts an array of object from specified position. |
static Object |
expand(Object src,
int increase)
Expands an array of object by specified size, src can not be
null . |
static Object |
expand(Object src,
int increase,
boolean bottom)
Expands an array of object by specified size, src can not be
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 a random number, range from lowerbound (inclusive) to upperbound (inclusive). |
static Random |
getRandomObject()
Returns pre-defined Random object. |
static void |
mixElements(Object src)
Shuffles elements in an array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Object expand(Object src, int increase, boolean bottom)
src
can not be
null
. The original array is not changed, this method creates and returns a new expanded array.
src
- the array to be expanded, could be an array of primitive or an array of Objectincrease
- array size incrementbottom
- true, the expanded array is at the bottom
public static Object expand(Object src, int increase)
src
can not be
null
. The new expanded object will be at the bottom of the returned array (last index).
src
- the array to be expanded, could be an array of primitive or an array of Objectincrease
- array size increment
public static Object expand(Object src, int increase, boolean bottom, Class type)
Class type
object by specified size,
src
can be null
.
src
- the array to be expanded, could be an array of primitive or an array of Objectincrease
- array size incrementbottom
- true, the expanded array is at the bottomtype
- array class
public static Object cut(Object src, int position)
The original array is not changed, this method creates and returns a new shrinked array.
src
- the array to be cut, could be an array of primitive or an array of Objectposition
- index position to be cut
public static void mixElements(Object src)
src
- the array to be mixed, could be an array of primitive or an array of Objectpublic static Random getRandomObject()
public static int getRandom(int lowerBound, int upperBound)
For example :
// to return random number from 0 to 10 int rand = Utility.getRandom(0, 10);
lowerBound
- the lowest random numberupperBound
- the highest random number
public static String[] compactStrings(String[] s)
s
to occupy less memory.
Use this with a big array of String to save up memory.
For example FileUtil.fileRead(File)
method is using this method
to returned a compact string.
s
- an array of String to be compacted.
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |