com.hazelcast.util
Class ValidationUtil

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

public final class ValidationUtil
extends Object

A utility class for validating arguments and state.


Method Summary
static void checkFalse(boolean expression, String message)
          Tests whether the supplied expression is false.
static
<T> Iterator<T>
checkHasNext(Iterator<T> iterator, String message)
          Check if iterator has next element.
static
<E> E
checkInstanceOf(Class type, E object, String argumentName)
          Tests whether the supplied object is an instance of the supplied class type.
static
<E> E
checkNotInstanceOf(Class type, E object, String argumentName)
          Tests the supplied object to see if it is not a type of the supplied class.
static
<T> T
checkNotNull(T argument, String message)
          Tests if an argument is not null.
static void checkState(boolean condition, String message)
          Check the state of a condition
static String hasText(String argument, String argName)
          Tests if a string contains text.
static void isNotNegative(long value, String argumentName)
          Tests if a long value is not negative.
static
<E> E
isNotNull(E argument, String argName)
          Tests if a string is not null.
static void shouldBePositive(long value, String argumentName)
          Tests if a long value is positive.
 
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 message)
Tests if an argument is not null.

Parameters:
argument - the argument tested to see if it is not null.
message - message thrown if argument is null.
Returns:
the argument that was tested.
Throws:
NullPointerException - if argument is null

hasText

public static String hasText(String argument,
                             String argName)
Tests if a string contains text.

Parameters:
argument - the string tested to see if it contains text.
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 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.

isNotNegative

public static void isNotNegative(long value,
                                 String argumentName)
Tests if a long value is not negative.

Parameters:
value - the long value tested to see if it is not negative.
argumentName - the value name (used in message if an error is thrown).
Throws:
IllegalArgumentException - if the value is negative.

shouldBePositive

public static void shouldBePositive(long value,
                                    String argumentName)
Tests if a long value is positive.

Parameters:
value - the long value tested to see if it is positive.
argumentName - the value name (used in message if an error is thrown).
Throws:
IllegalArgumentException - if the value is not positive.

checkInstanceOf

public static <E> E checkInstanceOf(Class type,
                                    E object,
                                    String argumentName)
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.
argumentName - the argument name of the object.
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 argumentName)
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.
argumentName - the argument name of the object.
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 message)
Tests whether the supplied expression is false.

Parameters:
expression - the expression tested to see if it is false.
message - exception message in case the supplied expression is not false.
Throws:
IllegalArgumentException - if the supplied expression is true.

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 © 2015 Hazelcast, Inc.. All Rights Reserved.