public final class X extends Object
Contains often used utility functions allowing to cut down on code bloat. This
is somewhat analogous to Predef
in Scala. Note that this should only be used
when this typedef does not sacrifice the code readability.
Modifier and Type | Field and Description |
---|---|
static Object[] |
EMPTY_OBJECT_ARRAY
An empty immutable
Object array. |
Modifier and Type | Method and Description |
---|---|
static <T extends Throwable> |
cause(Throwable t,
Class<T> cls)
Gets first cause if passed in
'Throwable' has given class in 'cause' hierarchy. |
static void |
checkMinMemory(long min)
Exits with code
-1 if maximum memory is below 90% of minimally allowed threshold. |
static <T> T |
cloneObject(T obj,
boolean deep,
boolean honorCloneable)
Clones a passed in object.
|
static int |
copy(InputStream in,
OutputStream out,
int bufSize)
Copies input byte stream to output byte stream.
|
static void |
error(String s1,
Object... rest)
Alias for
System.err.println . |
static String |
formatMins(long mins)
Pretty-formatting for minutes.
|
static Throwable |
getCause(Throwable throwable)
Introspects the
Throwable to obtain the cause. |
static Throwable |
getCause(Throwable throwable,
String[] mtdNames)
Introspects the
Throwable to obtain the cause. |
static String |
getFullStackTrace(Throwable throwable)
A way to get the entire nested stack-trace of an throwable.
|
static String |
getSystemOrEnv(String name)
Gets either system property or environment variable with given name.
|
static List<Throwable> |
getThrowableList(Throwable throwable)
Returns the list of
Throwable objects in the exception chain. |
static Throwable[] |
getThrowables(Throwable throwable)
Returns the list of
Throwable objects in the exception chain. |
static boolean |
hasCause(Throwable t,
Class<? extends Throwable>... cls)
Checks if passed in
'Throwable' has given class in 'cause' hierarchy
including that throwable itself. |
static boolean |
hasSuppressed(Throwable t,
Class<? extends Throwable> cls)
Checks if passed throwable has given class in one of the suppressed exceptions.
|
static boolean |
isNestedThrowable(Throwable throwable)
Checks whether this
Throwable class can store a cause. |
static boolean |
isThrowableNested()
Checks if the Throwable class has a
getCause method. |
static double |
parseDouble(String s,
double dflt)
Parses double from possibly
null or invalid string. |
static void |
print(String s1,
Object... rest)
Alias for
System.out.print . |
static void |
printerr(String s1,
Object... rest)
Alias for
System.err.print . |
static void |
printerrln()
Alias for
System.err.println() . |
static void |
printerrln(String s1,
Object... rest)
Alias for
System.err.println . |
static void |
println()
Alias for
System.out.println() . |
static void |
println(String s1,
Object... rest)
Alias for
System.out.println . |
static String |
resolveIgniteHome()
Tries to resolve Ignite installation home folder.
|
static String |
timeSpan2HMS(long span)
Creates string presentation of given time
span in hh:mm:ss HMS format. |
static String |
timeSpan2HMSM(long span)
Creates string presentation of given time
span in hh:mm:ss:msec HMSM format. |
static void |
waitAll(Iterable<IgniteFuture<?>> futs)
Synchronously waits for all futures in the collection.
|
public static final Object[] EMPTY_OBJECT_ARRAY
Object
array.public static void println()
System.out.println()
.public static void printerrln()
System.err.println()
.public static void println(@Nullable String s1, @Nullable Object... rest)
System.out.println
.s1
- First string to print.rest
- Optional list of objects to print as well.public static void printerrln(@Nullable String s1, @Nullable Object... rest)
System.err.println
.s1
- First string to print.rest
- Optional list of objects to print as well.public static void error(@Nullable String s1, @Nullable Object... rest)
System.err.println
.s1
- First string to print.rest
- Optional list of objects to print as well.public static void print(@Nullable String s1, @Nullable Object... rest)
System.out.print
.s1
- First string to print.rest
- Optional list of objects to print as well.public static void printerr(@Nullable String s1, @Nullable Object... rest)
System.err.print
.s1
- First string to print.rest
- Optional list of objects to print as well.@Nullable public static String getSystemOrEnv(String name)
name
- Name of the system property or environment variable.null
if neither can be found for given name.public static String timeSpan2HMSM(long span)
span
in hh:mm:ss:msec HMSM
format.span
- Time span.public static String timeSpan2HMS(long span)
span
in hh:mm:ss HMS
format.span
- Time span.@Nullable public static <T> T cloneObject(@Nullable T obj, boolean deep, boolean honorCloneable)
deep
is set to true
then this method will use deep cloning algorithm based on deep reflection
ignoring Cloneable
interface unless parameter honorCloneable
is set to false.
If deep
is false
then this method will check the object for
Cloneable
interface and use Object.clone()
to make a copy,
otherwise the object itself will be returned.
T
- Type of cloning object.obj
- Object to create a clone from.deep
- true
to use algorithm of deep cloning. If false
then this method will always be checking whether a passed in object
implements interface Cloneable
and if it does then method
Object.clone()
will be used to clone object, if does not
then the object itself will be returned.honorCloneable
- Flag indicating whether Cloneable
interface
should be honored or not when cloning. This parameter makes sense only if
parameter deep
is set to true
.@SafeVarargs public static boolean hasCause(@Nullable Throwable t, @Nullable Class<? extends Throwable>... cls)
'Throwable'
has given class in 'cause'
hierarchy
including that throwable itself.
Note that this method follows includes Throwable.getSuppressed()
into check.
t
- Throwable to check (if null
, false
is returned).cls
- Cause classes to check (if null
or empty, false
is returned).True
if one of the causing exception is an instance of passed in classes,
false
otherwise.public static boolean hasSuppressed(@Nullable Throwable t, @Nullable Class<? extends Throwable> cls)
t
- Throwable to check (if null
, false
is returned).cls
- Class to check.True
if one of the suppressed exceptions is an instance of passed class,
false
otherwise.@Nullable public static <T extends Throwable> T cause(@Nullable Throwable t, @Nullable Class<T> cls)
'Throwable'
has given class in 'cause'
hierarchy.
Note that this method follows includes Throwable.getSuppressed()
into check.
t
- Throwable to check (if null
, null
is returned).cls
- Cause class to get cause (if null
, null
is returned).null
otherwise.public static boolean isThrowableNested()
getCause
method.
This is true for JDK 1.4 and above.public static boolean isNestedThrowable(Throwable throwable)
Throwable
class can store a cause.
This method does not check whether it actually does store a cause.throwable
- The Throwable
to examine, may be null.true
if nested otherwise false
.public static Throwable getCause(Throwable throwable)
Throwable
to obtain the cause.
The method searches for methods with specific names that return a Throwable
object.
This will pick up most wrapping exceptions, including those from JDK 1.4.
The default list searched for are: getCause()
getNextException()
getTargetException()
getException()
getSourceException()
getRootCause()
getCausedByException()
getNested()
In the absence of any such method, the object is inspected for a detail
field assignable to a Throwable
.
null
.throwable
- The throwable to introspect for a cause, may be null.Throwable
,
null
if none found or null throwable input.public static Throwable getCause(Throwable throwable, String[] mtdNames)
Throwable
to obtain the cause.
A null
set of method names means use the default set.
A null
in the set of method names will be ignored.
throwable
- The throwable to introspect for a cause, may be null.mtdNames
- The method names, null treated as default set.Throwable
, null
if none found or null throwable input.public static List<Throwable> getThrowableList(Throwable throwable)
Throwable
objects in the exception chain.
A throwable without cause will return a list containing one element - the input throwable.
A throwable with one cause will return a list containing two elements - the input throwable
and the cause throwable. A null
throwable will return a list of size zero.
This method handles recursive cause structures that might otherwise cause infinite loops.
The cause chain is processed until the end is reached, or until the next item in the chain
is already in the result set.throwable
- The throwable to inspect, may be null.public static Throwable[] getThrowables(Throwable throwable)
Throwable
objects in the exception chain.
A throwable without cause will return an array containing one element - the input throwable.
A throwable with one cause will return an array containing two elements - the input throwable
and the cause throwable. A null
throwable will return an array of size zero.throwable
- The throwable to inspect, may be null.public static String getFullStackTrace(Throwable throwable)
throwable
- The Throwable
to be examined.public static void waitAll(@Nullable Iterable<IgniteFuture<?>> futs)
futs
- Futures to wait for.public static String formatMins(long mins)
mins
- Minutes to format.public static void checkMinMemory(long min)
-1
if maximum memory is below 90% of minimally allowed threshold.min
- Minimum memory threshold.public static int copy(InputStream in, OutputStream out, int bufSize) throws IOException
in
- Input byte stream.out
- Output byte stream.bufSize
- Intermediate buffer size.IOException
- Thrown if an I/O error occurs.public static String resolveIgniteHome() throws IgniteCheckedException
IgniteCheckedException
- If Ignite home folder was not set.public static double parseDouble(@Nullable String s, double dflt)
null
or invalid string.s
- String to parse double from. If string is null or invalid, a default value is used.dflt
- Default value for double, if parsing failed.
Follow @ApacheIgnite
Ignite Fabric : ver. 2.0.0 Release Date : April 30 2017