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 | 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 String |
getSystemOrEnv(String name)
Gets either system property or environment variable with given name.
|
static String |
getSystemOrEnv(String name,
String dflt)
Gets either system property or environment variable with given name.
|
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 |
hasCauseExcludeRoot(Throwable t,
Class<? extends Throwable>... cls)
Checks if passed in
'Throwable' has given class in 'cause' hierarchy
excluding that throwable itself. |
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 |
resolveGridGainHome()
Tries to resolve GridGain 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<GridFuture<?>> futs)
Synchronously waits for all futures in the collection.
|
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.@Nullable public static String getSystemOrEnv(String name, String dflt)
name - Name of the system property or environment variable.dflt - Default value.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.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 hasCauseExcludeRoot(@Nullable Throwable t, @Nullable Class<? extends Throwable>... cls)
'Throwable' has given class in 'cause' hierarchy
excluding 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.@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 void waitAll(@Nullable Iterable<GridFuture<?>> futs) throws GridException
futs - Futures to wait for.GridException - If any of the futures threw exception.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 resolveGridGainHome() throws GridException
GridException - If GridGain 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.Copyright © 2014. All rights reserved.