Class X
- java.lang.Object
-
- org.apache.ignite.internal.util.typedef.X
-
public final class X extends Object
Defines global scope.Contains often used utility functions allowing to cut down on code bloat. This is somewhat analogous to
Predefin Scala. Note that this should only be used when this typedef does not sacrifice the code readability.
-
-
Field Summary
Fields Modifier and Type Field Description static Object[]EMPTY_OBJECT_ARRAYAn empty immutableObjectarray.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Throwable>
Tcause(@Nullable Throwable t, @Nullable Class<T> cls)Gets first cause if passed in'Throwable'has given class in'cause'hierarchy.static voidcheckMinMemory(long min)Exits with code-1if maximum memory is below 90% of minimally allowed threshold.static <T> TcloneObject(T obj, boolean deep, boolean honorCloneable)Clones a passed in object.static intcopy(InputStream in, OutputStream out, int bufSize)Copies input byte stream to output byte stream.static voiderror(@Nullable String s1, @Nullable Object... rest)Alias forSystem.err.println.static StringformatMins(long mins)Pretty-formatting for minutes.static ThrowablegetCause(Throwable throwable)Introspects theThrowableto obtain the cause.static ThrowablegetCause(Throwable throwable, String[] mtdNames)Introspects theThrowableto obtain the cause.static StringgetFullStackTrace(Throwable throwable)A way to get the entire nested stack-trace of an throwable.static List<Throwable>getSuppressedList(@Nullable Throwable t)Collects suppressed exceptions from throwable and all it causes.static @Nullable StringgetSystemOrEnv(String name)Gets either system property or environment variable with given name.static List<Throwable>getThrowableList(Throwable throwable)Returns the list ofThrowableobjects in the exception chain.static Throwable[]getThrowables(Throwable throwable)Returns the list ofThrowableobjects in the exception chain.static booleanhasCause(@Nullable Throwable t, @Nullable Class<?>... cls)Checks if passed in'Throwable'has given class in'cause'hierarchy including that throwable itself.static booleanhasCause(@Nullable Throwable t, @Nullable String msg, @Nullable Class<?>... types)Checks if passed in'Throwable'has given class in'cause'hierarchy including that throwable itself.static booleanhasSuppressed(@Nullable Throwable t, @Nullable Class<? extends Throwable> cls)Checks if passed throwable has given class in one of the suppressed exceptions.static booleanisNestedThrowable(Throwable throwable)Checks whether thisThrowableclass can store a cause.static booleanisThrowableNested()Checks if the Throwable class has agetCausemethod.static doubleparseDouble(@Nullable String s, double dflt)Parses double from possiblynullor invalid string.static voidprint(@Nullable String s1, @Nullable Object... rest)Alias forSystem.out.print.static voidprinterr(@Nullable String s1, @Nullable Object... rest)Alias forSystem.err.print.static voidprinterrln()Alias forSystem.err.println().static voidprinterrln(@Nullable String s1, @Nullable Object... rest)Alias forSystem.err.println.static voidprintln()Alias forSystem.out.println().static voidprintln(@Nullable String s1, @Nullable Object... rest)Alias forSystem.out.println.static StringresolveIgniteHome()Tries to resolve Ignite installation home folder.static StringtimeSpan2DHMSM(long span)Creates string presentation of given timespanin days, hh:mm:ss.mmmHMSformat.static StringtimeSpan2HMS(long span)Creates string presentation of given timespanin hh:mm:ssHMSformat.static StringtimeSpan2HMSM(long span)Creates string presentation of given timespanin hh:mm:ss.msecHMSMformat.static voidwaitAll(@Nullable Iterable<IgniteFuture<?>> futs)Synchronously waits for all futures in the collection.
-
-
-
Field Detail
-
EMPTY_OBJECT_ARRAY
public static final Object[] EMPTY_OBJECT_ARRAY
An empty immutableObjectarray.
-
-
Method Detail
-
println
public static void println()
Alias forSystem.out.println().
-
printerrln
public static void printerrln()
Alias forSystem.err.println().
-
println
public static void println(@Nullable @Nullable String s1, @Nullable @Nullable Object... rest)Alias forSystem.out.println.- Parameters:
s1- First string to print.rest- Optional list of objects to print as well.
-
printerrln
public static void printerrln(@Nullable @Nullable String s1, @Nullable @Nullable Object... rest)Alias forSystem.err.println.- Parameters:
s1- First string to print.rest- Optional list of objects to print as well.
-
error
public static void error(@Nullable @Nullable String s1, @Nullable @Nullable Object... rest)Alias forSystem.err.println.- Parameters:
s1- First string to print.rest- Optional list of objects to print as well.
-
print
public static void print(@Nullable @Nullable String s1, @Nullable @Nullable Object... rest)Alias forSystem.out.print.- Parameters:
s1- First string to print.rest- Optional list of objects to print as well.
-
printerr
public static void printerr(@Nullable @Nullable String s1, @Nullable @Nullable Object... rest)Alias forSystem.err.print.- Parameters:
s1- First string to print.rest- Optional list of objects to print as well.
-
getSystemOrEnv
@Nullable public static @Nullable String getSystemOrEnv(String name)
Gets either system property or environment variable with given name.- Parameters:
name- Name of the system property or environment variable.- Returns:
- Value of the system property or environment variable. Returns
nullif neither can be found for given name.
-
timeSpan2HMSM
public static String timeSpan2HMSM(long span)
Creates string presentation of given timespanin hh:mm:ss.msecHMSMformat.- Parameters:
span- Time span.- Returns:
- String presentation. If duration if longer than 1 day, days count is ignored.
-
timeSpan2HMS
public static String timeSpan2HMS(long span)
Creates string presentation of given timespanin hh:mm:ssHMSformat.- Parameters:
span- Time span.- Returns:
- String presentation.
-
timeSpan2DHMSM
public static String timeSpan2DHMSM(long span)
Creates string presentation of given timespanin days, hh:mm:ss.mmmHMSformat.- Parameters:
span- Time span.- Returns:
- String presentation.
-
cloneObject
@Nullable public static <T> T cloneObject(@Nullable T obj, boolean deep, boolean honorCloneable)Clones a passed in object. If parameterdeepis set totruethen this method will use deep cloning algorithm based on deep reflection ignoringCloneableinterface unless parameterhonorCloneableis set to false.If
deepisfalsethen this method will check the object forCloneableinterface and useObject.clone()to make a copy, otherwise the object itself will be returned.- Type Parameters:
T- Type of cloning object.- Parameters:
obj- Object to create a clone from.deep-trueto use algorithm of deep cloning. Iffalsethen this method will always be checking whether a passed in object implements interfaceCloneableand if it does then methodObject.clone()will be used to clone object, if does not then the object itself will be returned.honorCloneable- Flag indicating whetherCloneableinterface should be honored or not when cloning. This parameter makes sense only if parameterdeepis set totrue.- Returns:
- Copy of a passed in object.
-
hasCause
public static boolean hasCause(@Nullable @Nullable Throwable t, @Nullable @Nullable String msg, @Nullable @Nullable Class<?>... types)Checks if passed in'Throwable'has given class in'cause'hierarchy including that throwable itself.Note that this method follows includes
Throwable.getSuppressed()into check.- Parameters:
t- Throwable to check (ifnull,falseis returned).msg- Message text that should be in cause.types- Cause classes to check (ifnullor empty,falseis returned).- Returns:
Trueif one of the causing exception is an instance of passed in classes,falseotherwise.
-
hasCause
public static boolean hasCause(@Nullable @Nullable Throwable t, @Nullable @Nullable Class<?>... cls)Checks if passed in'Throwable'has given class in'cause'hierarchy including that throwable itself.Note that this method follows includes
Throwable.getSuppressed()into check.- Parameters:
t- Throwable to check (ifnull,falseis returned).cls- Cause classes to check (ifnullor empty,falseis returned).- Returns:
Trueif one of the causing exception is an instance of passed in classes,falseotherwise.
-
hasSuppressed
public static boolean hasSuppressed(@Nullable @Nullable Throwable t, @Nullable @Nullable Class<? extends Throwable> cls)Checks if passed throwable has given class in one of the suppressed exceptions.- Parameters:
t- Throwable to check (ifnull,falseis returned).cls- Class to check.- Returns:
Trueif one of the suppressed exceptions is an instance of passed class,falseotherwise.
-
cause
@Nullable public static <T extends Throwable> T cause(@Nullable @Nullable Throwable t, @Nullable @Nullable Class<T> cls)
Gets first cause if passed in'Throwable'has given class in'cause'hierarchy.Note that this method follows includes
Throwable.getSuppressed()into check.- Parameters:
t- Throwable to check (ifnull,nullis returned).cls- Cause class to get cause (ifnull,nullis returned).- Returns:
- First causing exception of passed in class,
nullotherwise.
-
isThrowableNested
public static boolean isThrowableNested()
Checks if the Throwable class has agetCausemethod. This is true for JDK 1.4 and above.- Returns:
- True if Throwable is nestable.
-
isNestedThrowable
public static boolean isNestedThrowable(Throwable throwable)
Checks whether thisThrowableclass can store a cause. This method does not check whether it actually does store a cause.- Parameters:
throwable- TheThrowableto examine, may be null.- Returns:
- Boolean
trueif nested otherwisefalse.
-
getCause
public static Throwable getCause(Throwable throwable)
Introspects theThrowableto obtain the cause. The method searches for methods with specific names that return aThrowableobject. 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
If none of the above is found, returnsdetailfield assignable to aThrowable.null.- Parameters:
throwable- The throwable to introspect for a cause, may be null.- Returns:
- The cause of the
Throwable,nullif none found or null throwable input.
-
getCause
public static Throwable getCause(Throwable throwable, String[] mtdNames)
Introspects theThrowableto obtain the cause.- Try known exception types.
- Try the supplied array of method names.
- Try the field 'detail'.
A
nullset of method names means use the default set. Anullin the set of method names will be ignored.- Parameters:
throwable- The throwable to introspect for a cause, may be null.mtdNames- The method names, null treated as default set.- Returns:
- The cause of the
Throwable,nullif none found or null throwable input.
-
getThrowableList
public static List<Throwable> getThrowableList(Throwable throwable)
Returns the list ofThrowableobjects 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. Anullthrowable 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.- Parameters:
throwable- The throwable to inspect, may be null.- Returns:
- The list of throwables, never null.
-
getThrowables
public static Throwable[] getThrowables(Throwable throwable)
Returns the list ofThrowableobjects 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. Anullthrowable will return an array of size zero.- Parameters:
throwable- The throwable to inspect, may be null.- Returns:
- The array of throwables, never null.
-
getSuppressedList
public static List<Throwable> getSuppressedList(@Nullable @Nullable Throwable t)
Collects suppressed exceptions from throwable and all it causes.- Parameters:
t- Throwable.- Returns:
- List of suppressed throwables.
-
getFullStackTrace
public static String getFullStackTrace(Throwable throwable)
A way to get the entire nested stack-trace of an throwable. The result of this method is highly dependent on the JDK version and whether the exceptions override printStackTrace or not.- Parameters:
throwable- TheThrowableto be examined.- Returns:
- The nested stack trace, with the root cause first.
-
waitAll
public static void waitAll(@Nullable @Nullable Iterable<IgniteFuture<?>> futs)Synchronously waits for all futures in the collection.- Parameters:
futs- Futures to wait for.
-
formatMins
public static String formatMins(long mins)
Pretty-formatting for minutes.- Parameters:
mins- Minutes to format.- Returns:
- Formatted presentation of minutes.
-
checkMinMemory
public static void checkMinMemory(long min)
Exits with code-1if maximum memory is below 90% of minimally allowed threshold.- Parameters:
min- Minimum memory threshold.
-
copy
public static int copy(InputStream in, OutputStream out, int bufSize) throws IOException
Copies input byte stream to output byte stream.- Parameters:
in- Input byte stream.out- Output byte stream.bufSize- Intermediate buffer size.- Returns:
- Number of the copied bytes.
- Throws:
IOException- Thrown if an I/O error occurs.
-
resolveIgniteHome
public static String resolveIgniteHome() throws IgniteCheckedException
Tries to resolve Ignite installation home folder.- Returns:
- Installation home folder.
- Throws:
IgniteCheckedException- If Ignite home folder was not set.
-
parseDouble
public static double parseDouble(@Nullable @Nullable String s, double dflt)Parses double from possiblynullor invalid string.- Parameters:
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.- Returns:
- Resulting double.
-
-