Package cern.accsoft.steering.jmad.util
Class ListUtil
- java.lang.Object
-
- cern.accsoft.steering.jmad.util.ListUtil
-
public final class ListUtil extends java.lang.Object
This class provides some utility-methods for generic lists.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ListUtil.Mapper<IN,OUT>
this interface just defines one method to convert one object into another.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.List<T>
createDefaultValueList(int size, T defaultValue)
creates a new list of the given size, containing the same element in every itemstatic <T> java.util.List<T>
createOneElementList(T element)
creates an array list with the one given element.static <T> java.util.List<T>
createOneElementOrEmptyList(T element)
creates an array list with the one given element, or an empty list if the element is null.static java.util.List<java.lang.Double>
diff(java.util.List<java.lang.Double> doublesA, java.util.List<java.lang.Double> doublesB)
returns a list with the values difference values doublesA-doublesBstatic java.util.List<java.lang.Double>
divide(java.util.List<java.lang.Double> doublesA, java.util.List<java.lang.Double> doublesB)
performs an element wise devision of the lists (doublesA / doublesB).static <IN,OUT>
java.util.List<OUT>map(java.util.List<IN> inlist, ListUtil.Mapper<IN,OUT> mapper)
converts a list of one tye into a list of another type using the provided mapperstatic java.util.List<java.lang.String>
toString(java.util.List<? extends java.lang.Object> objects)
this method converts any List to a list of strings.
-
-
-
Method Detail
-
map
public static <IN,OUT> java.util.List<OUT> map(java.util.List<IN> inlist, ListUtil.Mapper<IN,OUT> mapper)
converts a list of one tye into a list of another type using the provided mapper- Type Parameters:
IN
- the type of the input-list itemsOUT
- the type of the output-list items- Parameters:
inlist
- the list of items to convertmapper
- the mapper which converts the types- Returns:
- the new list.
-
toString
public static java.util.List<java.lang.String> toString(java.util.List<? extends java.lang.Object> objects)
this method converts any List to a list of strings.- Parameters:
objects
- the objects that shall be converted to strings- Returns:
- the list of strings
-
createOneElementList
public static <T> java.util.List<T> createOneElementList(T element)
creates an array list with the one given element.- Type Parameters:
T
- the type of objects for the list- Parameters:
element
- the single element that shall be contained in the new list- Returns:
- a list containing the given element
-
createOneElementOrEmptyList
public static <T> java.util.List<T> createOneElementOrEmptyList(T element)
creates an array list with the one given element, or an empty list if the element is null.- Type Parameters:
T
- the type of objects for the list- Parameters:
element
- the single element that shall be contained in the new list- Returns:
- a list containing the given element, or an empty list
-
createDefaultValueList
public static <T> java.util.List<T> createDefaultValueList(int size, T defaultValue)
creates a new list of the given size, containing the same element in every item- Type Parameters:
T
- the type of the list items- Parameters:
size
- the size of the new listdefaultValue
- the value that shall be contained in all items- Returns:
- the new list, containing the defaultValue in all items
-
diff
public static java.util.List<java.lang.Double> diff(java.util.List<java.lang.Double> doublesA, java.util.List<java.lang.Double> doublesB)
returns a list with the values difference values doublesA-doublesB- Parameters:
doublesA
- the values from which to subtractdoublesB
- the values which shall be subtracted- Returns:
- a list of differences
-
divide
public static java.util.List<java.lang.Double> divide(java.util.List<java.lang.Double> doublesA, java.util.List<java.lang.Double> doublesB)
performs an element wise devision of the lists (doublesA / doublesB).- Parameters:
doublesA
- the list of values that act as dividendsdoublesB
- the list of values that act as divisors- Returns:
- element wise doublesA / doublesB
-
-