Skip to content

Commit

Permalink
Version 0.4.0
Browse files Browse the repository at this point in the history
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
tryptichon committed Jul 8, 2022
1 parent 33ff518 commit 2ad7723
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 147 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.4.0
2 changes: 1 addition & 1 deletion collections/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>java-project</artifactId>
<groupId>co.arago</groupId>
<version>0.3.1</version>
<version>0.4.0</version>
</parent>

<groupId>co.arago.util</groupId>
Expand Down
2 changes: 1 addition & 1 deletion common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ This is a library containing common classes that are used throughout our project
* Reflections: `co.arago.util.reflections.Reflections`
* Templates: `co.arago.util.text.templates.*`
* Tokenizer: `co.arago.util.text.EscapingStringTokenizer`
* Validation / Field checks: `co.arago.util.validation.RequiredFieldChecks`
* Validation / Field checks: `co.arago.util.validation.ValueChecks`
* Deep cloning of serializable objects: `co.arago.util.Cloner`
* Get fields of collections, maps and public fields of any object via paths: `co.arago.util.GetByPath`
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>co.arago</groupId>
<artifactId>java-project</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>
</parent>

<groupId>co.arago.util</groupId>
Expand Down
121 changes: 0 additions & 121 deletions common/src/main/java/co/arago/util/validation/RequiredFieldChecks.java

This file was deleted.

121 changes: 121 additions & 0 deletions common/src/main/java/co/arago/util/validation/ValueChecks.java
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);
}
}
4 changes: 2 additions & 2 deletions json-schema/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>co.arago</groupId>
<artifactId>java-project</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>
</parent>

<groupId>co.arago.util</groupId>
Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>co.arago.util</groupId>
<artifactId>json</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>com.kjetland</groupId>
Expand Down
4 changes: 2 additions & 2 deletions json-surfer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>co.arago</groupId>
<artifactId>java-project</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>
</parent>

<groupId>co.arago.util</groupId>
Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>co.arago.util</groupId>
<artifactId>json</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>com.github.jsurfer</groupId>
Expand Down
2 changes: 1 addition & 1 deletion json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>java-project</artifactId>
<groupId>co.arago</groupId>
<version>0.3.1</version>
<version>0.4.0</version>
</parent>

<groupId>co.arago.util</groupId>
Expand Down
Loading

0 comments on commit 2ad7723

Please sign in to comment.