org.whispersystems.signalservice.api.util.Preconditions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-service-java Show documentation
Show all versions of signal-service-java Show documentation
Signal Service communication library for Java, unofficial fork
package org.whispersystems.signalservice.api.util;
/**
* Convenient ways to assert expected state.
*/
public final class Preconditions {
private Preconditions() {}
public static void checkArgument(boolean state) {
checkArgument(state, "Condition must be true!");
}
public static void checkArgument(boolean state, String message) {
if (!state) {
throw new IllegalArgumentException(message);
}
}
public static void checkState(boolean state) {
checkState(state, "Condition must be true!");
}
public static void checkState(boolean state, String message) {
if (!state) {
throw new IllegalStateException(message);
}
}
public static E checkNotNull(E object) {
return checkNotNull(object, "Must not be null!");
}
public static E checkNotNull(E object, String message) {
if (object == null) {
throw new NullPointerException(message);
} else {
return object;
}
}
}