GTGE API

com.golden.gamedev.util
Class Utility

java.lang.Object
  extended by com.golden.gamedev.util.Utility

public class Utility
extends Object

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

expand

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

The original array is not changed, this method creates and returns a new expanded array.

Parameters:
src - the array to be expanded, could be an array of primitive or an array of Object
increase - array size increment
bottom - true, the expanded array is at the bottom
Returns:
The expanded array.

expand

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

The new expanded object will be at the bottom of the returned array (last index).

Parameters:
src - the array to be expanded, could be an array of primitive or an array of Object
increase - array size increment
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.

Parameters:
src - the array to be expanded, could be an array of primitive or an array of Object
increase - array size increment
bottom - true, the expanded array is at the bottom
type - array class
Returns:
The expanded array.

cut

public static Object cut(Object src,
                         int position)
Cuts an array of object from specified position.

The original array is not changed, this method creates and returns a new shrinked array.

Parameters:
src - the array to be cut, could be an array of primitive or an array of Object
position - index position to be cut
Returns:
The shrinked array.

mixElements

public static void mixElements(Object src)
Shuffles elements in an array.

Parameters:
src - the array to be mixed, could be an array of primitive or an array of Object

getRandomObject

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


getRandom

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

For example :

    // to return random number from 0 to 10
    int rand = Utility.getRandom(0, 10);
 

Parameters:
lowerBound - the lowest random number
upperBound - the highest random number
Returns:
Random number range from lowerbound to upperbound.

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 is using this method to returned a compact string.

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

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id