org.unitils.core.util
Class ArrayAndCollectionFormatter

java.lang.Object
  extended by org.unitils.core.util.ArrayAndCollectionFormatter

public class ArrayAndCollectionFormatter
extends Object

Helper class for generating a string representation of a collection or array.

Author:
Tim Ducheyne, Filip Neven

Field Summary
protected  int maxNrOfElements
           
protected  ObjectFormatter objectFormatter
           
 
Constructor Summary
ArrayAndCollectionFormatter(int maxNrOfElements, ObjectFormatter objectFormatter)
          Creates a formatter with the given maximum nr of elements.
 
Method Summary
 void formatArray(Object array, int currentDepth, StringBuilder result)
          Formats the given array.
protected  void formatBooleanArray(boolean[] array, StringBuilder result)
           
protected  void formatByteArray(byte[] array, StringBuilder result)
           
protected  void formatCharArray(char[] array, StringBuilder result)
           
 void formatCollection(Collection<?> collection, int currentDepth, StringBuilder result)
          Formats the given collection.
protected  void formatDoubleArray(double[] array, StringBuilder result)
           
protected  void formatFloatArray(float[] array, StringBuilder result)
           
protected  void formatIntArray(int[] array, StringBuilder result)
           
protected  void formatLongArray(long[] array, StringBuilder result)
           
 void formatMap(Map<?,?> map, int currentDepth, StringBuilder result)
          Formats the given map.
protected  void formatObjectArray(Object[] array, int currentDepth, StringBuilder result)
           
protected  void formatShortArray(short[] array, StringBuilder result)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxNrOfElements

protected int maxNrOfElements

objectFormatter

protected ObjectFormatter objectFormatter
Constructor Detail

ArrayAndCollectionFormatter

public ArrayAndCollectionFormatter(int maxNrOfElements,
                                   ObjectFormatter objectFormatter)
Creates a formatter with the given maximum nr of elements.

Parameters:
maxNrOfElements - The maximum nr of elements for arrays and collections to display > 0
objectFormatter - The object formatter that uses this array/collection formatter, not null
Method Detail

formatArray

public void formatArray(Object array,
                        int currentDepth,
                        StringBuilder result)
Formats the given array.

Parameters:
array - The array, not null
currentDepth - The current recursion depth
result - The builder to append the result to, not null

formatCollection

public void formatCollection(Collection<?> collection,
                             int currentDepth,
                             StringBuilder result)
Formats the given collection.

Parameters:
collection - The collection, not null
currentDepth - The current recursion depth
result - The builder to append the result to, not null

formatMap

public void formatMap(Map<?,?> map,
                      int currentDepth,
                      StringBuilder result)
Formats the given map.

Parameters:
map - The map, not null
currentDepth - The current recursion depth
result - The builder to append the result to, not null

formatObjectArray

protected void formatObjectArray(Object[] array,
                                 int currentDepth,
                                 StringBuilder result)

formatByteArray

protected void formatByteArray(byte[] array,
                               StringBuilder result)

formatShortArray

protected void formatShortArray(short[] array,
                                StringBuilder result)

formatIntArray

protected void formatIntArray(int[] array,
                              StringBuilder result)

formatLongArray

protected void formatLongArray(long[] array,
                               StringBuilder result)

formatCharArray

protected void formatCharArray(char[] array,
                               StringBuilder result)

formatFloatArray

protected void formatFloatArray(float[] array,
                                StringBuilder result)

formatDoubleArray

protected void formatDoubleArray(double[] array,
                                 StringBuilder result)

formatBooleanArray

protected void formatBooleanArray(boolean[] array,
                                  StringBuilder result)


Copyright © 2011. All Rights Reserved.