You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added Validator.add() and Validator.or() logical operators.
* Removed all type converters from ObjectValidator and StringValidator because the concept does not scale. We can't just keep on adding methods to these centralized classes.
@@ -84,8 +84,10 @@ If you violate a **class invariant**:
84
84
85
85
```java
86
86
Cake cake =newCake(1_000_000);
87
-
while (true)
88
-
cake.eat();
87
+
while(true)
88
+
cake.
89
+
90
+
eat();
89
91
```
90
92
91
93
You'll get:
@@ -99,8 +101,10 @@ If you violate a **postcondition**:
99
101
100
102
```java
101
103
Cake cake =newCake(100);
102
-
while (true)
103
-
cake.eat();
104
+
while(true)
105
+
cake.
106
+
107
+
eat();
104
108
```
105
109
106
110
You'll get:
@@ -114,12 +118,19 @@ If you violate **multiple** conditions at once:
114
118
115
119
```java
116
120
Cake cake =newCake(1);
117
-
cake.bitesTaken =-1;
118
-
cake.piecesLeft =2;
121
+
cake.bitesTaken =-1;
122
+
cake.piecesLeft =2;
119
123
StringJoiner failures =newStringJoiner("\n\n");
120
-
for (String failure : cake.getFailures())
121
-
failures.add(failure);
122
-
System.out.println(failures);
124
+
for(
125
+
String failure :cake.
126
+
127
+
getFailures())
128
+
failures.
129
+
130
+
add(failure);
131
+
System.out.
132
+
133
+
println(failures);
123
134
```
124
135
125
136
You'll get:
@@ -144,6 +155,8 @@ This library offers the following features:
144
155
*[Multiple validation failures](docs/Features.md#multiple-validation-failures) that report all the errors at
145
156
once
146
157
*[Nested validations](docs/Features.md#nested-validations) that allow you to validate complex objects
158
+
*[Logical operators](docs/Features.md#logical-operators) that allow you to combine the validation of
159
+
unrelated values
147
160
*[String diff](docs/Features.md#string-diff) that shows the differences between two strings
148
161
*[Performant and robust](docs/Performance.md)
149
162
@@ -152,28 +165,35 @@ This library offers the following features:
152
165
Designed for discovery using your favorite IDE's auto-complete feature.
153
166
The main entry points are:
154
167
155
-
*[requireThat(value, name)](https://cowwoc.github.io/requirements.java/10.0/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#requireThat(T,java.lang.String)) for method preconditions.
156
-
*[assumeThat(value, name)](https://cowwoc.github.io/requirements.java/10.0/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#assumeThat(T,java.lang.String)) for class invariants, method postconditions and private methods.
157
-
*[checkIfThat(value, name)](https://cowwoc.github.io/requirements.java/10.0/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#checkIf(T,java.lang.String)) for multiple failures and customized error handling.
158
-
*[JavaValidators](https://cowwoc.github.io/requirements.java/10.0/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/JavaValidators.html) for custom configurations.
The first three methods use a shared configuration, while `JavaValidators` allows you to create an independent
161
178
configuration.
162
179
163
180
*`requireThat()` and `assumeThat()` throw an exception on the first validation failure.
164
-
*`checkIf()` returns multiple validation failures at once. It is more flexible than the others, but its syntax
165
-
is more verbose.
181
+
*`checkIf()` returns multiple validation failures at once. It is more flexible than the others, but its
182
+
syntax
183
+
is more verbose.
166
184
167
-
Thrown exceptions may be configured using [ConfigurationUpdater.exceptionTransformer(Function)](https://cowwoc.github.io/requirements.java/10.0/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/ConfigurationUpdater.html#exceptionTransformer(java.util.function.Function)).
185
+
Thrown exceptions may be configured
186
+
using [ConfigurationUpdater.exceptionTransformer(Function)](https://cowwoc.github.io/requirements.java/10.0/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/ConfigurationUpdater.html#exceptionTransformer(java.util.function.Function)).
168
187
169
188
See the [API documentation](https://cowwoc.github.io/requirements.java/10.0/docs/api/) for more details.
170
189
171
190
## Tips
172
191
173
-
* Use `assert` with `assumeThat().elseThrow()` for sanity checks. When assertions are disabled, the checks will get removed.
192
+
* Use `assert` with `assumeThat().elseThrow()` for sanity checks. When assertions are disabled, the checks
193
+
will get removed.
174
194
* Use `checkIf().elseGetMessages()` to return failure messages without throwing an exception.
175
195
This is the fastest validation approach, ideal for web services.
176
-
* To enhance the clarity of failure messages, you should provide parameter names, even when they are optional.
196
+
* To enhance the clarity of failure messages, you should provide parameter names, even when they are optional.
177
197
In other words, favor `assumeThat(value, name)` to `assumeThat(value)`.
Copy file name to clipboardExpand all lines: jackson/src/main/java/com/github/cowwoc/requirements10/jackson/internal/validator/JacksonValidatorsImpl.java
0 commit comments