org.apache.ignite.internal.util.typedef

## 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 `Predef` in Scala. Note that this should only be used when this typedef does not sacrifice the code readability.

### Field Summary

Fields
`static Object[]` `EMPTY_OBJECT_ARRAY` An empty immutable `Object` array.

### Method Summary

All Methods Static Methods Concrete Methods
`static <T extends Throwable> T` `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 List<Throwable>` `getSuppressedList(Throwable t)` Collects suppressed exceptions from throwable and all it causes.
`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<?>... 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` `timeSpan2DHMSM(long span)` Creates string presentation of given time `span` in days, hh:mm:ss.mmm `HMS` format.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### EMPTY_OBJECT_ARRAY

    public static final Object[] EMPTY_OBJECT_ARRAY

An empty immutable `Object` array.

### Method Detail

#### println

    public static void println()

Alias for `System.out.println()`.

#### printerrln

    public static void printerrln()

Alias for `System.err.println()`.

#### println

    public static void println(@Nullable
                               String s1,
                               @Nullable
                               Object... rest)

Alias for `System.out.println`.

Parameters:
  `s1` - First string to print.
  `rest` - Optional list of objects to print as well.

#### printerrln

    public static void printerrln(@Nullable
                                  String s1,
                                  @Nullable
                                  Object... rest)

Alias for `System.err.println`.

Parameters:
  `s1` - First string to print.
  `rest` - Optional list of objects to print as well.

#### error

    public static void error(@Nullable
                             String s1,
                             @Nullable
                             Object... rest)

Alias for `System.err.println`.

Parameters:
  `s1` - First string to print.
  `rest` - Optional list of objects to print as well.

#### print

    public static void print(@Nullable
                             String s1,
                             @Nullable
                             Object... rest)

Alias for `System.out.print`.

Parameters:
  `s1` - First string to print.
  `rest` - Optional list of objects to print as well.

#### printerr

    public static void printerr(@Nullable
                                String s1,
                                @Nullable
                                Object... rest)

Alias for `System.err.print`.

Parameters:
  `s1` - First string to print.
  `rest` - Optional list of objects to print as well.

#### getSystemOrEnv

    @Nullable
    public static 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 `null` if neither can be found for given name.

#### timeSpan2HMSM

    public static String timeSpan2HMSM(long span)

Creates string presentation of given time `span` in hh:mm:ss.msec `HMSM` format.

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 time `span` in hh:mm:ss `HMS` format.

Parameters:
  `span` - Time span.
Returns:
  String presentation.

#### timeSpan2DHMSM

    public static String timeSpan2DHMSM(long span)

Creates string presentation of given time `span` in days, hh:mm:ss.mmm `HMS` format.

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 parameter `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.

Type Parameters:
  `T` - Type of cloning object.
Parameters:
  `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`.
Returns:
  Copy of a passed in object.

#### hasCause

    @SafeVarargs
    public static boolean hasCause(@Nullable
                                                Throwable t,
                                                @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 (if `null`, `false` is returned).
  `cls` - Cause classes to check (if `null` or empty, `false` is returned).
Returns:
  `True` if one of the causing exception is an instance of passed in classes, `false` otherwise.

#### hasSuppressed

    public static boolean hasSuppressed(@Nullable
                                        Throwable t,
                                        @Nullable
                                        Class<? extends Throwable> cls)

Checks if passed throwable has given class in one of the suppressed exceptions.

Parameters:
  `t` - Throwable to check (if `null`, `false` is returned).
  `cls` - Class to check.
Returns:
  `True` if one of the suppressed exceptions is an instance of passed class, `false` otherwise.

#### cause

    @Nullable
    public static <T extends Throwable> T cause(@Nullable
                                                          Throwable t,
                                                          @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 (if `null`, `null` is returned).
  `cls` - Cause class to get cause (if `null`, `null` is returned).
Returns:
  First causing exception of passed in class, `null` otherwise.

#### isThrowableNested

    public static boolean isThrowableNested()

Checks if the Throwable class has a `getCause` method. This is true for JDK 1.4 and above.

Returns:
  True if Throwable is nestable.

#### isNestedThrowable

    public static boolean isNestedThrowable(Throwable throwable)

Checks whether this `Throwable` class can store a cause. This method does not check whether it actually does store a cause.

Parameters:
  `throwable` - The `Throwable` to examine, may be null.
Returns:
  Boolean `true` if nested otherwise `false`.

#### getCause

    public static Throwable getCause(Throwable throwable)

Introspects the `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`.

If none of the above is found, returns `null`.

Parameters:
  `throwable` - The throwable to introspect for a cause, may be null.
Returns:
  The cause of the `Throwable`, `null` if none found or null throwable input.

#### getCause

    public static Throwable getCause(Throwable throwable,
                                     String[] mtdNames)

Introspects the `Throwable` to obtain the cause.

1. Try known exception types.
2. Try the supplied array of method names.
3. Try the field 'detail'.

A `null` set of method names means use the default set. A `null` in 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`, `null` if none found or null throwable input.

#### getThrowableList

    public static List<Throwable> getThrowableList(Throwable throwable)

Returns the list of `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.

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 of `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.

Parameters:
  `throwable` - The throwable to inspect, may be null.
Returns:
  The array of throwables, never null.

#### getSuppressedList

    public static List<Throwable> getSuppressedList(@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` - The `Throwable` to be examined.
Returns:
  The nested stack trace, with the root cause first.

#### waitAll

    public static void waitAll(@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 `-1` if 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
                                     String s,
                                     double dflt)

Parses double from possibly `null` or 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.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.0
Release Date | : November 30 2018