Package jetbrains.buildServer.util
Class Util
- java.lang.Object
-
- jetbrains.buildServer.util.Util
-
public class Util extends java.lang.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 java.lang.Throwable>
TdoUnderContextClassLoader(java.lang.ClassLoader cl, FuncThrow<T,E> action)
Performs an action under context class loader.static <T> java.util.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 java.lang.Comparable>
Tmax(T o1, T o2)
Compares two comparables and return the greater one.static <T> T
ofNullable(java.util.function.Supplier<T> value, T defaultValue)
Nullable of supplier with defaultstatic <T> T
ofNullable(T value, java.util.function.Supplier<T> defaultValue)
Nullable with defaultstatic <T> T
ofNullable(T value, T defaultValue)
Nullable with defaultstatic int
unbox(java.lang.Integer nullable, int nullValue)
Unbox nullablestatic <T extends java.lang.Throwable>
TunwrapCause(java.lang.Throwable t, java.lang.Class<T> causeClass)
static java.lang.Throwable
unwrapCause(java.lang.Throwable t, java.lang.String causeClassName)
-
-
-
Method Detail
-
max
@Nullable public static <T extends java.lang.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 java.lang.Throwable> T doUnderContextClassLoader(@NotNull java.lang.ClassLoader cl, FuncThrow<T,E> action) throws E extends java.lang.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 java.lang.Throwable
-
map
public static <T> java.util.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 java.lang.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 java.util.function.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 java.util.function.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 java.lang.Throwable> T unwrapCause(@Nullable java.lang.Throwable t, @NotNull java.lang.Class<T> causeClass)
-
unwrapCause
@Nullable public static java.lang.Throwable unwrapCause(@Nullable java.lang.Throwable t, @NotNull java.lang.String causeClassName)
-
-