com.hazelcast.util

## Class Preconditions

- java.lang.Object
- - com.hazelcast.util.Preconditions

-     public final class Preconditions
      extends Object

  A utility class for validating arguments and state.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `checkAsyncBackupCount(int currentBackupCount, int newAsyncBackupCount)` Tests if the newAsyncBackupCount count is valid.
    `static int` | `checkBackupCount(int newBackupCount, int currentAsyncBackupCount)` Tests if the newBackupCount count is valid.
    `static void` | `checkFalse(boolean expression, String errorMessage)` Tests whether the supplied expression is `false`.
    `static <T> Iterator<T>` | `checkHasNext(Iterator<T> iterator, String message)` Check if iterator has next element.
    `static String` | `checkHasText(String argument, String errorMessage)` Tests if a string contains text.
    `static <E> E` | `checkInstanceOf(Class<E> type, Object object)`
    `static <E> E` | `checkInstanceOf(Class<E> type, Object object, String errorMessage)` Tests whether the supplied object is an instance of the supplied class type.
    `static long` | `checkNegative(long value, String errorMessage)` Tests if the `value` is < 0.
    `static <T> Iterable<T>` | `checkNoNullInside(Iterable<T> argument, String errorMessage)` Tests if the elements inside the argument collection are not null.
    `static <E> E` | `checkNotInstanceOf(Class type, E object, String errorMessage)` Tests the supplied object to see if it is not a type of the supplied class.
    `static int` | `checkNotNegative(int value, String errorMessage)` Tests if the `value` is >= 0.
    `static long` | `checkNotNegative(long value, String errorMessage)` Tests if the `value` is >= 0.
    `static <T> T` | `checkNotNull(T argument)` Tests if an argument is not null.
    `static <T> T` | `checkNotNull(T argument, String errorMessage)` Tests if an argument is not null.
    `static double` | `checkPositive(double value, String errorMessage)` Tests if a `value` is positive, that is strictly larger than 0 (value > 0).
    `static int` | `checkPositive(int value, String errorMessage)` Tests if a `value` is positive, that is strictly larger than 0 (value > 0).
    `static long` | `checkPositive(long value, String errorMessage)` Tests if a `value` is positive, that is strictly larger than 0 (value > 0).
    `static void` | `checkState(boolean condition, String message)` Check the state of a condition
    `static void` | `checkTrue(boolean expression, String errorMessage)` Tests whether the supplied expression is `true`.
    `static <E> E` | `isNotNull(E argument, String argName)` Tests if a string is not null.

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

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

- - ### Method Detail

    - #### checkHasText

          public static String checkHasText(String argument,
                                            String errorMessage)

      Tests if a string contains text.
      Parameters:
        `argument` - the string tested to see if it contains text.
        `errorMessage` - the errorMessage
      Returns:
        the string argument that was tested.
      Throws:
        `IllegalArgumentException` - if the string is empty

    - #### checkNotNull

          public static <T> T checkNotNull(T argument,
                                           String errorMessage)

      Tests if an argument is not null.
      Parameters:
        `argument` - the argument tested to see if it is not null.
        `errorMessage` - the errorMessage
      Returns:
        the argument that was tested.
      Throws:
        `NullPointerException` - if argument is null

    - #### checkNoNullInside

          public static <T> Iterable<T> checkNoNullInside(Iterable<T> argument,
                                                          String errorMessage)

      Tests if the elements inside the argument collection are not null. If collection is null or empty the test is ignored.
      Parameters:
        `argument` - the iterable tested to see if it does not contain null elements; may be null or empty
        `errorMessage` - the errorMessage
      Returns:
        the argument that was tested.
      Throws:
        `NullPointerException` - if argument contains a null element inside

    - #### checkNotNull

          public static <T> T checkNotNull(T argument)

      Tests if an argument is not null.
      Parameters:
        `argument` - the argument tested to see if it is not null.
      Returns:
        the argument that was tested.
      Throws:
        `NullPointerException` - if argument is null

    - #### isNotNull

          public static <E> E isNotNull(E argument,
                                        String argName)

      Tests if a string is not null.
      Parameters:
        `argument` - the string tested to see if it is not null.
        `argName` - the string name (used in message if an error is thrown).
      Returns:
        the string argument that was tested.
      Throws:
        `IllegalArgumentException` - if the string is null.

    - #### checkNotNegative

          public static long checkNotNegative(long value,
                                              String errorMessage)

      Tests if the `value` is >= 0.
      Parameters:
        `value` - the value tested to see if it is not negative.
        `errorMessage` - the errorMessage
      Returns:
        the value
      Throws:
        `IllegalArgumentException` - if the value is negative.

    - #### checkNotNegative

          public static int checkNotNegative(int value,
                                             String errorMessage)

      Tests if the `value` is >= 0.
      Parameters:
        `value` - the value tested to see if it is not negative.
        `errorMessage` - the errorMessage
      Returns:
        the value
      Throws:
        `IllegalArgumentException` - if the value is negative.

    - #### checkNegative

          public static long checkNegative(long value,
                                           String errorMessage)

      Tests if the `value` is < 0.
      Parameters:
        `value` - the long value tested to see if it is not negative.
        `errorMessage` - the message
      Returns:
        the value
      Throws:
        `IllegalArgumentException` - if the value is negative.

    - #### checkPositive

          public static long checkPositive(long value,
                                           String errorMessage)

      Tests if a `value` is positive, that is strictly larger than 0 (value > 0).
      Parameters:
        `value` - the value tested to see if it is positive.
        `errorMessage` - the message
      Returns:
        the value
      Throws:
        `IllegalArgumentException` - if the value is not positive.

    - #### checkPositive

          public static double checkPositive(double value,
                                             String errorMessage)

      Tests if a `value` is positive, that is strictly larger than 0 (value > 0).
      Parameters:
        `value` - the value tested to see if it is positive.
        `errorMessage` - the message
      Returns:
        the value
      Throws:
        `IllegalArgumentException` - if the value is not positive.

    - #### checkPositive

          public static int checkPositive(int value,
                                          String errorMessage)

      Tests if a `value` is positive, that is strictly larger than 0 (value > 0).
      Parameters:
        `value` - the value tested to see if it is positive.
        `errorMessage` - the message
      Returns:
        the value
      Throws:
        `IllegalArgumentException` - if the value is not positive.

    - #### checkBackupCount

          public static int checkBackupCount(int newBackupCount,
                                             int currentAsyncBackupCount)

      Tests if the newBackupCount count is valid.
      Parameters:
        `newBackupCount` - the number of sync backups
        `currentAsyncBackupCount` - the current number of async backups
      Returns:
        the newBackupCount
      Throws:
        `IllegalArgumentException` - if newBackupCount is smaller than 0, or larger than the maximum number of backups.

    - #### checkAsyncBackupCount

          public static int checkAsyncBackupCount(int currentBackupCount,
                                                  int newAsyncBackupCount)

      Tests if the newAsyncBackupCount count is valid.
      Parameters:
        `currentBackupCount` - the current number of backups
        `newAsyncBackupCount` - the new number of async backups
      Returns:
        the newAsyncBackupCount
      Throws:
        `IllegalArgumentException` - if asyncBackupCount is smaller than 0, or larger than the maximum number of backups.

    - #### checkInstanceOf

          public static <E> E checkInstanceOf(Class<E> type,
                                              Object object,
                                              String errorMessage)

      Tests whether the supplied object is an instance of the supplied class type.
      Parameters:
        `type` - the expected type.
        `object` - the object tested against the expected type.
        `errorMessage` - the errorMessage
      Returns:
        the object argument.
      Throws:
        `IllegalArgumentException` - if the object is not an instance of the expected type.

    - #### checkInstanceOf

          public static <E> E checkInstanceOf(Class<E> type,
                                              Object object)

    - #### checkNotInstanceOf

          public static <E> E checkNotInstanceOf(Class type,
                                                 E object,
                                                 String errorMessage)

      Tests the supplied object to see if it is not a type of the supplied class.
      Parameters:
        `type` - the type that is not of the supplied class.
        `object` - the object tested against the type.
        `errorMessage` - the errorMessage
      Returns:
        the object argument.
      Throws:
        `IllegalArgumentException` - if the object is an instance of the type that is not of the expected class.

    - #### checkFalse

          public static void checkFalse(boolean expression,
                                        String errorMessage)

      Tests whether the supplied expression is `false`.
      Parameters:
        `expression` - the expression tested to see if it is `false`.
        `errorMessage` - the errorMessage
      Throws:
        `IllegalArgumentException` - if the supplied expression is `true`.

    - #### checkTrue

          public static void checkTrue(boolean expression,
                                       String errorMessage)

      Tests whether the supplied expression is `true`.
      Parameters:
        `expression` - the expression tested to see if it is `true`.
        `errorMessage` - the errorMessage
      Throws:
        `IllegalArgumentException` - if the supplied expression is `false`.

    - #### checkHasNext

          public static <T> Iterator<T> checkHasNext(Iterator<T> iterator,
                                                     String message)
                                              throws NoSuchElementException

      Check if iterator has next element. If not throw NoSuchElementException
      Parameters:
        `iterator` -
        `message` -
      Returns:
        the iterator itself
      Throws:
        `NoSuchElementException` - if iterator.hasNext returns false

    - #### checkState

          public static void checkState(boolean condition,
                                        String message)
                                 throws IllegalStateException

      Check the state of a condition
      Parameters:
        `condition` -
        `message` -
      Throws:
        `IllegalStateException` - if condition if false

Copyright © 2019. All rights reserved.