add nonNullArray and mergeLists

This commit is contained in:
2023-01-19 16:11:54 -06:00
parent f9408716ac
commit 1c150e207a
2 changed files with 82 additions and 0 deletions

View File

@ -415,6 +415,22 @@ public class CollectionUtils
/*******************************************************************************
** Returns the input array, unless it was null - in which case a new (empty) array is returned.
**
** Meant to help avoid null checks on foreach loops.
*******************************************************************************/
public static <T> T[] nonNullArray(T[] array)
{
if(array == null)
{
return (T[]) new ArrayList<T>().toArray();
}
return (array);
}
/*******************************************************************************
** Returns the input list, unless it was null - in which case a new array list is returned.
**
@ -513,4 +529,25 @@ public class CollectionUtils
return (mapper.convertValue(o, Map.class));
}
/*******************************************************************************
**
*******************************************************************************/
public static <T> List<T> mergeLists(List<T>... lists)
{
List<T> rs = new ArrayList<>();
if(lists != null)
{
for(List<T> list : lists)
{
if(list != null)
{
rs.addAll(list);
}
}
}
return (rs);
}
}