Skip to content

Commit 2ad7723

Browse files
committed
Version 0.4.0
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.
1 parent 33ff518 commit 2ad7723

File tree

11 files changed

+180
-147
lines changed

11 files changed

+180
-147
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.1
1+
0.4.0

collections/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<artifactId>java-project</artifactId>
99
<groupId>co.arago</groupId>
10-
<version>0.3.1</version>
10+
<version>0.4.0</version>
1111
</parent>
1212

1313
<groupId>co.arago.util</groupId>

common/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ This is a library containing common classes that are used throughout our project
55
* Reflections: `co.arago.util.reflections.Reflections`
66
* Templates: `co.arago.util.text.templates.*`
77
* Tokenizer: `co.arago.util.text.EscapingStringTokenizer`
8-
* Validation / Field checks: `co.arago.util.validation.RequiredFieldChecks`
8+
* Validation / Field checks: `co.arago.util.validation.ValueChecks`
99
* Deep cloning of serializable objects: `co.arago.util.Cloner`
1010
* Get fields of collections, maps and public fields of any object via paths: `co.arago.util.GetByPath`

common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>co.arago</groupId>
99
<artifactId>java-project</artifactId>
10-
<version>0.3.1</version>
10+
<version>0.4.0</version>
1111
</parent>
1212

1313
<groupId>co.arago.util</groupId>

common/src/main/java/co/arago/util/validation/RequiredFieldChecks.java

Lines changed: 0 additions & 121 deletions
This file was deleted.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package co.arago.util.validation;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
import java.util.Collection;
6+
import java.util.Map;
7+
import java.util.Objects;
8+
9+
/**
10+
* This interface provides value checking to the classes that implement it.
11+
*/
12+
public interface ValueChecks {
13+
/**
14+
* Check for null values.
15+
*
16+
* @param value The value to check for null
17+
* @param name Name of the value for the exception message
18+
* @param <N> Type of any value.
19+
* @return The value itself
20+
* @throws NullPointerException when value == null
21+
*/
22+
static <N> N notNull(N value, String name) {
23+
return Objects.requireNonNull(value, "Value '" + name + "' is required and cannot be null.");
24+
}
25+
26+
/**
27+
* Check for null value arrays.
28+
*
29+
* @param name Name of the value for the exception message
30+
* @param value The value array to check for null
31+
* @param <N> Type of any value.
32+
* @return The value itself
33+
* @throws NullPointerException when value == null
34+
*/
35+
static <N> N[] notNull(String name, N[] value) {
36+
if (value == null)
37+
throw new IllegalArgumentException("Value '" + name + "' is required and cannot be null.");
38+
return value;
39+
}
40+
41+
/**
42+
* Check for null or empty value array.
43+
*
44+
* @param name Name of the value for the exception message
45+
* @param value The value array to check for null
46+
* @param <N> Type of any value.
47+
* @return The value itself
48+
* @throws NullPointerException when value == null
49+
*/
50+
static <N> N[] notEmpty(String name, N[] value) {
51+
if (value == null || value.length == 0)
52+
throw new IllegalArgumentException("Value '" + name + "' is required and cannot be null or empty.");
53+
return value;
54+
}
55+
56+
/**
57+
* Check for empty string values.
58+
*
59+
* @param value The value to check for
60+
* @param name Name of the value for the exception message
61+
* @return The value itself
62+
* @throws IllegalArgumentException when value is empty
63+
*/
64+
static String notEmpty(String value, String name) {
65+
if (StringUtils.isEmpty(value))
66+
throw new IllegalArgumentException("Value '" + name + "' cannot be empty.");
67+
return value;
68+
}
69+
70+
/**
71+
* Check for empty collection values.
72+
*
73+
* @param value The value to check for
74+
* @param name Name of the value for the exception message
75+
* @return The value itself
76+
* @throws IllegalArgumentException when value is empty
77+
*/
78+
static Collection<?> notEmpty(Collection<?> value, String name) {
79+
if (value == null || value.isEmpty())
80+
throw new IllegalArgumentException("Collection '" + name + "' cannot be empty.");
81+
return value;
82+
}
83+
84+
/**
85+
* Check for empty map values.
86+
*
87+
* @param value The value to check for
88+
* @param name Name of the value for the exception message
89+
* @return The value itself
90+
* @throws IllegalArgumentException when value is empty
91+
*/
92+
static Map<?, ?> notEmpty(Map<?, ?> value, String name) {
93+
if (value == null || value.isEmpty())
94+
throw new IllegalArgumentException("Map '" + name + "' cannot be empty.");
95+
return value;
96+
}
97+
98+
/**
99+
* Check for blank string values.
100+
*
101+
* @param value The value to check for
102+
* @param name Name of the value for the exception message
103+
* @return The value itself
104+
* @throws IllegalArgumentException when value is blank
105+
*/
106+
static String notBlank(String value, String name) {
107+
if (StringUtils.isBlank(value))
108+
throw new IllegalArgumentException("Value '" + name + "' cannot be blank.");
109+
return value;
110+
}
111+
112+
/**
113+
* Create an exception for any custom error
114+
*
115+
* @param message The message to display.
116+
* @throws IllegalArgumentException with the message.
117+
*/
118+
static void anyError(String message) {
119+
throw new IllegalArgumentException(message);
120+
}
121+
}

json-schema/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>co.arago</groupId>
99
<artifactId>java-project</artifactId>
10-
<version>0.3.1</version>
10+
<version>0.4.0</version>
1111
</parent>
1212

1313
<groupId>co.arago.util</groupId>
@@ -21,7 +21,7 @@
2121
<dependency>
2222
<groupId>co.arago.util</groupId>
2323
<artifactId>json</artifactId>
24-
<version>0.3.1</version>
24+
<version>0.4.0</version>
2525
</dependency>
2626
<dependency>
2727
<groupId>com.kjetland</groupId>

json-surfer/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>co.arago</groupId>
99
<artifactId>java-project</artifactId>
10-
<version>0.3.1</version>
10+
<version>0.4.0</version>
1111
</parent>
1212

1313
<groupId>co.arago.util</groupId>
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>co.arago.util</groupId>
2424
<artifactId>json</artifactId>
25-
<version>0.3.1</version>
25+
<version>0.4.0</version>
2626
</dependency>
2727
<dependency>
2828
<groupId>com.github.jsurfer</groupId>

json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<artifactId>java-project</artifactId>
99
<groupId>co.arago</groupId>
10-
<version>0.3.1</version>
10+
<version>0.4.0</version>
1111
</parent>
1212

1313
<groupId>co.arago.util</groupId>

0 commit comments

Comments
 (0)