-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#42] Move precondition checks into common package/class.
- Loading branch information
1 parent
c4d7cc4
commit 89f5cd2
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/org/irods/irods4j/input_validation/PreconditionViolationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/irods/irods4j/input_validation/Preconditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} |