Modifier and Type | Method and Description |
---|---|
static Throwable |
getDeepestNestedCause(Throwable throwable)
Gets the deepest nested cause of the supplied throwable.
|
static <T> T |
useDefaultValueWhenValueIsNull(T value,
T defaultValue)
Convenience method to use a default value when the actual value is null.
|
public static Throwable getDeepestNestedCause(Throwable throwable)
throwable
- The throwable to search for the deepest nested cause.NullPointerException
- When the supplied throwable is null.public static <T> T useDefaultValueWhenValueIsNull(T value, T defaultValue)
if (valueOne != null) {
o.setValueOne(valueOne);
}
if (valueTwo != null) {
o.setValueTwo(valueTwo);
}
// Can be replaced with
o.setValueOne(useDefaultValueWhenValueIsNull(valueOne, o.getValueOne()));
o.setValueTwo(useDefaultValueWhenValueIsNull(valueTwo, o.getValueTwo()));
As you can see, this method decreases the complexity of the code
(McCabe), at the expense of calling an extra setter when the supplied
value is null.T
- The type of the supplied value and defaultValue.value
- The value.defaultValue
- The default value to use when the supplied value is
null.Copyright © 2008–2018. All rights reserved.