com.twitter.common.base
Class MorePreconditions

java.lang.Object
  extended by com.twitter.common.base.MorePreconditions

public final class MorePreconditions
extends Object

A utility helpful in concisely checking preconditions on arguments. This utility is a complement to Preconditions.


Method Summary
static double checkArgumentRange(double argument, double minimum, double maximum, String message)
          Checks that a double falls within a specified range, inclusive
static int checkArgumentRange(int argument, int minimum, int maximum, String message)
          Checks that an int falls within a specified range, inclusive
static boolean checkArguments(String message, Boolean... arguments)
          Checks that at least one of the specified arguments is true.
static String checkNotBlank(String argument)
          Checks that a string is both non-null and non-empty.
static String checkNotBlank(String argument, String message, Object... args)
          Checks that a string is both non-null and non-empty.
static
<S,T extends Iterable<S>>
T
checkNotBlank(T argument)
          Checks that an Iterable is both non-null and non-empty.
static
<S,T extends Iterable<S>>
T
checkNotBlank(T argument, String message, Object... args)
          Checks that an Iterable is both non-null and non-empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkNotBlank

public static String checkNotBlank(String argument)
Checks that a string is both non-null and non-empty.

See Also:
checkNotBlank(String, String, Object...)

checkNotBlank

public static String checkNotBlank(String argument,
                                   String message,
                                   Object... args)
Checks that a string is both non-null and non-empty.

Parameters:
argument - the argument to validate
message - the message template for validation exception messages where %s serves as the sole argument placeholder
args - any arguments needed by the message template
Returns:
the argument if it is valid
Throws:
NullPointerException - if the argument is null
IllegalArgumentException - if the argument is the empty string or a pure whitespace string

checkNotBlank

public static <S,T extends Iterable<S>> T checkNotBlank(T argument)
Checks that an Iterable is both non-null and non-empty. This method does not check individual elements in the Iterable.

See Also:
checkNotBlank(Iterable, String, Object...)

checkNotBlank

public static <S,T extends Iterable<S>> T checkNotBlank(T argument,
                                                        String message,
                                                        Object... args)
Checks that an Iterable is both non-null and non-empty. This method does not check individual elements in the Iterable, it just checks that the Iterable has at least one element.

Parameters:
argument - the argument to validate
message - the message template for validation exception messages where %s serves as the sole argument placeholder
args - any arguments needed by the message template
Returns:
the argument if it is valid
Throws:
NullPointerException - if the argument is null
IllegalArgumentException - if the argument has no iterable elements

checkArgumentRange

public static double checkArgumentRange(double argument,
                                        double minimum,
                                        double maximum,
                                        String message)
Checks that a double falls within a specified range, inclusive

Parameters:
argument - argument to validate.
minimum - minimum possible valid value for the argument.
maximum - maximum possible valid value for the argument.
message - the message template for validation exception messages where %s serves as the sole argument placeholder.
Returns:
the argument if it is valid.
Throws:
IllegalArgumentException - if the argument falls outside of the specified range.

checkArgumentRange

public static int checkArgumentRange(int argument,
                                     int minimum,
                                     int maximum,
                                     String message)
Checks that an int falls within a specified range, inclusive

Parameters:
argument - argument to validate.
minimum - minimum possible valid value for the argument.
maximum - maximum possible valid value for the argument.
message - the message template for validation exception messages where %s serves as the sole argument placeholder.
Returns:
the argument if it is valid.
Throws:
IllegalArgumentException - if the argument falls outside of the specified range.

checkArguments

public static boolean checkArguments(String message,
                                     Boolean... arguments)
Checks that at least one of the specified arguments is true.

Parameters:
message - the message for validation exception messages.
arguments - one or more arguments to check.
Returns:
true if at least one of the arguments is true.
Throws:
IllegalArgumentException - if none of the arguments are true.