DESY ACOP Beans Home

com.cosylab.introspection
Class DataFormatter

java.lang.Object
  extended by com.cosylab.introspection.DataFormatter

public class DataFormatter
extends java.lang.Object

This class helps create String representations of given objects using introspection. It also contains some methods that facilitate String manipulation.

Version:
@@VERSION@@
Author:
Miha Kadunc (miha.kadunc@cosylab.com)

Constructor Summary
DataFormatter()
           
 
Method Summary
static java.lang.String arrayToString(java.lang.Object array)
          Returns a default String representation of an array.
static java.lang.String arrayToString(java.lang.Object array, java.lang.String lineStart)
          Returns a String representation of an array with the specified text in the beginning of each line.
static java.lang.Object[] convertPrimitiveArray(java.lang.Object value)
          Converts an array of primitive values into Java wrappers.
static int getLineCount(java.lang.String lines)
          Returns number of lines (separated by \n) contained in the given String.
static java.lang.String[] splitStringByLines(java.lang.String stringToSplit)
          Splits a given string into multiple strings, each containing a single line (separated by \n)
static java.lang.String[] splitStringOnCapitals(java.lang.String stringToSplit)
           
static java.lang.String toString(java.lang.Class aClass)
          Returns short name of the given Class object.
static java.lang.String toString(java.lang.Class[] array)
          Returns a String representing an array of Class objects, separated by ","
static java.lang.String toString(java.lang.reflect.Constructor aConstructor, boolean showParameters)
          Returns a String representation of a constructor.
static java.lang.String toString(java.lang.reflect.Field aField)
          Returns a String representation of the given field, showing its type and its name.
static java.lang.String toString(java.lang.reflect.Field aField, boolean showType)
          Returns a String representation of the given field, showing its type iff the showType parameter is set to true.
static java.lang.String toString(java.lang.reflect.Member aMember)
          Returns a String representation of the specified member, and its return and parameter types.
static java.lang.String toString(java.lang.reflect.Member aMember, boolean showType, boolean showParameters)
          Returns a String representation of the specified member, and its return and parameter types only if specified so by the showType and showParameters flags.
static java.lang.String toString(java.lang.reflect.Method aMethod)
          Returns a String representation of the given method, showing also its type and parameter types.
static java.lang.String toString(java.lang.reflect.Method aMethod, boolean showType, boolean showParameters)
          Returns a String representation of the given method, showing also its type and parameter types iff specified.
static java.lang.String[] toStringArray(java.lang.Class[] array)
          Returns an array of String representations of Class objects contained in the given array.
static java.lang.String[] toStringArray(java.beans.FeatureDescriptor[] array, boolean showType, boolean showParameters)
          Returns an array of String representations of feature descriptors in the given array.
static java.lang.String[] toStringArray(java.lang.reflect.Member[] array, boolean showType, boolean showParameters)
          Returns an array of String representations of members in the given array.
static java.lang.String[] toStringArray(java.lang.Object[] array)
          Returns an array of String representations of objects in the given array.
static java.lang.String unpackArray(java.lang.Object array)
          Creates a default String representation of an array.
static java.lang.String unpackArray(java.lang.Object array, java.lang.String lineStart)
          Creates a String representation of an array, putting the passed lineStart at the beginning of each line.
static java.lang.String unpackArray(java.lang.Object array, java.lang.String lineStart, int level)
          Creates a String representation of an array, putting the passed lineStart at the beginning of each line.
static java.lang.String unpackReturnValue(java.lang.Object value, java.lang.String start, int level)
          Uses introspection to unpack any type of return value operations might return.
static java.lang.String unpackReturnValue(java.lang.Object value, java.lang.String start, int level, boolean expand)
          Uses introspection to unpack any type of return value operations might return.
static java.lang.String unpackValues(java.lang.String[] names, java.lang.Object[] values)
          Unpacks the given values and creates their String representations.
static java.lang.String unpackValues(java.lang.String[] names, java.lang.Object[] values, java.lang.String delimiter)
          Unpacks the given values and creates their String representations.
static java.lang.String unpackValues(java.lang.String[] names, java.lang.Object[] values, java.lang.String delimiter, boolean expand)
          Unpacks the given values and creates their String representations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataFormatter

public DataFormatter()
Method Detail

toString

public static java.lang.String toString(java.lang.Class aClass)
Returns short name of the given Class object. Appends the appropriate number of "[]" sequences for arrays.

Parameters:
aClass - Class
Returns:
java.lang.String

toString

public static java.lang.String toString(java.lang.Class[] array)
Returns a String representing an array of Class objects, separated by ","

Parameters:
array - Class[]
Returns:
parameter names

toString

public static java.lang.String toString(java.lang.reflect.Constructor aConstructor,
                                        boolean showParameters)
Returns a String representation of a constructor.

Parameters:
aConstructor - Constructor
showParameters - boolean
Returns:
java.lang.String

toString

public static java.lang.String toString(java.lang.reflect.Field aField)
Returns a String representation of the given field, showing its type and its name.

Parameters:
aField - Field
Returns:
java.lang.String

toString

public static java.lang.String toString(java.lang.reflect.Field aField,
                                        boolean showType)
Returns a String representation of the given field, showing its type iff the showType parameter is set to true.

Parameters:
aField - Field
showType - boolean
Returns:
java.lang.String

toString

public static java.lang.String toString(java.lang.reflect.Member aMember)
Returns a String representation of the specified member, and its return and parameter types.

Parameters:
aMember - Member
Returns:
java.lang.String

toString

public static java.lang.String toString(java.lang.reflect.Member aMember,
                                        boolean showType,
                                        boolean showParameters)
Returns a String representation of the specified member, and its return and parameter types only if specified so by the showType and showParameters flags.

Parameters:
aMember - Member
showType - boolean
showParameters - boolean
Returns:
java.lang.String

toString

public static java.lang.String toString(java.lang.reflect.Method aMethod)
Returns a String representation of the given method, showing also its type and parameter types.

Parameters:
aMethod - Method
Returns:
java.lang.String

toString

public static java.lang.String toString(java.lang.reflect.Method aMethod,
                                        boolean showType,
                                        boolean showParameters)
Returns a String representation of the given method, showing also its type and parameter types iff specified.

Parameters:
aMethod - Method
showType - boolean
showParameters - boolean
Returns:
java.lang.String

toStringArray

public static java.lang.String[] toStringArray(java.lang.Class[] array)
Returns an array of String representations of Class objects contained in the given array.

Parameters:
array - Class[]
Returns:
parameter names

toStringArray

public static java.lang.String[] toStringArray(java.lang.reflect.Member[] array,
                                               boolean showType,
                                               boolean showParameters)
Returns an array of String representations of members in the given array. Parameters can be set to show return or parameter types.

Parameters:
array - Member[]
showType - boolean
showParameters - boolean
Returns:
String[] array of string representations of the members

toStringArray

public static java.lang.String[] toStringArray(java.beans.FeatureDescriptor[] array,
                                               boolean showType,
                                               boolean showParameters)
Returns an array of String representations of feature descriptors in the given array.

Parameters:
array - FeatureDescriptor[]
showType - boolean
showParameters - boolean
Returns:
String[] array of string representations of the members

toStringArray

public static java.lang.String[] toStringArray(java.lang.Object[] array)
Returns an array of String representations of objects in the given array.

Parameters:
array - Object[]
Returns:
String[]

arrayToString

public static java.lang.String arrayToString(java.lang.Object array)
Returns a default String representation of an array.

Parameters:
array - java.lang.Object
Returns:
java.lang.String

arrayToString

public static java.lang.String arrayToString(java.lang.Object array,
                                             java.lang.String lineStart)
Returns a String representation of an array with the specified text in the beginning of each line.

Parameters:
array - java.lang.Object
lineStart - java.lang.String
Returns:
java.lang.String

convertPrimitiveArray

public static java.lang.Object[] convertPrimitiveArray(java.lang.Object value)
Converts an array of primitive values into Java wrappers.

Parameters:
value - Object
Returns:
Object[]

getLineCount

public static int getLineCount(java.lang.String lines)
Returns number of lines (separated by \n) contained in the given String.

Parameters:
lines - java.lang.String
Returns:
int

splitStringByLines

public static java.lang.String[] splitStringByLines(java.lang.String stringToSplit)
Splits a given string into multiple strings, each containing a single line (separated by \n)

Parameters:
stringToSplit - String
Returns:
int

splitStringOnCapitals

public static java.lang.String[] splitStringOnCapitals(java.lang.String stringToSplit)

unpackArray

public static java.lang.String unpackArray(java.lang.Object array)
Creates a default String representation of an array.

Parameters:
array - java.lang.Object
Returns:
java.lang.String

unpackArray

public static java.lang.String unpackArray(java.lang.Object array,
                                           java.lang.String lineStart)
Creates a String representation of an array, putting the passed lineStart at the beginning of each line.

Parameters:
array - java.lang.Object
lineStart - java.lang.String
Returns:
java.lang.String

unpackArray

public static java.lang.String unpackArray(java.lang.Object array,
                                           java.lang.String lineStart,
                                           int level)
Creates a String representation of an array, putting the passed lineStart at the beginning of each line. Level specifies the recursion depth.

Parameters:
array - java.lang.Object
lineStart - java.lang.String
level - int
Returns:
java.lang.String

unpackReturnValue

public static java.lang.String unpackReturnValue(java.lang.Object value,
                                                 java.lang.String start,
                                                 int level)
Uses introspection to unpack any type of return value operations might return. It does that recursively to the level of max_recursion_level. It omitts methods, such as hashCode, clone etc.

Parameters:
value - Object
start - String
level - int
Returns:
String

unpackReturnValue

public static java.lang.String unpackReturnValue(java.lang.Object value,
                                                 java.lang.String start,
                                                 int level,
                                                 boolean expand)
Uses introspection to unpack any type of return value operations might return. If expand is true, it does that recursively to the level of max_recursion_level. It omitts methods, such as hashCode.

Parameters:
value - Object
start - String
level - int
expand - boolean
Returns:
String

unpackValues

public static java.lang.String unpackValues(java.lang.String[] names,
                                            java.lang.Object[] values)
Unpacks the given values and creates their String representations.

Parameters:
names - java.lang.String[]
values - java.lang.Object[]
Returns:
java.lang.String

unpackValues

public static java.lang.String unpackValues(java.lang.String[] names,
                                            java.lang.Object[] values,
                                            java.lang.String delimiter)
Unpacks the given values and creates their String representations. The names and values are separated by the specified delimiter

Parameters:
names - java.lang.String[]
values - java.lang.Object[]
delimiter - String
Returns:
java.lang.String

unpackValues

public static java.lang.String unpackValues(java.lang.String[] names,
                                            java.lang.Object[] values,
                                            java.lang.String delimiter,
                                            boolean expand)
Unpacks the given values and creates their String representations. The names and values are separated by the specified delimiter and the values are expanded and analyzed recursively, if specified.

Parameters:
names - java.lang.String[]
values - java.lang.Object[]
delimiter - String
expand - boolean
Returns:
java.lang.String


Copyright © 2010. All Rights Reserved.