Support multiple api's within a q instance. For science!

This commit is contained in:
2023-04-04 13:40:32 -05:00
parent e35761e0a6
commit e779c392bb
21 changed files with 1171 additions and 341 deletions

View File

@ -22,6 +22,9 @@
package com.kingsrook.qqq.backend.core.utils;
import com.kingsrook.qqq.backend.core.utils.lambdas.UnsafeSupplier;
/*******************************************************************************
**
*******************************************************************************/
@ -48,4 +51,49 @@ public class ObjectUtils
throw (new NullPointerException("all null objects"));
}
/*******************************************************************************
** Like Objects.requireNonNullElse, only use an (unsafe) supplier as the first
** arg, and only if it throws, return the 2nd arg
*******************************************************************************/
public static <T> T tryElse(UnsafeSupplier<T, ?> supplier, T defaultIfThrew)
{
try
{
return (supplier.get());
}
catch(Exception e)
{
return (defaultIfThrew);
}
}
/*******************************************************************************
** Like Objects.requireNonNullElse, only use an (unsafe) supplier as the first
** arg, and if it throws or returns null, then return the 2nd arg
*******************************************************************************/
public static <T> T tryAndRequireNonNullElse(UnsafeSupplier<T, ?> supplier, T defaultIfThrew)
{
try
{
T t = supplier.get();
if(t != null)
{
return (t);
}
}
catch(Exception e)
{
//////////
// noop //
//////////
}
return (defaultIfThrew);
}
}