Class ListUtils

java.lang.Object
uk.ac.ebi.utils.collections.ListUtils

public class ListUtils extends Object
Miscellanea utilities about lists.
Author:
brandizi date: Dec 13, 2009
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> void
    add(List<T> list, int i, T v)
    Adds the element i in list, as in List.add(int, Object), but independently on list.size().
    static <T> T
    get(List<T> list, int i)
    Gets the i element of list, independently on list.size().
    static OptionsMap
    getRow(String[] headers, Object[] row)
    A little helper, which turns a row (typically from a table) into a dictionary, where the keys are the column headers.
    static <T> T
    set(List<T> list, int i, T v)
    Sets the element i in list, independently on the list size.
    static <T> List<T>
    union(List<? extends T>... lists)
    The union of all the parameters (the list elements) in a single list

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ListUtils

      public ListUtils()
  • Method Details

    • set

      public static <T> T set(List<T> list, int i, T v)
      Sets the element i in list, independently on the list size. That is: if i < list.size() calls list.set (i, v), otherwise adds i - list.size() null elements to list and then adds v as the last element, which will be the i element.
    • get

      public static <T> T get(List<T> list, int i)
      Gets the i element of list, independently on list.size(). That is: i < list.size () ? list.get ( i ) : null
    • add

      public static <T> void add(List<T> list, int i, T v)
      Adds the element i in list, as in List.add(int, Object), but independently on list.size(). That is: calls list.add (i, v) if i <= list.size() (and shifts all elements from i upward as usually), calls set ( list, i, v) otherwise (i.e.: adds null element up to i-1 and v as last element).
    • union

      public static <T> List<T> union(List<? extends T>... lists)
      The union of all the parameters (the list elements) in a single list
    • getRow

      public static OptionsMap getRow(String[] headers, Object[] row)
      A little helper, which turns a row (typically from a table) into a dictionary, where the keys are the column headers. In other words, the result is such that:
      result [ headers[j] ] == row [j], for j in [0..min-len (headers, row) )
      Throws:
      IllegalArgumentException - if headers is null or empty, to prevent serious misses from a table. If the row is null or empty, it returns an empty dictionary, since this often happens for inputs like CSV.