36
36
* Example usage: <code>
37
37
* Object additProps = schemaJson.get("additionalProperties");
38
38
* typeMultiplexer(additionalProps)
39
- * .ifIs(JSONArray.class).then(arr -> {...if additProps is a JSONArray then process it... })
40
- * .ifObject().then(obj -> {...if additProps is a JSONArray then process it... })
39
+ * .ifIs(JSONArray.class).then(arr -> {...if additProps is a JSONArray then process it... })
40
+ * .ifObject().then(obj -> {...if additProps is a JSONArray then process it... })
41
41
* .requireAny(); // throw a SchemaException if additProps is neither a JSONArray nor a JSONObject
42
42
* </code>
43
43
*
@@ -91,10 +91,18 @@ public TypeBasedMultiplexer then(final Consumer<JSONObject> consumer) {
91
91
*
92
92
* @param <E>
93
93
* the type of the input to the operation.
94
- * @return the parent multiplexer instance
95
94
*/
96
95
@ FunctionalInterface
97
96
public interface OnTypeConsumer <E > {
97
+
98
+ /**
99
+ * Sets the callback (consumer) to be called if the type of {@code obj} is the previously set
100
+ * {@code predicateClass}.
101
+ *
102
+ * @param consumer
103
+ * the callback to be called if the type of {@code obj} is the previously set class.
104
+ * @return the parent multiplexer instance
105
+ */
98
106
TypeBasedMultiplexer then (Consumer <E > consumer );
99
107
}
100
108
@@ -132,14 +140,25 @@ public TypeBasedMultiplexer then(final Consumer<E> consumer) {
132
140
private final Collection <ResolutionScopeChangeListener > scopeChangeListeners = new ArrayList <>(1 );
133
141
134
142
/**
135
- * Constructor with {@code null} {@code keyOfObj}.
143
+ * Constructor with {@code null} {@code keyOfObj} and {@code null} {@code id}.
144
+ *
145
+ * @param obj
146
+ * the object which' class is matched against the classes defined by {@link #ifIs(Class)}
147
+ * (or {@link #ifObject()}) calls.
136
148
*/
137
149
public TypeBasedMultiplexer (final Object obj ) {
138
150
this (null , obj );
139
151
}
140
152
141
153
/**
142
154
* Contstructor with {@code null id}.
155
+ *
156
+ * @param keyOfObj
157
+ * is an optional (nullable) string used by {@link #requireAny()} to construct the
158
+ * message of the {@link SchemaException} if no appropriate consumer action is found.
159
+ * @param obj
160
+ * the object which' class is matched against the classes defined by {@link #ifIs(Class)}
161
+ * (or {@link #ifObject()}) calls.
143
162
*/
144
163
public TypeBasedMultiplexer (final String keyOfObj , final Object obj ) {
145
164
this (keyOfObj , obj , null );
@@ -172,6 +191,14 @@ public void addResolutionScopeChangeListener(
172
191
* Creates a setter which will be invoked by {@link #orElse(Consumer)} or {@link #requireAny()} if
173
192
* {@code obj} is an instance of {@code predicateClass}.
174
193
*
194
+ * @param predicateClass
195
+ * the predicate class (the callback set by a subsequent
196
+ * {@link OnTypeConsumer#then(Consumer)} will be executed if {@code obj} is an instance
197
+ * of {@code predicateClass}).
198
+ * @param <E>
199
+ * the type represented by {@code predicateClass}.
200
+ * @return an {@code OnTypeConsumer} implementation to be used to set the action performed if
201
+ * {@code obj} is an instance of {@code predicateClass}.
175
202
* @throws IllegalArgumentException
176
203
* if {@code predicateClass} is {@link JSONObject}. Use {@link #ifObject()} for matching
177
204
* {@code obj}'s class against {@link JSONObject}.
@@ -194,6 +221,9 @@ public <E> OnTypeConsumer<E> ifIs(final Class<E> predicateClass) {
194
221
* append this id value to {@link org.everit.json.schema.loader.SchemaLoader#id} for the duration
195
222
* of the action execution, then it will restore the original id.
196
223
* </p>
224
+ *
225
+ * @return an {@code OnTypeConsumer} implementation to be used to set the action performed if
226
+ * {@code obj} is a JSONObject instance.
197
227
*/
198
228
public OnTypeConsumer <JSONObject > ifObject () {
199
229
return new IdModifyingTypeConsumerImpl (JSONObject .class );
@@ -203,6 +233,9 @@ public OnTypeConsumer<JSONObject> ifObject() {
203
233
* Checks if the {@code obj} is an instance of any previously set classes (by {@link #ifIs(Class)}
204
234
* or {@link #ifObject()}), performs the mapped action of found or invokes {@code orElseConsumer}
205
235
* with the {@code obj}.
236
+ *
237
+ * @param orElseConsumer
238
+ * the callback to be called if no types matched.
206
239
*/
207
240
public void orElse (final Consumer <Object > orElseConsumer ) {
208
241
@ SuppressWarnings ("unchecked" )
0 commit comments