net.sf.okapi.common

## Class ListUtil

- java.lang.Object
- - net.sf.okapi.common.ListUtil

-     public class ListUtil
      extends java.lang.Object

  Helper methods to manipulate lists.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ListUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <E> java.util.List<E>` | `arrayAsList(E[] array)` Converts a given array to a list containing all elements of the original array.
    `static java.lang.String` | `arrayAsString(java.lang.String[] array)` Returns a string, representing a given array of strings.
    `static java.lang.String` | `arrayAsString(java.lang.String[] array, java.lang.String delimiter)` Returns a string, representing a given array of strings.
    `static java.lang.Class<?>[]` | `classListAsArray(java.util.List<java.lang.Class<?>> list)` Converts a list of class references into an array of those class references.
    `static <E> java.util.List<E>` | `copyItems(java.util.List<E> list, int start, int end)` Creates a new list from a range of elements of a given list.
    `static <E> E` | `getFirstNonNullItem(java.util.List<E> list)` Gets a first non-null element of a given list.
    `static java.lang.String` | `intListAsString(java.util.List<java.lang.Integer> list)` Returns a string, representing a given list of integers.
    `static java.lang.String` | `intListAsString(java.util.List<java.lang.Integer> list, java.lang.String delimiter)` Returns a string, representing a given list of integers.
    `static <E> java.util.List<E>` | `invert(java.util.List<E> list)` Returns a copy of the specified list in reverse order.
    `static java.lang.String` | `listAsString(java.util.List<java.lang.String> list)` Returns a string, representing a given list of strings.
    `static java.lang.String` | `listAsString(java.util.List<java.lang.String> list, java.lang.String delimiter)` Returns a string, representing a given list of strings.
    `static void` | `listTrimTrail(java.util.List<java.lang.String> list)` Remove empty trailing elements of the given list.
    `static java.util.List<java.lang.String>` | `listTrimValues(java.util.List<java.lang.String> list)` Creates a list, containing all trimmed values of a given list of strings.
    `static java.util.List<java.lang.String>` | `loadList(java.lang.Class<?> classRef, java.lang.String resourceLocation)` Creates a new list of strings and fills it with the data read from a given resource.
    `static void` | `loadList(java.util.List<java.lang.String> list, java.lang.Class<?> classRef, java.lang.String resourceLocation)` Fills in an existing list of strings with the data read from a given resource.
    `static java.lang.String` | `merge(java.util.List<java.lang.String> list, int start, int end, java.lang.String joiner)` Merges specified items of a given string list into a single string.
    `static java.lang.String` | `merge(java.lang.String[] array, int start, int end, java.lang.String joiner)` Merges specified elements of a given string array into a single string.
    `static <E> java.util.List<E>` | `moveItems(java.util.List<E> buffer)` Moves all items from a given list to a newly created list.
    `static <E> java.util.List<E>` | `moveItems(java.util.List<E> buffer, int start, int end)` Creates a new list and moves therein a range of elements from a given list.
    `static java.lang.Object[]` | `objectListAsArray(java.util.List<java.lang.Object> list)` Converts a list of objects into an array of those objects.
    `static <E> void` | `remove(java.util.List<E> list, int start, int end)` Removes a range of elements from a given list.
    `static java.lang.String[]` | `stringAsArray(java.lang.String st)` Splits up a string of comma-separated substrings into an array of those substrings.
    `static java.lang.String[]` | `stringAsArray(java.lang.String st, java.lang.String delimiter)` Splits up a string of comma-separated substrings into an array of those substrings.
    `static java.util.List<java.lang.Integer>` | `stringAsIntList(java.lang.String st)` Converts a string of comma-separated numbers into a list of integers.
    `static java.util.List<java.lang.Integer>` | `stringAsIntList(java.lang.String st, java.lang.String delimiter)` Converts a string of comma-separated numbers into a list of integers and sorts the list ascendantly.
    `static java.util.List<java.lang.Integer>` | `stringAsIntList(java.lang.String st, java.lang.String delimiter, boolean sortList)` Converts a string of comma-separated numbers into a list of integers.
    `static java.util.List<LocaleId>` | `stringAsLanguageList(java.lang.String input)` Splits up a string of comma-separated substrings representing locale codes into a string list of `LocaleId` objects.
    `static void` | `stringAsList(java.util.List<java.lang.String> list, java.lang.String st)` Splits up a string of comma-separated substrings into a string list of those substrings.
    `static void` | `stringAsList(java.util.List<java.lang.String> list, java.lang.String st, java.lang.String delimiter)` Splits up a string of delimited substrings into a string list of those substrings.
    `static java.util.List<java.lang.String>` | `stringAsList(java.lang.String st)` Splits up a string of comma-separated substrings into a string list of those substrings.
    `static java.util.List<java.lang.String>` | `stringAsList(java.lang.String st, char delimiter)` Splits up a string of delimited substrings into a string list of those substrings.
    `static java.util.List<java.lang.String>` | `stringAsList(java.lang.String st, java.lang.String delimiter)` Splits up a string of delimited substrings into a string list of those substrings.
    `static java.lang.String[]` | `stringListAsArray(java.util.List<java.lang.String> list)` Converts a list of strings into an array of those strings.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ListUtil

          public ListUtil()

  - ### Method Detail

    - #### stringAsList

          public static java.util.List<java.lang.String> stringAsList(java.lang.String st)

      Splits up a string of comma-separated substrings into a string list of those substrings.
      Parameters:
        `st` - string of comma-separated substrings.
      Returns:
        a list of substrings.

    - #### stringAsLanguageList

          public static java.util.List<LocaleId> stringAsLanguageList(java.lang.String input)

      Splits up a string of comma-separated substrings representing locale codes into a string list of `LocaleId` objects.
      Parameters:
        `input` - string of comma-separated substrings.
      Returns:
        a list of `LocaleId` objects.

    - #### stringAsList

          public static void stringAsList(java.util.List<java.lang.String> list,
                          java.lang.String st)

      Splits up a string of comma-separated substrings into a string list of those substrings.
      Parameters:
        `list` - a list to put the substrings.
        `st` - string of comma-separated substrings.

    - #### stringAsList

          public static java.util.List<java.lang.String> stringAsList(java.lang.String st,
                                                      java.lang.String delimiter)

      Splits up a string of delimited substrings into a string list of those substrings.
      Parameters:
        `st` - string of delimited substrings.
        `delimiter` - a string delimiting substrings in the string.
      Returns:
        a list of substrings.

    - #### stringAsList

          public static java.util.List<java.lang.String> stringAsList(java.lang.String st,
                                                      char delimiter)

      Splits up a string of delimited substrings into a string list of those substrings.
      Parameters:
        `st` - string of delimited substrings.
        `delimiter` - a character delimiting substrings in the string.
      Returns:
        a list of substrings.

    - #### stringAsList

          public static void stringAsList(java.util.List<java.lang.String> list,
                          java.lang.String st,
                          java.lang.String delimiter)

      Splits up a string of delimited substrings into a string list of those substrings.
      Parameters:
        `list` - a list to put the substrings.
        `st` - string of delimited substrings.
        `delimiter` - a string delimiting substrings in the string.

    - #### stringAsArray

          public static java.lang.String[] stringAsArray(java.lang.String st)

      Splits up a string of comma-separated substrings into an array of those substrings.
      Parameters:
        `st` - string of comma-separated substrings.
      Returns:
        the generated array of strings.

    - #### stringAsArray

          public static java.lang.String[] stringAsArray(java.lang.String st,
                                         java.lang.String delimiter)

      Splits up a string of comma-separated substrings into an array of those substrings.
      Parameters:
        `st` - string of comma-separated substrings.
        `delimiter` - a string delimiting substrings in the string.
      Returns:
        the generated array of strings.

    - #### merge

          public static java.lang.String merge(java.lang.String[] array,
                               int start,
                               int end,
                               java.lang.String joiner)

      Merges specified elements of a given string array into a single string. The merged elements are joined with a given joiner.
      Parameters:
        `array` - the given array of strings.
        `start` - index of the start element to be merged.
        `end` - index of the end element (inclusive) to be merged.
        `joiner` - string to join elements in the resulting string.
      Returns:
        the string of merged elements.

    - #### merge

          public static java.lang.String merge(java.util.List<java.lang.String> list,
                               int start,
                               int end,
                               java.lang.String joiner)

      Merges specified items of a given string list into a single string. The merged items are joined with a given joiner.
      Parameters:
        `list` - the given list of strings.
        `start` - index of the start item to be merged.
        `end` - index of the end item (inclusive) to be merged.
        `joiner` - string to join items in the resulting string.
      Returns:
        the string of merged items.

    - #### stringAsIntList

          public static java.util.List<java.lang.Integer> stringAsIntList(java.lang.String st)

      Converts a string of comma-separated numbers into a list of integers.
      Parameters:
        `st` - string of comma-separated numbers.
      Returns:
        a list of integers.

    - #### stringAsIntList

          public static java.util.List<java.lang.Integer> stringAsIntList(java.lang.String st,
                                                          java.lang.String delimiter)

      Converts a string of comma-separated numbers into a list of integers and sorts the list ascendantly.
      Parameters:
        `st` - string of comma-separated numbers
        `delimiter` - a string delimiting numbers in the string
      Returns:
        a list of integers

    - #### stringAsIntList

          public static java.util.List<java.lang.Integer> stringAsIntList(java.lang.String st,
                                                          java.lang.String delimiter,
                                                          boolean sortList)

      Converts a string of comma-separated numbers into a list of integers.
      Parameters:
        `st` - string of comma-separated numbers
        `delimiter` - a string delimiting numbers in the string
        `sortList` - if the numbers in the resulting list should be sorted (ascendantly)
      Returns:
        a list of integers

    - #### listTrimTrail

          public static void listTrimTrail(java.util.List<java.lang.String> list)

      Remove empty trailing elements of the given list. Possible empty elements in the head and middle of the list remain if located before a non-empty element.
      Parameters:
        `list` - the list to be trimmed.

    - #### listTrimValues

          public static java.util.List<java.lang.String> listTrimValues(java.util.List<java.lang.String> list)

      Creates a list, containing all trimmed values of a given list of strings. Empty elements remain on the list, non-empty ones are trimmed from both sides. The given list is not changed.
      Parameters:
        `list` - the given list of strings.
      Returns:
        the list with trimmed elements.

    - #### stringListAsArray

          public static java.lang.String[] stringListAsArray(java.util.List<java.lang.String> list)

      Converts a list of strings into an array of those strings.
      Parameters:
        `list` - List of strings.
      Returns:
        an array of strings.

    - #### classListAsArray

          public static java.lang.Class<?>[] classListAsArray(java.util.List<java.lang.Class<?>> list)

      Converts a list of class references into an array of those class references.
      Parameters:
        `list` - List of class references.
      Returns:
        An array of class references.

    - #### objectListAsArray

          public static java.lang.Object[] objectListAsArray(java.util.List<java.lang.Object> list)

      Converts a list of objects into an array of those objects.
      Parameters:
        `list` - List of objects.
      Returns:
        an array of objects.

    - #### arrayAsList

          public static <E> java.util.List<E> arrayAsList(E[] array)

      Converts a given array to a list containing all elements of the original array. The resulting list is not backed by the given array. (Changes to the returned list DO NOT "write through" to the array and vice versa.)
      Type Parameters:
        `E` - the type of the array's element.
      Parameters:
        `array` - the given array.
      Returns:
        the list of all elements contained in the given array.

    - #### arrayAsString

          public static java.lang.String arrayAsString(java.lang.String[] array)

      Returns a string, representing a given array of strings. Array elements are separated with a comma in the resulting string.
      Parameters:
        `array` - the given array of strings.
      Returns:
        the string with comma-separated elements of the given array.

    - #### arrayAsString

          public static java.lang.String arrayAsString(java.lang.String[] array,
                                       java.lang.String delimiter)

      Returns a string, representing a given array of strings. Array elements in the resulting string are separated with a given delimiter.
      Parameters:
        `array` - the given array of strings.
        `delimiter` - the given delimiter.
      Returns:
        the string with delimited elements of the given array.

    - #### listAsString

          public static java.lang.String listAsString(java.util.List<java.lang.String> list)

      Returns a string, representing a given list of strings. List elements are separated with a comma in the resulting string.
      Parameters:
        `list` - the given list of strings.
      Returns:
        the string with comma-separated elements of the given list.

    - #### listAsString

          public static java.lang.String listAsString(java.util.List<java.lang.String> list,
                                      java.lang.String delimiter)

      Returns a string, representing a given list of strings. List elements in the resulting string are separated with a given delimiter.
      Parameters:
        `list` - the given list of strings.
        `delimiter` - the given delimiter.
      Returns:
        the string with delimited elements of the given list.

    - #### intListAsString

          public static java.lang.String intListAsString(java.util.List<java.lang.Integer> list)

      Returns a string, representing a given list of integers. List elements are converted into strings ("12" for 12 etc.) and separated with a comma in the resulting string.
      Parameters:
        `list` - the given list of integers.
      Returns:
        the string with comma-separated converted elements of the given list.

    - #### intListAsString

          public static java.lang.String intListAsString(java.util.List<java.lang.Integer> list,
                                         java.lang.String delimiter)

      Returns a string, representing a given list of integers. List elements are converted into strings ("12" for 12 etc.) and separated with a given delimiter.
      Parameters:
        `list` - the given list of integers.
        `delimiter` - the given delimiter.
      Returns:
        the string with delimited converted elements of the given list.

    - #### invert

          public static <E> java.util.List<E> invert(java.util.List<E> list)

      Returns a copy of the specified list in reverse order. Differs from `Collections#reverse` in that it does not modify the original list.
      Parameters:
        `list` - the list to reverse.
      Returns:
        a copy of the reverted list.

    - #### remove

          public static <E> void remove(java.util.List<E> list,
                        int start,
                        int end)

      Removes a range of elements from a given list.
      Type Parameters:
        `E` - the type of the list's element.
      Parameters:
        `list` - the given list.
        `start` - the start index (inclusive) to be removed.
        `end` - the end index (exclusive) to be removed.

    - #### copyItems

          public static <E> java.util.List<E> copyItems(java.util.List<E> list,
                                        int start,
                                        int end)

      Creates a new list from a range of elements of a given list.
      Type Parameters:
        `E` - the type of the list's element.
      Parameters:
        `list` - the given list.
        `start` - the start index (inclusive) to be included in the resulting list.
        `end` - the end index (exclusive) to be included in the resulting list.
      Returns:
        a new list, containing all elements in the specified range of the given list.

    - #### moveItems

          public static <E> java.util.List<E> moveItems(java.util.List<E> buffer,
                                        int start,
                                        int end)

      Creates a new list and moves therein a range of elements from a given list. The given list won't contain the moved elements anymore.
      Type Parameters:
        `E` - the type of the list's element.
      Parameters:
        `buffer` - the given list.
        `start` - the start index (inclusive) to be included in the resulting list.
        `end` - the end index (exclusive) to be included in the resulting list.
      Returns:
        a new list, containing all elements in the specified range of the given list.

    - #### moveItems

          public static <E> java.util.List<E> moveItems(java.util.List<E> buffer)

      Moves all items from a given list to a newly created list. The given list won't contain the moved elements anymore.
      Type Parameters:
        `E` - the type of the list's element.
      Parameters:
        `buffer` - the given list.
      Returns:
        the resulting list, containing all elements of the given list.

    - #### getFirstNonNullItem

          public static <E> E getFirstNonNullItem(java.util.List<E> list)

      Gets a first non-null element of a given list.
      Type Parameters:
        `E` - the type of the list's element.
      Parameters:
        `list` - the given list.
      Returns:
        the found element or null if nothing found (all elements are null, or the list is empty).

    - #### loadList

          public static java.util.List<java.lang.String> loadList(java.lang.Class<?> classRef,
                                                  java.lang.String resourceLocation)

      Creates a new list of strings and fills it with the data read from a given resource.
      Parameters:
        `classRef` - reference to a class associated with the given resource.
        `resourceLocation` - the name of resource.
      Returns:
        the new list loaded from the resource.

    - #### loadList

          public static void loadList(java.util.List<java.lang.String> list,
                      java.lang.Class<?> classRef,
                      java.lang.String resourceLocation)

      Fills in an existing list of strings with the data read from a given resource.
      Parameters:
        `list` - the given list of strings.
        `classRef` - reference to a class associated with the given resource.
        `resourceLocation` - the name of resource.