Package jetbrains.buildServer.util
Class Util
- java.lang.Object
-
- jetbrains.buildServer.util.Util
-
public class Util extends Object
General purpose utility functions- Author:
- Sergey.Anchipolevsky Date: 18.10.2007
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
compare(long f, long s)
Compares two long valuesstatic <T,E extends Throwable>
TdoUnderContextClassLoader(ClassLoader cl, FuncThrow<T,E> action)
Performs an action under context class loader.static <T> Map<T,T>
map(T... args)
Converts input arguments into a map: elements with even indexes are keys, elements with odd indexes are values.static <T extends Comparable>
Tmax(T o1, T o2)
Compares two comparables and return the greater one.static <T> T
ofNullable(Supplier<T> value, T defaultValue)
Nullable of supplier with defaultstatic <T> T
ofNullable(T value, Supplier<T> defaultValue)
Nullable with defaultstatic <T> T
ofNullable(T value, T defaultValue)
Nullable with defaultstatic int
unbox(Integer nullable, int nullValue)
Unbox nullablestatic <T extends Throwable>
TunwrapCause(Throwable t, Class<T> causeClass)
static Throwable
unwrapCause(Throwable t, String causeClassName)
-
-
-
Method Detail
-
max
@Nullable public static <T extends Comparable> T max(@Nullable T o1, @Nullable T o2)
Compares two comparables and return the greater one. If both are equal any of them can be returned. If one is null the other is returned. If both are nulls null is returned.- Parameters:
o1
- the first comparableo2
- the second comparable- Returns:
- the greater one
-
compare
public static int compare(long f, long s)
Compares two long values- Parameters:
f
- the first values
- the second value- Returns:
- -1 when f < s; 0 when f == s; 1 when f > s
-
doUnderContextClassLoader
public static <T,E extends Throwable> T doUnderContextClassLoader(@NotNull ClassLoader cl, FuncThrow<T,E> action) throws E extends Throwable
Performs an action under context class loader.- Type Parameters:
E
- exception that action could throw- Parameters:
cl
- classloader to setaction
- action to run- Returns:
- the value returned from action
- Throws:
E
- exception if action throws an exception.E extends Throwable
-
map
public static <T> Map<T,T> map(T... args)
Converts input arguments into a map: elements with even indexes are keys, elements with odd indexes are values. If the number of arguments is odd the last argument is considered as a key with a null value.- Type Parameters:
T
- any type- Parameters:
args
- arguments in the following format - key1, value1, key2, value2...- Returns:
- the map
-
unbox
public static int unbox(@Nullable Integer nullable, int nullValue)
Unbox nullable- Parameters:
nullable
- Nullable to unboxnullValue
- Value in case nullable is null- Returns:
- unboxed value if nullable is not null,
nullValue
otherwise
-
ofNullable
public static <T> T ofNullable(@Nullable T value, @NotNull T defaultValue)
Nullable with default- Parameters:
value
- actual valuedefaultValue
- value for null- Returns:
- value if not null or default
-
ofNullable
public static <T> T ofNullable(@NotNull Supplier<T> value, @NotNull T defaultValue)
Nullable of supplier with default- Parameters:
value
- value supplierdefaultValue
- value for null- Returns:
- value if supplier returns not null or default
-
ofNullable
public static <T> T ofNullable(@Nullable T value, @NotNull Supplier<T> defaultValue)
Nullable with default- Parameters:
value
- actual valuedefaultValue
- supplier of value for null- Returns:
- value if not null or default
-
unwrapCause
@Nullable public static <T extends Throwable> T unwrapCause(@Nullable Throwable t, @NotNull Class<T> causeClass)
-
-