cz.jalasoft.util.ArgumentAssertion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JalasoftUtils Show documentation
Show all versions of JalasoftUtils Show documentation
A collection of utility classes that might be useful.
package cz.jalasoft.util;
/**
* A utility class that allows checking of method parameters
* and throwing {@link java.lang.IllegalArgumentException} in case
* that an argument is not valid.
*
* Created by Honza Lastovicka on 19.4.15.
*/
public final class ArgumentAssertion {
public static void mustNotBeNull(Object obj, String name) {
if (obj == null) {
throw new IllegalArgumentException(name + " must notbe null.");
}
}
public static void mustNotBeNegative(int number, String name) {
if (number < 0) {
throw new IllegalArgumentException(name + " must not be negative.");
}
}
public static void mustNotBeNullOrEmpty(String value, String name) {
if (value == null || value.isEmpty()) {
throw new IllegalArgumentException(name + " must not be null or empty.");
}
}
public static void mustBeBetweenIncluding(int value, int lowerBoundary, int higherBoudary, String name) {
if (value < lowerBoundary || value > higherBoudary) {
throw new IllegalArgumentException(name + " must be >= than " + lowerBoundary + " and =< than " + higherBoudary);
}
}
private ArgumentAssertion() {
throw new RuntimeException();
}
}