com.cleancode.util
Class ArrayPlus

java.lang.Object
  extended by com.cleancode.util.ArrayPlus

public final class ArrayPlus
extends Object

Convenience methods for array handling.

Since:
CleanCode 0.9.02
Version:
$Revision: 9 $
Author:
Michael Sorens

Field Summary
static String NL
          System dependent line separator.
 
Method Summary
static String arrayToString(Object[] data)
          Convert a 1-dimensional Object array into a String representation.
static String arrayToString(Object[][] data)
          Convert a 2-dimensional Object array into a String representation.
static String join(char separator, Object[] anArray)
          Joins array elements into a String with the specified separator character.
static String join(String separator, Object[] anArray)
          Joins array elements into a String with the specified separator string.
static String joinDecl(Object[] anArray)
          Joins array elements into a String with the specified separator string, formatting the array as a Java declaration.
static String[] push(String[] anArray, String item)
          Adds new last element to a String array.
static String[] shift(String[] anArray)
          Removes first element of a String array.
static String[] shift(String[] anArray, int n)
          Removes 'n' elements of a String array.
static String[] toStringArray(ArrayList data)
          Convert an ArrayList containing strings into an array of String (maintaining its String-iness rather than getting an Object array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NL

public static final String NL
System dependent line separator.

Method Detail

toStringArray

public static String[] toStringArray(ArrayList data)
Convert an ArrayList containing strings into an array of String (maintaining its String-iness rather than getting an Object array.

Parameters:
data - ArrayList containing String objects
Returns:
String array

arrayToString

public static String arrayToString(Object[][] data)
Convert a 2-dimensional Object array into a String representation. Columns are tab-separated; rows are on separate lines.

Parameters:
data - 2-dimensional array
Returns:
String representation of array

arrayToString

public static String arrayToString(Object[] data)
Convert a 1-dimensional Object array into a String representation. Items are on separate lines.

Parameters:
data - 1-dimensional array
Returns:
String representation of array

shift

public static String[] shift(String[] anArray)
Removes first element of a String array.

Parameters:
anArray - array of String objects
Returns:
a new array without the first element

shift

public static String[] shift(String[] anArray,
                             int n)
Removes 'n' elements of a String array.

Parameters:
anArray - array of String objects
n - number of elements to remove
Returns:
a new array without the first 'n' element

push

public static String[] push(String[] anArray,
                            String item)
Adds new last element to a String array.

Parameters:
anArray - an array of String objects
item - a String to push onto the array
Returns:
a new array with the item as the new last element

join

public static String join(char separator,
                          Object[] anArray)
Joins array elements into a String with the specified separator character.

Parameters:
separator - character to use to join the array elements
anArray - array of String objects
Returns:
a string with all array elements joined by separators

join

public static String join(String separator,
                          Object[] anArray)
Joins array elements into a String with the specified separator string.

Parameters:
separator - string to use to join the array elements
anArray - array of String objects
Returns:
a string with all array elements joined by separators

joinDecl

public static String joinDecl(Object[] anArray)
Joins array elements into a String with the specified separator string, formatting the array as a Java declaration.

Parameters:
anArray - array of String objects
Returns:
a string representing a Java declaration for the array


CleanCode Java Libraries Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads