com.bristle.javalib.util
Class ListUtil

java.lang.Object
  extended by com.bristle.javalib.util.ListUtil

public class ListUtil
extends Object

This class contains utility routines for manipulating Java Lists.

Usage:
   - The typical scenario for using this class is:
       String str1 = ListUtil.listToString(list1);

   - See the source code of the inner Tester class for more examples.
  
Assumptions:
Effects:
       - None.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class ListUtil.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Constructor Summary
ListUtil()
           
 
Method Summary
static boolean haveEqualContents(List list1, List list2)
          Return true if the two Lists contains equal elements or are both null or both empty; false otherwise.
static boolean haveIdenticalContents(List list1, List list2)
          Return true if the two Lists contains the same elements or are both null or both empty; false otherwise.
static String listToString(List list)
          Return a String version of the List.
static List toList(Enumeration enumeration)
          Return a new List copied from the specified Enumeration, or null if the Enumeration is null.
static List toList(Iterator iter)
          Return a new List copied from the specified Iterator, or null if the Iterator is null.
static List toList(Object[] arr)
          Create a List from the specified array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListUtil

public ListUtil()
Method Detail

listToString

public static String listToString(List list)
Return a String version of the List.

Parameters:
list - List to convert to a String.
Returns:
String version of the List.

toList

public static List toList(Object[] arr)
Create a List from the specified array. Note: Same as Arrays.asList, except it tolerates null, returning null.

Parameters:
arr - Array of Objects to put in the List.
Returns:
The new List, or null.

toList

public static List toList(Iterator iter)
Return a new List copied from the specified Iterator, or null if the Iterator is null. Note: This leaves the Iterator with hasNext() == false.

Parameters:
iter - Iterator to copy to a new List.
Returns:
The new List.

toList

public static List toList(Enumeration enumeration)
Return a new List copied from the specified Enumeration, or null if the Enumeration is null. Note: This leaves the Enumeration with hasMoreElements() == false.

Parameters:
enumeration - Enumeration to copy to a new List.
Returns:
The new List.

haveIdenticalContents

public static boolean haveIdenticalContents(List list1,
                                            List list2)
Return true if the two Lists contains the same elements or are both null or both empty; false otherwise. Note: Elements must be exactly the same. "==", not just equals().

Parameters:
list1 - List to compare.
list2 - List to compare.
Returns:
true if the same, false otherwise.

haveEqualContents

public static boolean haveEqualContents(List list1,
                                        List list2)
Return true if the two Lists contains equal elements or are both null or both empty; false otherwise. Note: Elements may not be identical. May be just equals(), not "==".

Parameters:
list1 - List to compare.
list2 - List to compare.
Returns:
true if equal, false otherwise.