Class ListUtil

java.lang.Object
org.ampere.base.util.ListUtil
All Implemented Interfaces:
PACTEdef

public class ListUtil extends Object implements PACTEdef
Utilities for lists
Author:
hmorel
  • Constructor Details

    • ListUtil

      public ListUtil()
  • Method Details

    • merge

      public static <T> List<T> merge(List<T> list, T value)
      merge a value into an List
      Type Parameters:
      T - type of the list
      Parameters:
      list - input list
      value - input value
      Returns:
      the merged list
    • merge

      public static <T> void merge(List<T> list1, List<T> list2)
      merge list2 into list1
      Type Parameters:
      T - type of the lists
      Parameters:
      list1 - main list
      list2 - second list, its data are merge into the main list
    • build

      public static <T> List<T> build(T... list)
      merge a value into an ArrayList
      Type Parameters:
      T - type of the list
      Parameters:
      list - input list
      Returns:
      the built list
    • buildIntersection

      public static <T> List<T> buildIntersection(List<T> list1, List<T> list2)
      build the intersection of two lists
      Type Parameters:
      T - type of the lists
      Parameters:
      list1 - first list
      list2 - second list
      Returns:
      the intersection
    • printArray

      public static <T> void printArray(PrintWriter out, T[] v, String sep)
      print a vector of PacteObject
    • listToString

      public static <T> String listToString(String header, List<T> v, String sep)
    • printArrayList

      public static <T> void printArrayList(PrintWriter out, String header, List<T> v, String sep)
    • printArrayList

      public static <T> void printArrayList(PrintWriter out, String header, List<T> v, String begin, String sep, String end)
    • printArrayList

      public static <T> void printArrayList(PrintWriter out, String header, List<T> v, String begin, String sep, String end, int nbOfChars)
      print an ArrayList
      Type Parameters:
      T - type of element to be printed
      Parameters:
      out - output stream
      header - title of the list, may be null
      v - list to be printed
      begin - string starting the list, like "["
      sep - separator like ","
      end - string ending the list, like "]"
      nbOfChars - maximal number of characters per line
    • convert2intArray

      public static int[] convert2intArray(List<Integer> list)
    • builtList

      public static <T> List<T> builtList(T val, int n)
    • builtList

      public static <D> List<D> builtList()
      only to test generic member mechanisms. In this case the type of the return value is defined by the left side type !
      Type Parameters:
      D - type of the element
      Returns:
    • toString

      public static <T> String toString(List<T> list)
      build a tring representation of the list
      Type Parameters:
      T - class of the element
      Parameters:
      list - input list
      Returns:
      a representative string
    • toString

      public static <T> String toString(T[] list)
      build a tring representation of the list
      Type Parameters:
      T - class of the element
      Parameters:
      list - input list
      Returns:
      a representative string
    • concat

      public static char[] concat(char... inputs)
    • build

      public static char[] build(List<Character> list)
    • concatenate

      public static <T> T[] concatenate(T[] begining, T... following)
    • concatenate

      public static <T> T[] concatenate(T begining, T... following)
    • contains

      public static <T> boolean contains(T[] values, T value)
      test if an array contains a given value
      Type Parameters:
      T - type of values
      Parameters:
      values - array of values
      value - given value
      Returns:
      true if the array contains the given value.
    • getIndex

      public static <T> int getIndex(T[] values, T target)
      test if an array contains a given value
      Type Parameters:
      T - type of values
      Parameters:
      values - array of values
      target - searched value
      Returns:
      the found index or UNKNOWN.
    • contains

      public static boolean contains(int[] values, int value)
      test if an array of int contains a given value
      Parameters:
      values - array of values
      value - given value
      Returns:
      true if the array contains the given value.
    • contains

      public static boolean contains(List<Integer> list, int value)
      test if an array of int contains a given value
      Parameters:
      list - array of values
      value - given value
      Returns:
      true if the array contains the given value.
    • isEmpty

      public static <T> boolean isEmpty(List<T> list)
    • size

      public static <T> int size(List<T> list)
    • isEmpty

      public static <T> boolean isEmpty(T[] list)
    • size

      public static <T> int size(T[] list)
    • asList

      public static <T> List<T> asList(T[] values)
      Build a list of values
      Type Parameters:
      T - type of values
      Parameters:
      values - array of values
      Returns:
      a void list if the input array is null, else return the Arrays.asList().