org.deduced.utilities
Class ObjectUtilities

java.lang.Object
  extended by org.deduced.utilities.ObjectUtilities

public class ObjectUtilities
extends java.lang.Object

ObjectUtilities is used to host static utility methods to deal with java objects

Author:
Steve McDuff

Field Summary
private static int DEFAULT_READ_ARRAY_SIZE
          default read array size when reading an input stream
 
Constructor Summary
ObjectUtilities()
           
 
Method Summary
static java.lang.String aggregateStringListWithSeparator(java.util.List<java.lang.String> stringListToAggregate, java.lang.String separator)
          aggregate String list.
static
<E> E
callCloneOnObject(E valueToClone)
          Call the clone method on an object if it exists.
static void clearRemainingArraySpace(int clearStartIndex, java.lang.Object[] arrayToClear)
          Reset all array slots to null starting with clearStartIndex until the end of the array
static
<T> T[]
copyArrayToArray(T[] arrayToModify, java.lang.Object[] sourceArray, int size)
          Utility method used to convert a source array to a destination array.
static
<T> T[]
enlargeArrayIfTooSmall(int size, T[] sourceArray)
          Enlarge an array if it is too small.
static byte[] inputStreamToByteArray(java.io.InputStream stream, int initialSize)
          convert an input stream to a byte array
static java.lang.String inputStreamToString(java.io.InputStream stream)
          convert an input stream to a string
static void sleepSilent(long milliseconds)
          sleep Silent ignores interrupted exceptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_READ_ARRAY_SIZE

private static final int DEFAULT_READ_ARRAY_SIZE
default read array size when reading an input stream

See Also:
Constant Field Values
Constructor Detail

ObjectUtilities

public ObjectUtilities()
Method Detail

callCloneOnObject

public static <E> E callCloneOnObject(E valueToClone)
Call the clone method on an object if it exists.

Type Parameters:
E - the type of object to clone
Parameters:
valueToClone - the value to clone
Returns:
the cloned value. Null if cloning failed.

inputStreamToString

public static java.lang.String inputStreamToString(java.io.InputStream stream)
                                            throws java.io.IOException
convert an input stream to a string

Parameters:
stream - the stream to convert
Returns:
the converted string
Throws:
java.io.IOException - if reading fails

inputStreamToByteArray

public static byte[] inputStreamToByteArray(java.io.InputStream stream,
                                            int initialSize)
                                     throws java.io.IOException
convert an input stream to a byte array

Parameters:
stream - the stream to convert
initialSize - the initial buffer size
Returns:
the converted byte array
Throws:
java.io.IOException - if reading fails

enlargeArrayIfTooSmall

public static <T> T[] enlargeArrayIfTooSmall(int size,
                                             T[] sourceArray)
Enlarge an array if it is too small. IF the array is big enough, Then the same array is reused, otherwise a new array is created that is big enough to hold enough elements to match the size parameter.

Type Parameters:
T - the type of objects contained in the array
Parameters:
size - the size the array must contain
sourceArray - the source array that might be reused if it is large enough
Returns:
the array that is guaranteed to be length >= size

copyArrayToArray

public static <T> T[] copyArrayToArray(T[] arrayToModify,
                                       java.lang.Object[] sourceArray,
                                       int size)
Utility method used to convert a source array to a destination array. The first array used as a parameter will be modified to contain the list of values contained in the sourceArray. If the array is too small, it will be enlarged to fit the size of the collection. If the array is too big, remaining slots in the array will be set to null

Type Parameters:
T - the object type in the array to modify and return
Parameters:
arrayToModify - the array that might be modified if the array is big enough
sourceArray - the array that will be read and used to fill the returned array
size - size of the source array to copy.
Returns:
the array of values contained in the collection to convert

clearRemainingArraySpace

public static void clearRemainingArraySpace(int clearStartIndex,
                                            java.lang.Object[] arrayToClear)
Reset all array slots to null starting with clearStartIndex until the end of the array

Parameters:
clearStartIndex - the start index that will be used to clear the array
arrayToClear - the array to start clearing

sleepSilent

public static void sleepSilent(long milliseconds)
sleep Silent ignores interrupted exceptions

Parameters:
milliseconds - the amount of time to sleep for in milliseconds.

aggregateStringListWithSeparator

public static java.lang.String aggregateStringListWithSeparator(java.util.List<java.lang.String> stringListToAggregate,
                                                                java.lang.String separator)
aggregate String list.

Examples :

arrayToAggregate = {"a","b","c"}, separator = "," will result in : "a,b,c"

arrayToAggregate = {"a"}, separator = "," will result in : "a"

arrayToAggregate = {"a","b","c"}, separator = null will result in : "abc"

Parameters:
stringListToAggregate - the list of string to aggregate
separator - the separator to use between each string. If this is null, no separator will be inserted between each string.
Returns:
the aggregated string