diff --git a/src/main/java/org/irods/irods4j/input_validation/PreconditionViolationException.java b/src/main/java/org/irods/irods4j/input_validation/PreconditionViolationException.java new file mode 100644 index 0000000..ad19cac --- /dev/null +++ b/src/main/java/org/irods/irods4j/input_validation/PreconditionViolationException.java @@ -0,0 +1,11 @@ +package org.irods.irods4j.input_validation; + +public class PreconditionViolationException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public PreconditionViolationException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/irods/irods4j/input_validation/Preconditions.java b/src/main/java/org/irods/irods4j/input_validation/Preconditions.java new file mode 100644 index 0000000..ddf8ab5 --- /dev/null +++ b/src/main/java/org/irods/irods4j/input_validation/Preconditions.java @@ -0,0 +1,54 @@ +package org.irods.irods4j.input_validation; + +public class Preconditions { + + /** + * Checks if the object is null. + * + * @param o The object to check for null. + * @param message The precondition violation message. + * + * @throws PreconditionViolationException If the object is null. + * + * @since 0.1.0 + */ + public static void notNull(Object o, String message) { + if (null == o) { + throw new PreconditionViolationException(message); + } + } + + /** + * Checks if a string is null or empty. + * + * @param s The string to check. + * @param message The precondition violation message. + * + * @throws PreconditionViolationException If the object is null. + * + * @since 0.1.0 + */ + public static void notNullOrEmpty(String s, String message) { + if (null == s || s.isEmpty()) { + throw new PreconditionViolationException(message); + } + } + + /** + * Checks if an integer is greater than or equal to a threshold. + * + * @param value The integer to test. + * @param threshold The integer to test against. + * @param message The precondition violation message. + * + * @throws PreconditionViolationException If the object is null. + * + * @since 0.1.0 + */ + public static void greaterThanOrEqualToValue(long value, long threshold, String message) { + if (value < threshold) { + throw new PreconditionViolationException(message); + } + } + +}