-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JsonTools: * Add control over `JsonParser.Feature#AUTO_CLOSE_SOURCE` to `JsonTools`. * Added `JsonTools#toObjectEx` with correct class casting. Common: * Renamed `RequiredFieldChecks` To `ValueChecks`. * Updated documentation.
- Loading branch information
1 parent
33ff518
commit 2ad7723
Showing
11 changed files
with
180 additions
and
147 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.3.1 | ||
0.4.0 |
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
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
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
121 changes: 0 additions & 121 deletions
121
common/src/main/java/co/arago/util/validation/RequiredFieldChecks.java
This file was deleted.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
common/src/main/java/co/arago/util/validation/ValueChecks.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,121 @@ | ||
package co.arago.util.validation; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* This interface provides value checking to the classes that implement it. | ||
*/ | ||
public interface ValueChecks { | ||
/** | ||
* Check for null values. | ||
* | ||
* @param value The value to check for null | ||
* @param name Name of the value for the exception message | ||
* @param <N> Type of any value. | ||
* @return The value itself | ||
* @throws NullPointerException when value == null | ||
*/ | ||
static <N> N notNull(N value, String name) { | ||
return Objects.requireNonNull(value, "Value '" + name + "' is required and cannot be null."); | ||
} | ||
|
||
/** | ||
* Check for null value arrays. | ||
* | ||
* @param name Name of the value for the exception message | ||
* @param value The value array to check for null | ||
* @param <N> Type of any value. | ||
* @return The value itself | ||
* @throws NullPointerException when value == null | ||
*/ | ||
static <N> N[] notNull(String name, N[] value) { | ||
if (value == null) | ||
throw new IllegalArgumentException("Value '" + name + "' is required and cannot be null."); | ||
return value; | ||
} | ||
|
||
/** | ||
* Check for null or empty value array. | ||
* | ||
* @param name Name of the value for the exception message | ||
* @param value The value array to check for null | ||
* @param <N> Type of any value. | ||
* @return The value itself | ||
* @throws NullPointerException when value == null | ||
*/ | ||
static <N> N[] notEmpty(String name, N[] value) { | ||
if (value == null || value.length == 0) | ||
throw new IllegalArgumentException("Value '" + name + "' is required and cannot be null or empty."); | ||
return value; | ||
} | ||
|
||
/** | ||
* Check for empty string values. | ||
* | ||
* @param value The value to check for | ||
* @param name Name of the value for the exception message | ||
* @return The value itself | ||
* @throws IllegalArgumentException when value is empty | ||
*/ | ||
static String notEmpty(String value, String name) { | ||
if (StringUtils.isEmpty(value)) | ||
throw new IllegalArgumentException("Value '" + name + "' cannot be empty."); | ||
return value; | ||
} | ||
|
||
/** | ||
* Check for empty collection values. | ||
* | ||
* @param value The value to check for | ||
* @param name Name of the value for the exception message | ||
* @return The value itself | ||
* @throws IllegalArgumentException when value is empty | ||
*/ | ||
static Collection<?> notEmpty(Collection<?> value, String name) { | ||
if (value == null || value.isEmpty()) | ||
throw new IllegalArgumentException("Collection '" + name + "' cannot be empty."); | ||
return value; | ||
} | ||
|
||
/** | ||
* Check for empty map values. | ||
* | ||
* @param value The value to check for | ||
* @param name Name of the value for the exception message | ||
* @return The value itself | ||
* @throws IllegalArgumentException when value is empty | ||
*/ | ||
static Map<?, ?> notEmpty(Map<?, ?> value, String name) { | ||
if (value == null || value.isEmpty()) | ||
throw new IllegalArgumentException("Map '" + name + "' cannot be empty."); | ||
return value; | ||
} | ||
|
||
/** | ||
* Check for blank string values. | ||
* | ||
* @param value The value to check for | ||
* @param name Name of the value for the exception message | ||
* @return The value itself | ||
* @throws IllegalArgumentException when value is blank | ||
*/ | ||
static String notBlank(String value, String name) { | ||
if (StringUtils.isBlank(value)) | ||
throw new IllegalArgumentException("Value '" + name + "' cannot be blank."); | ||
return value; | ||
} | ||
|
||
/** | ||
* Create an exception for any custom error | ||
* | ||
* @param message The message to display. | ||
* @throws IllegalArgumentException with the message. | ||
*/ | ||
static void anyError(String message) { | ||
throw new IllegalArgumentException(message); | ||
} | ||
} |
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
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
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
Oops, something went wrong.