Add good getFirstNonNull method

This commit is contained in:
2023-02-22 11:22:14 -06:00
parent 1bdce12b8d
commit 4cf8e37e7e
2 changed files with 46 additions and 1 deletions

View File

@ -728,4 +728,29 @@ public class ValueUtils
.with(ChronoField.NANO_OF_DAY, 0);
return (startOfMonth.toInstant(zone.getRules().getOffset(computerTime)));
}
/*******************************************************************************
** Return the first argument that isn't null.
** If all were null, return null.
*******************************************************************************/
public static <T> T getFirstNonNull(T... ts)
{
if(ts == null || ts.length == 0)
{
return (null);
}
for(T t : ts)
{
if(t != null)
{
return (t);
}
}
return (null);
}
}