edu.jhu.tmaj.util
Class ListConvertUtil

java.lang.Object
  extended by edu.jhu.tmaj.util.ListConvertUtil

public final class ListConvertUtil
extends java.lang.Object

Provides methods for converting and printing information about Collections and arrays.


Method Summary
static java.util.List<java.util.List> arrayTo2dList(java.lang.Object[][] array)
           
static java.util.List arrayToList(java.lang.Object[] array)
          Converts an Array of Objects to a List of Objects.
static java.util.Set arrayToSet(java.lang.Object[] objects)
          Converts an array into a Set.
static java.lang.String arrayToString(java.lang.Object[] objects)
          Returns a description of every object in the provided Array.
static java.util.List<java.lang.Boolean> booleanArrayPrimitiveAsList(boolean[] bools)
           
static java.lang.String[] concatStringArrays(java.lang.String[] strings1, java.lang.String[] strings2)
          Merges Two String arrays into one big array.
static
<T> java.util.Vector
convertCollectionToVector(java.util.Collection<T> collection)
           
static java.util.List<java.util.Map> convertListOfLists_TO_ListOfMaps(java.util.List<java.util.List> listOfLists, java.util.List fieldNames)
          Convert List-of-List (spreadsheet) to a List-of-Maps.
static java.util.List<java.lang.String> convertListOfLists_TO_ListOfTabDelimitedStrings(java.util.List<java.util.List> listsList)
           
static java.util.List<java.util.List> convertListOfMaps_TO_ListOfLists(java.util.List<java.util.Map> listOfMaps, java.util.List fieldNames)
          Convert a List of Maps into a SpreadSheet-like List-Of-Lists.
static java.util.List<java.util.Map<java.lang.String,java.lang.String>> convertListOfStringsToListOfMaps(java.util.List<java.lang.String> listOfStrings)
          Converts a List of tab-delimited Strings into a List of Maps.
static java.util.List<java.lang.Double> doubleArrayToList(double[] doubles)
          Converts an doubles array to a List of Doubles.
static java.util.Set getAllKeys(java.util.List<java.util.Map> listOfMaps)
          Gets a Map containing the union of all keys found in many Maps
static java.lang.String getListDescription(java.util.List list)
          Returns a description of every object in the provided List.
static java.lang.String getObjectDescription(java.lang.Object obj)
          Returns a description of an Object including its toString() value and its class name.
static java.util.Map getObjectFrequencyHash(java.util.List list)
           
static java.lang.String intArrayToCommaParenthesisString(int[] values)
          Converts an array of ints to a comma-delimited String with parenthesis at the beginning and end.
static java.lang.String listToCommaDelimitedString(java.util.List list)
          Converts a List to one big comma-delimited String.
static java.lang.String listToDelimitedString(java.util.List list, java.lang.String delimiter)
          Converts a list to a String where the elements of the list are delimited by the specified delimiter.
static int[] listToIntArray(java.util.List<java.lang.Integer> intList)
          Converts an int array to a List of Doubles.
static java.lang.String listToString(java.util.List list, java.lang.String delimiter)
          A useful join() function
static java.lang.String listToTabDelimitedString(java.util.List list)
          Converts a list to a tab-delimited String
static java.util.List<java.lang.String> prefixList(java.util.List list, java.lang.String prefix)
           
static java.util.List<java.lang.String> purgeEmptyStrings(java.util.List<java.lang.String> listOfStrings)
          Returns a list where any strings that were empty have been removed.
static java.lang.String setToCommaDelimitedString(java.util.Set set)
           
static java.lang.String stringArrayToString(java.lang.String[] values, java.lang.String delimiter)
          Converts an array of Strings one big comma-delimited String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

convertListOfLists_TO_ListOfMaps

public static java.util.List<java.util.Map> convertListOfLists_TO_ListOfMaps(java.util.List<java.util.List> listOfLists,
                                                                             java.util.List fieldNames)
Convert List-of-List (spreadsheet) to a List-of-Maps.

Parameters:
listOfLists - A List of List of Objects, representing the data in a spread sheet. For example, listOfLists.get(10).get(20) represents row=11 column=21. The Objects represent a cell's data. Note the first List does NOT contain the fieldNames.
fieldNames - The field names of the data. Thus, listOfLists.get(x).size()==fieldNames.size() *
Returns:
a List of Maps. The keys of the Maps are the fieldNames.

convertListOfMaps_TO_ListOfLists

public static java.util.List<java.util.List> convertListOfMaps_TO_ListOfLists(java.util.List<java.util.Map> listOfMaps,
                                                                              java.util.List fieldNames)
Convert a List of Maps into a SpreadSheet-like List-Of-Lists.

Parameters:
listOfMaps - a list of Maps, where each Map represents on row.
fieldNames - the FieldNames found in the Maps. The order will determine the order in the List. It is not necessary for all the Maps to have each of the FieldNames. If the key is missing in the Map, a default NOT_FOUND_STRING of " " in used as the value.
Returns:
A List of Lists (a spreadsheet-like structure.) The first row is NOT the fieldNames.

listToTabDelimitedString

public static java.lang.String listToTabDelimitedString(java.util.List list)
Converts a list to a tab-delimited String


convertListOfLists_TO_ListOfTabDelimitedStrings

public static java.util.List<java.lang.String> convertListOfLists_TO_ListOfTabDelimitedStrings(java.util.List<java.util.List> listsList)

listToDelimitedString

public static java.lang.String listToDelimitedString(java.util.List list,
                                                     java.lang.String delimiter)
Converts a list to a String where the elements of the list are delimited by the specified delimiter.


purgeEmptyStrings

public static java.util.List<java.lang.String> purgeEmptyStrings(java.util.List<java.lang.String> listOfStrings)
Returns a list where any strings that were empty have been removed.


convertListOfStringsToListOfMaps

public static java.util.List<java.util.Map<java.lang.String,java.lang.String>> convertListOfStringsToListOfMaps(java.util.List<java.lang.String> listOfStrings)
Converts a List of tab-delimited Strings into a List of Maps. A List of tab-delimited Strings if often read from a tab-delimited file.

Parameters:
listOfStrings - a List of tab-delimited Strings; the first row represents the column names
Returns:
a List of Maps. The keys are the fieldNames, and the values the cell-value of the row.

arrayToList

public static java.util.List arrayToList(java.lang.Object[] array)
Converts an Array of Objects to a List of Objects.


arrayTo2dList

public static java.util.List<java.util.List> arrayTo2dList(java.lang.Object[][] array)

intArrayToCommaParenthesisString

public static java.lang.String intArrayToCommaParenthesisString(int[] values)
Converts an array of ints to a comma-delimited String with parenthesis at the beginning and end.


stringArrayToString

public static java.lang.String stringArrayToString(java.lang.String[] values,
                                                   java.lang.String delimiter)
Converts an array of Strings one big comma-delimited String.


listToCommaDelimitedString

public static java.lang.String listToCommaDelimitedString(java.util.List list)
Converts a List to one big comma-delimited String.


setToCommaDelimitedString

public static java.lang.String setToCommaDelimitedString(java.util.Set set)

concatStringArrays

public static java.lang.String[] concatStringArrays(java.lang.String[] strings1,
                                                    java.lang.String[] strings2)
Merges Two String arrays into one big array.


getObjectDescription

public static java.lang.String getObjectDescription(java.lang.Object obj)
Returns a description of an Object including its toString() value and its class name.


getListDescription

public static java.lang.String getListDescription(java.util.List list)
Returns a description of every object in the provided List.


arrayToString

public static java.lang.String arrayToString(java.lang.Object[] objects)
Returns a description of every object in the provided Array.


getAllKeys

public static java.util.Set getAllKeys(java.util.List<java.util.Map> listOfMaps)
Gets a Map containing the union of all keys found in many Maps

Parameters:
listOfMaps - self-explanatory
Returns:
a Set containing all keys that are found in 1 or more of the Maps in the List

prefixList

public static java.util.List<java.lang.String> prefixList(java.util.List list,
                                                          java.lang.String prefix)

arrayToSet

public static java.util.Set arrayToSet(java.lang.Object[] objects)
Converts an array into a Set.


convertCollectionToVector

public static <T> java.util.Vector convertCollectionToVector(java.util.Collection<T> collection)

doubleArrayToList

public static java.util.List<java.lang.Double> doubleArrayToList(double[] doubles)
Converts an doubles array to a List of Doubles.


listToIntArray

public static int[] listToIntArray(java.util.List<java.lang.Integer> intList)
Converts an int array to a List of Doubles.


listToString

public static java.lang.String listToString(java.util.List list,
                                            java.lang.String delimiter)
A useful join() function


getObjectFrequencyHash

public static java.util.Map getObjectFrequencyHash(java.util.List list)

booleanArrayPrimitiveAsList

public static java.util.List<java.lang.Boolean> booleanArrayPrimitiveAsList(boolean[] bools)