public class MiscUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
asNull(Supplier<T> supplier)
If the supplier produces a null pointer or index-out-of-bounds exception, returns null.
|
static <T> T |
castTo(Object value,
Class<T> type)
Casts a value to the specified type, returning null if the cast is not possible.
|
static boolean |
fileExists(String fileName)
Returns true if the specified file exists.
|
static Class<?> |
firstAssignable(Class<?> type,
Class<?>... candidates)
Returns the first class from a list of candidate classes that is assignable from the specified
type.
|
static Class<?> |
firstAssignable(Class<?> type,
Collection<Class<?>> candidates)
Returns the first class in a collection of candidate classes that is assignable from the specified
type.
|
static String |
formatExceptionForDisplay(Throwable exc)
Formats an exception for display.
|
static Class<?>[] |
getParameterTypes(Object... parameters)
Returns an array of parameter types given an array of parameters.
|
static Pattern |
globToRegex(String glob)
Converts a glob search pattern to a regular expression.
|
static <T> T |
throwUnchecked(Throwable e)
Throws an exception, converting it to unchecked as necessary.
|
static RuntimeException |
toUnchecked(Throwable e)
Converts a checked exception to unchecked.
|
static <T> T |
withDefault(T deflt,
Supplier<T> supplier)
If the supplier produces a null pointer or index-out-of-bounds exception, returns the default value.
|
public static boolean fileExists(String fileName)
fileName - File name.public static RuntimeException toUnchecked(Throwable e)
e - The original exception.public static <T> T throwUnchecked(Throwable e)
T - Arbitrary return type.e - The original exception. If null, no exception is thrown.public static String formatExceptionForDisplay(Throwable exc)
exc - Exception to format.public static <T> T asNull(Supplier<T> supplier)
T - The type of the value.supplier - The supplier of the value.public static <T> T withDefault(T deflt,
Supplier<T> supplier)
T - The type of the value.deflt - The default value to use.supplier - The supplier of the value.public static Class<?>[] getParameterTypes(Object... parameters)
parameters - Array of parameters.public static <T> T castTo(Object value, Class<T> type)
T - The type to cast to.value - The value to cast.type - The type to cast to.public static Class<?> firstAssignable(Class<?> type, Class<?>... candidates)
type - The type.candidates - A list of candidate types.public static Class<?> firstAssignable(Class<?> type, Collection<Class<?>> candidates)
type - The type.candidates - A collection of candidate types.Copyright © 2023 Fujion Framework. All rights reserved.