mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 21:50:45 +00:00
add nonNullArray and mergeLists
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user