Package nz.ac.waikato.cms.core
Class Utils
java.lang.Object
nz.ac.waikato.cms.core.Utils
Class implementing some simple utility methods.
- Version:
- $Revision: 10906 $
- Author:
- Eibe Frank, Yong Wang, Len Trigg, Julien Prados, FracPete (fracpete at waikat dot ac dot nz)
- See Also:
-
weka.core.Utils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringarrayToString(Object array) Returns the given Array in a string representation.static StringarrayToString(Object array, boolean outputClass) Returns the given Array in a string representation.static StringclassesToString(Class[] c) Turns a class array into a string.static StringclassesToString(Class[] c, String separator) Turns a class array into a string.static StringTurns a class into a string.static StringFlattens the array into a single, long string.static StringFlattens the list into a single, long string.static ClassReturns the basic class of an array class (handles multi-dimensional arrays).static intgetArrayDimensions(Class array) Returns the dimensions of the given array.static intgetArrayDimensions(Object array) Returns the dimensions of the given array.static StringgetStackTrace(int maxDepth) Returns the current stack trace.static ObjectCreates a new array of the specified element type with the specified number of elements.static StringPads the string with a padding character with to at most "width" width.static StringPads the string with a padding character with to at most "width" width.static String[]Splits the row into separate cells based on the delimiter character.static String[]Splits the row into separate cells based on the delimiter string.static ClassstringToClass(String classname) Turns a class name into a Class instance.static StringReturns the stacktrace of the throwable as string.static StringthrowableToString(Throwable t, int maxLines) Returns the stacktrace of the throwable as string.toBase(int n, int base) Converts the given decimal number into a different base.static double[]toDouble(float[] array) Turns the float array into a double array.static float[]toFloat(double[] array) Turns the double array into a float array.
-
Field Details
-
ARRAY_INDICATOR
the indicator for arrays.- See Also:
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
getArrayClass
Returns the basic class of an array class (handles multi-dimensional arrays).- Parameters:
c- the array to inspect- Returns:
- the class of the innermost elements
-
getArrayDimensions
Returns the dimensions of the given array. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].- Parameters:
array- the array to determine the dimensions for- Returns:
- the dimensions of the array
-
getArrayDimensions
Returns the dimensions of the given array. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].- Parameters:
array- the array to determine the dimensions for- Returns:
- the dimensions of the array
-
arrayToString
Returns the given Array in a string representation. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].- Parameters:
array- the array to return in a string representationoutputClass- whether to output the class name instead of calling the object's "toString()" method- Returns:
- the array as string
-
arrayToString
Returns the given Array in a string representation. Even though the parameter is of type "Object" one can hand over primitve arrays, e.g. int[3] or double[2][4].- Parameters:
array- the array to return in a string representation- Returns:
- the array as string
-
flatten
Flattens the list into a single, long string. The separator string gets added between the objects, but not after the last one.- Parameters:
lines- the lines to flattensep- the separator- Returns:
- the generated string
-
flatten
Flattens the array into a single, long string. The separator string gets added between the objects, but not after the last one. Uses the "toString()" method of the objects to turn them into a string.- Parameters:
lines- the lines to flattensep- the separator- Returns:
- the generated string
-
stringToClass
Turns a class name into a Class instance. Arrays are indicated by "[]" at the end of the name. Multiple array indicators can be used.- Parameters:
classname- the class name to return the Class instance for- Returns:
- the generated class instance, null if failed to create
-
newArray
Creates a new array of the specified element type with the specified number of elements. Arrays are indicated by "[]" at the end of the clas name. Multiple array indicators can be used. E.g., newArray("java.lang.Double[]", 5) will generate "Double[5][]".- Parameters:
elementClass- the class type for the array elements- Returns:
- the generated array instance, null if failed to create
-
classToString
Turns a class into a string.- Parameters:
c- the class to turn into a string- Returns:
- the string
-
classesToString
Turns a class array into a string.- Parameters:
c- the class array to turn into a string- Returns:
- the string
-
classesToString
Turns a class array into a string.- Parameters:
c- the class array to turn into a stringseparator- the separator between the classes- Returns:
- the string
-
toFloat
public static float[] toFloat(double[] array) Turns the double array into a float array.- Parameters:
array- the array to convert- Returns:
- the converted array
-
toDouble
public static double[] toDouble(float[] array) Turns the float array into a double array.- Parameters:
array- the array to convert- Returns:
- the converted array
-
padLeft
Pads the string with a padding character with to at most "width" width. Does not truncate the string.- Parameters:
s- the string to padpadding- the padding characterwidth- the maximum width- Returns:
- the padded string
-
padLeft
Pads the string with a padding character with to at most "width" width. Truncating, if string is longer than "width", is optional.- Parameters:
s- the string to padpadding- the padding characterwidth- the maximum widthtruncate- if true then the string can be truncated (on the left) to fit width- Returns:
- the padded string
-
throwableToString
Returns the stacktrace of the throwable as string.- Parameters:
t- the throwable to get the stacktrace for- Returns:
- the stacktrace
-
throwableToString
Returns the stacktrace of the throwable as string.- Parameters:
t- the throwable to get the stacktrace formaxLines- the maximum number of lines to print, <= 0 for all- Returns:
- the stacktrace
-
getStackTrace
Returns the current stack trace.- Parameters:
maxDepth- the maximum depth of the stack trace, <= 0 for full trace- Returns:
- the stack trace as string (multiple lines)
-
toBase
Converts the given decimal number into a different base.- Parameters:
n- the decimal number to convertbase- the base- Returns:
- the digits in the new base; index refers to power, ie, 0 = base^0, 3 = base^3
-
split
Splits the row into separate cells based on the delimiter character. String.split(regexp) does not work with empty cells (eg ",,,").- Parameters:
line- the row to splitdelimiter- the delimiter to use- Returns:
- the cells
-
split
Splits the row into separate cells based on the delimiter string. String.split(regexp) does not work with empty cells (eg ",,,").- Parameters:
line- the row to splitdelimiter- the delimiter to use- Returns:
- the cells
-