com.hazelcast.util
Class Preconditions

java.lang.Object
  extended by com.hazelcast.util.Preconditions

public final class Preconditions
extends Object

A utility class for validating arguments and state.


Method Summary
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 String checkHasText(String argument, String errorMessage)
          Tests if a string contains text.
static
<E> E
checkInstanceOf(Class type, E 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 a long value is not negative.
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 a value is not negative.
static long checkNotNegative(long value, String errorMessage)
          Tests if a value is not negative.
static
<T> T
checkNotNull(T argument, String errorMessage)
          Tests if an argument is not null.
static int checkPositive(int value, String errorMessage)
          Tests if a value is positive; larger than 0.
static long checkPositive(long value, String errorMessage)
          Tests if a value is positive; so larger than 0.
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

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

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

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 a value is not negative.

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 a value is not negative.

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 a long value is not negative.

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; so larger than 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; larger than 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 type,
                                    E 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.

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.


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.