Package org.openrewrite.internal
Class ListUtils
java.lang.Object
org.openrewrite.internal.ListUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T @Nullable []arrayOrNullIfEmpty(@Nullable List<T> list, T[] array) static <T> List<T>static <T> List<T>static <T> List<T>static <T> List<T>static <T> List<T>static <T> List<T>Insert element to a list at the specified position in the list.static <T> List<T>static <T> List<T>insertInOrder(@Nullable List<T> ls, T insert, Comparator<T> naturalOrdering) Insert into as-near of a location representing the natural ordering of the list without assuming the list is already sorted according to its natural ordering AND without changing the position of any other element.static <T> List<T>map(@Nullable List<T> ls, BiFunction<Integer, T, T> map) static <T> List<T>map(@Nullable List<T> ls, UnaryOperator<T> map) static <T> List<T>mapFirst(@Nullable List<T> ls, UnaryOperator<T> mapFirst) static <T> List<T>mapLast(@Nullable List<T> ls, UnaryOperator<T> mapLast) nullIfEmpty(@Nullable List<T> ls) static <T> T @Nullable []nullIfEmpty(T @Nullable [] list)
-
Method Details
-
insertInOrder
public static <T> List<T> insertInOrder(@Nullable @Nullable List<T> ls, T insert, Comparator<T> naturalOrdering) Insert into as-near of a location representing the natural ordering of the list without assuming the list is already sorted according to its natural ordering AND without changing the position of any other element. This provides a means of both inserting in a natural order but also making the least invasive change.- Type Parameters:
T- The type of elements in the list.- Parameters:
ls- The original list, which may not be ordered.insert- The element to add.naturalOrdering- The natural or idiomatic ordering of the list.- Returns:
- A new list with the element inserted in an approximately ordered place.
-
insert
Insert element to a list at the specified position in the list. Throws the same exceptions as List.add()- Type Parameters:
T- The type of elements in the list.- Parameters:
ls- The original list.t- The element to add.index- index at which the specified element is to be inserted- Returns:
- A new list with the element inserted at the specified position.
-
mapLast
-
mapFirst
-
map
-
map
-
flatMap
-
flatMap
-
concat
-
concat
-
concatAll
-
insertAll
-
nullIfEmpty
-
arrayOrNullIfEmpty
-
nullIfEmpty
-