public class BambooObjectUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends Throwable> |
asRuntimeException(T t) |
static <T extends Comparable<T>> |
compare(T lhs,
T rhs)
Deprecated.
since 5.10, use
ObjectUtils.compare(Comparable, Comparable) |
static <T> T |
defaultObject(T object,
T defaultVal)
Deprecated.
since 5.10, use
ObjectUtils.defaultIfNull(Object, Object) |
static <T> T |
getCached(AtomicReference<T> valueHolder,
Supplier<T> valueSupplier)
Obtain a value from the given supplier, caching it in the passed holder variable.
|
static String |
getId(Object o) |
static String |
getMessageOrStackTrace(Throwable throwable)
returns a message from throwable, or, if there's no message create one using exception class name and stack trace
|
static <T extends Throwable,C extends T> |
rethrow(T t,
Class<C> toRethrowC)
Deprecated.
since 5.10 use the
rethrowAnyCauseThatIsInstanceOf(Throwable, Class) method. |
static <T extends Throwable,C extends T,D extends T> |
rethrow(T t,
Class<C> toRethrowC,
Class<D> toRethrowD)
Deprecated.
since 5.10 without replacement; wasn't used and one 2 args rethrow was replaced
|
static <T extends Throwable,C extends T> |
rethrowAnyCauseThatIsInstanceOf(T t,
Class<C> toRethrowC)
Given a Throwable t, and a Throwable toRethrowC, if t is an instance of toRethrowC, it will be returned.
|
static <T extends Throwable> |
rethrowUnexpectedException(T t)
Deprecated.
since 5.0 use
asRuntimeException(Throwable) |
static String |
toString(Object key) |
@Deprecated public static <T extends Comparable<T>> int compare(@Nullable T lhs, @Nullable T rhs)
ObjectUtils.compare(Comparable, Comparable)
@Deprecated @NotNull public static <T> T defaultObject(@Nullable T object, @NotNull T defaultVal)
ObjectUtils.defaultIfNull(Object, Object)
public static <T extends Throwable,C extends T> RuntimeException rethrowAnyCauseThatIsInstanceOf(@NotNull T t, Class<C> toRethrowC) throws C extends T
C extends T
@Deprecated public static <T extends Throwable,C extends T> RuntimeException rethrow(T t, Class<C> toRethrowC) throws C extends T
rethrowAnyCauseThatIsInstanceOf(Throwable, Class)
method.C extends T
@NotNull public static String getMessageOrStackTrace(@NotNull Throwable throwable)
@Deprecated public static <T extends Throwable,C extends T,D extends T> RuntimeException rethrow(T t, Class<C> toRethrowC, Class<D> toRethrowD) throws C extends T, D extends T
C extends T
@Deprecated public static <T extends Throwable> RuntimeException rethrowUnexpectedException(T t)
asRuntimeException(Throwable)
public static <T extends Throwable> RuntimeException asRuntimeException(T t)
public static <T> T getCached(@NotNull AtomicReference<T> valueHolder, @NotNull Supplier<T> valueSupplier)
Obtain a value from the given supplier, caching it in the passed holder variable. The supplier will be only executed once, and the calculated result will be cached in the holder variable for future calls to avoid unnecessary calculations.
This method uses synchronization by intrinsic locking on the value holder param.
Example usage:
class MyClass {
private final AtomicReference<User> currentUser = new AtomicReference<>();
...
public User getCurrentUser() {
return getCached(currentUser, () -> userManager.getUser(authenticationContext.getCurrentUserName()));
}
}
T
- type of returned valuevalueHolder
- a variable to cache the result of calling the suppliervalueSupplier
- supplier of the value to be called once onlyNullPointerException
- if the supplier returns a null valueCopyright © 2017 Atlassian Software Systems Pty Ltd. All rights reserved.