name.neuhalfen.projects.crypto.internal.Preconditions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bouncy-gpg Show documentation
Show all versions of bouncy-gpg Show documentation
Make using Bouncy Castle with OpenPGP fun again!
The newest version!
package name.neuhalfen.projects.crypto.internal;
import javax.annotation.Nullable;
/**
* Idea borrowed from google guava.
*/
public final class Preconditions {
/*
* Prevent instantiation
*/
private Preconditions() {
}
/**
* Throw a IllegalArgumentException when 'expression' is false.
*
* Call this function in methods to check parameters.
*
*
* @param expression expression that must be true, else the exception is raised
* @param message message passed to the exception
*
* @throws IllegalArgumentException expression is false
*/
public static void checkArgument(boolean expression, @Nullable String message) {
if (!expression) {
throw new IllegalArgumentException(nonNullString(message));
}
}
/**
* Throw a IllegalArgumentException when 'expression' is false.
*
* Call this function in methods to check parameters.
*
*
* @param expression expression that must be true, else the exception is raised
*
* @throws IllegalArgumentException expression is false
*/
public static void checkArgument(boolean expression) {
if (!expression) {
throw new IllegalArgumentException();
}
}
/**
* Throw a IllegalStateException when 'expression' is false.
*
* Call this function in methods to check state.
*
*
* @param expression expression that must be true, else the exception is raised
* @param message message passed to the exception
*
* @throws IllegalStateException expression is false
*/
public static void checkState(boolean expression, @Nullable String message) {
if (!expression) {
throw new IllegalStateException(nonNullString(message));
}
}
/**
* Throw a IllegalStateException when 'expression' is false.
*
* Call this function in methods to check state.
*
*
* @param expression expression that must be true, else the exception is raised
*
* @throws IllegalStateException expression is false
*/
public static void checkState(boolean expression) {
if (!expression) {
throw new IllegalStateException();
}
}
private static String nonNullString(String string) {
return (string == null) ? "" : string;
}
}