org.af.commons.tools
Class ListTools

java.lang.Object
  extended by org.af.commons.tools.ListTools

public class ListTools
extends Object


Constructor Summary
ListTools()
           
 
Method Summary
static
<E> List<E>
copyAndAdd(List<E> xs, E x)
          Copies a list (shallow copy) and adds an element at the end.
static
<E> List<String>
toString(List<E> xs)
          Converts a list to a list of strings by calling toString on every entry.
static String[] toStringArray(List xs)
          Converts a List to an array of Strings by calling toString on every entry.
static
<E,F> List<F>
transform(List<E> xs, String method)
          Transforms a list by calling a method on every element of the list by using reflection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListTools

public ListTools()
Method Detail

toStringArray

public static String[] toStringArray(List xs)
Converts a List to an array of Strings by calling toString on every entry.

Parameters:
xs - The list.
Returns:
String array.

toString

public static <E> List<String> toString(List<E> xs)
Converts a list to a list of strings by calling toString on every entry.

Parameters:
xs - The list.
Returns:
List of strings.

transform

public static <E,F> List<F> transform(List<E> xs,
                                      String method)
Transforms a list by calling a method on every element of the list by using reflection. The method is specified by its name, must have no arguments and return an object. Otherwise a runtime exception might be thrown.

Type Parameters:
E - Base type of the list.
F - Type that the call to method returns
Parameters:
xs - The list.
method - The name of the method to call.
Returns:
Transformed list of base type F.

copyAndAdd

public static <E> List<E> copyAndAdd(List<E> xs,
                                     E x)
Copies a list (shallow copy) and adds an element at the end.

Type Parameters:
E - Type for the list.
Parameters:
xs - The list.
x - The Element to add.
Returns:
Copied list with added element.