Package com.atlassian.bamboo.util
Class BambooObjectUtils
- java.lang.Object
-
- com.atlassian.bamboo.util.BambooObjectUtils
-
public class BambooObjectUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T extends Throwable>
RuntimeExceptionasRuntimeException(T t)
static <T extends Comparable<T>>
intcompare(T lhs, T rhs)
Deprecated.since 5.10, useObjectUtils.compare(Comparable, Comparable)
static <T> T
defaultObject(T object, T defaultVal)
Deprecated.since 5.10, useObjectUtils.defaultIfNull(Object, Object)
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.static String
getId(@Nullable Object o)
static @NotNull String
getMessageOrStackTrace(@NotNull Throwable throwable)
returns a message from throwable, or, if there's no message create one using exception class name and stack tracestatic <T extends Throwable,C extends T>
RuntimeExceptionrethrow(T t, Class<C> toRethrowC)
Deprecated.since 5.10 use therethrowAnyCauseThatIsInstanceOf(Throwable, Class)
method.static <T extends Throwable,C extends T,D extends T>
RuntimeExceptionrethrow(T t, Class<C> toRethrowC, Class<D> toRethrowD)
Deprecated.since 5.10 without replacement; wasn't used and one 2 args rethrow was replacedstatic <T extends Throwable,C extends T>
RuntimeExceptionrethrowAnyCauseThatIsInstanceOf(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>
RuntimeExceptionrethrowUnexpectedException(T t)
Deprecated.since 5.0 useasRuntimeException(Throwable)
static String
toString(Object key)
-
-
-
Method Detail
-
compare
@Deprecated public static <T extends Comparable<T>> int compare(@Nullable T lhs, @Nullable T rhs)
Deprecated.since 5.10, useObjectUtils.compare(Comparable, Comparable)
Compares two objects in a null-safe way. A null object is considered to be lesser than a non-null one
-
defaultObject
@Deprecated @NotNull public static <T> T defaultObject(@Nullable T object, @NotNull T defaultVal)
Deprecated.since 5.10, useObjectUtils.defaultIfNull(Object, Object)
-
rethrowAnyCauseThatIsInstanceOf
public static <T extends Throwable,C extends T> RuntimeException rethrowAnyCauseThatIsInstanceOf(@NotNull T t, Class<C> toRethrowC) throws C extends T
Given a Throwable t, and a Throwable toRethrowC, if t is an instance of toRethrowC, it will be returned. Otherwise it will recursively look into chain of causes of Throwable t. If one of them is an instance of RethrowC, it will be returned. Otherwise, it will throw RuntimeException or, if it's already a RuntimeException, throw it directly. This method should be used when a method has a broad throws clause (e.g. Callable) and we know which checked exceptions it will return throwable of class toRethrowC or throw runtime exception.- Throws:
C extends T
-
rethrow
@Deprecated public static <T extends Throwable,C extends T> RuntimeException rethrow(T t, Class<C> toRethrowC) throws C extends T
Deprecated.since 5.10 use therethrowAnyCauseThatIsInstanceOf(Throwable, Class)
method.Given a Throwable t, and a Throwable toRethrowC, if it is an instance of toRethrowC, it will be rethrown. Otherwise, it will be returned as a RuntimeException or, if it's already a RuntimeException, returned directly. This method should be used when a method has a broad throws clause (e.g. Callable) and we know which checked exceptions it may actually throw.- Throws:
C extends T
-
getMessageOrStackTrace
@NotNull public static @NotNull String getMessageOrStackTrace(@NotNull @NotNull Throwable throwable)
returns a message from throwable, or, if there's no message create one using exception class name and stack trace- Returns:
-
rethrow
@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
Deprecated.since 5.10 without replacement; wasn't used and one 2 args rethrow was replacedGiven a Throwable t, and a Trowables toRethrowC, toRethrowD, if t is an instance of toRethrowC or toRethrowD, it will be rethrown. Otherwise, it will be returned as a RuntimeException or, if it's already a RuntimeException, returned directly. This method should be used when a method has a broad throws clause (e.g. Callable) and we know which checked exceptions it may actually throw.- Throws:
C extends T
-
rethrowUnexpectedException
@Deprecated public static <T extends Throwable> RuntimeException rethrowUnexpectedException(T t)
Deprecated.since 5.0 useasRuntimeException(Throwable)
-
asRuntimeException
public static <T extends Throwable> RuntimeException asRuntimeException(T t)
-
getCached
public static <T> T getCached(@NotNull @NotNull AtomicReference<T> valueHolder, @NotNull @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())); } }
- Type Parameters:
T
- type of returned value- Parameters:
valueHolder
- a variable to cache the result of calling the suppliervalueSupplier
- supplier of the value to be called once only- Returns:
- value returned by supplier or obtained from cache if it was already defined; if the value is stored in the cache, supplier will not be called.
- Throws:
NullPointerException
- if the supplier returns a null value
-
-