org.jcoderz.commons.util
Class ArraysUtil

java.lang.Object
  extended by org.jcoderz.commons.util.ArraysUtil

public final class ArraysUtil
extends Object

This class contains a static factory that allows arrays to be viewed as lists.

Author:
Michael Griffel

Method Summary
static String toString(boolean[] array)
          Returns a string representation of the contents of the specified array.
static String toString(byte[] array)
          Returns a string representation of the contents of the specified array.
static String toString(char[] array)
          Returns a string representation of the contents of the specified array.
static String toString(int[] array)
          Returns a string representation of the contents of the specified array.
static String toString(long[] array)
          Returns a string representation of the contents of the specified array.
static String toString(Object array)
          Returns a string representation of the contents of given object with special care for potential arrays.
static String toString(Object[] array)
          Returns a string representation of the contents of the specified array.
static String toString(Object[] array, int maxSize)
          Returns a string representation of the contents of the specified array with a maxSize limitation.
static String toString(Object array, int maxSize)
          Returns a string representation of the contents of given object with special care for potential arrays, the output is cut - for each potentially contained array - to maxSize.
static String toString(short[] array)
          Returns a string representation of the contents of the specified array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toString

public static String toString(Object array)
Returns a string representation of the contents of given object with special care for potential arrays. For none array objects the toString method is invoked, for arrays the content of the array is converted. If the array contains other arrays as elements, they are also get their content dumped.

The value returned by this method is equal to the value that would be returned by Arrays.asList(a).toString(), unless array is null, in which case "null" is returned.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
  CLASSNAME, "foo(Object[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.

toString

public static String toString(Object array,
                              int maxSize)
Returns a string representation of the contents of given object with special care for potential arrays, the output is cut - for each potentially contained array - to maxSize.

If one of the contained arrays contains more than maxSize elements, the dump is stopped and the number of total elements is printed in the output, for the particular array.

Parameters:
array - The array whose string representation to return.
maxSize - the maximum number of elements to print, will be ignored if set to 0 or below.
Returns:
A string representation of array.
See Also:
toString(Object)

toString

public static String toString(Object[] array)
Returns a string representation of the contents of the specified array. If the array contains other arrays as elements, they are converted to strings by the Object.toString()method inherited from Object, which describes their identities rather than their contents.

The value returned by this method is equal to the value that would be returned by Arrays.asList(a).toString(), unless array is null, in which case "null" is returned.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(Object[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.

toString

public static String toString(Object[] array,
                              int maxSize)
Returns a string representation of the contents of the specified array with a maxSize limitation.

The value returned by this method is equal to the value that would be returned by Arrays.asList(a).toString(), unless array is null, in which case "null" is returned.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(Object[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
maxSize - the maximum number of elements to print, will be ignored if set to 0 or below.
Returns:
A string representation of array.

toString

public static String toString(int[] array)
Returns a string representation of the contents of the specified array.

The value dumps all int stored in the given array.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(int[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.

toString

public static String toString(short[] array)
Returns a string representation of the contents of the specified array.

The value dumps all short stored in the given array.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(short[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.

toString

public static String toString(long[] array)
Returns a string representation of the contents of the specified array.

The value dumps all long stored in the given array.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(long[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.

toString

public static String toString(byte[] array)
Returns a string representation of the contents of the specified array.

The value dumps all byte values stored in the given array.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(byte[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.

toString

public static String toString(char[] array)
Returns a string representation of the contents of the specified array.

The value dumps all char values stored in the given array.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(char[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.

toString

public static String toString(boolean[] array)
Returns a string representation of the contents of the specified array.

The value dumps all boolean values stored in the given array.

This method is useful to dump the content of the array in a tracing method, e.g.:

 logger.entering(
     CLASSNAME, "foo(boolean[])", ArraysUtil.toString(array));
 

Parameters:
array - The array whose string representation to return.
Returns:
A string representation of array.


Copyright 2007 The jCoderZ Project.