Skip to content

Commit 0185bcb

Browse files
committed
Value API: Value vs ValueNode
1 parent 0966186 commit 0185bcb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+539
-504
lines changed

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* multiple path params on MVC routes (fix link sync)
1+
* Session set null context to Value API
22
* review toString on Value API
33
* Value vs ValueNode API
44
* tests and coverage

jooby/src/main/java/io/jooby/Body.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @author edgar
2727
* @since 2.0.0
2828
*/
29-
public interface Body extends Value {
29+
public interface Body extends ValueNode {
3030

3131
/**
3232
* HTTP body as string.

jooby/src/main/java/io/jooby/Context.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public interface Context extends Registry {
9494
* @param <T> Generic type.
9595
* @return Converted value.
9696
*/
97-
@Nullable <T> T convert(@Nonnull Value value, @Nonnull Class<T> type);
97+
@Nullable <T> T convert(@Nonnull ValueNode value, @Nonnull Class<T> type);
9898

9999
/*
100100
* **********************************************************************************************
@@ -115,7 +115,7 @@ public interface Context extends Registry {
115115
* @param name Attribute's name.
116116
* @return Flash attribute.
117117
*/
118-
@Nonnull Value flash(@Nonnull String name);
118+
@Nonnull ValueNode flash(@Nonnull String name);
119119

120120
/**
121121
* Find a session or creates a new session.
@@ -137,7 +137,7 @@ public interface Context extends Registry {
137137
* @param name Cookie's name.
138138
* @return Cookie value.
139139
*/
140-
@Nonnull Value cookie(@Nonnull String name);
140+
@Nonnull ValueNode cookie(@Nonnull String name);
141141

142142
/**
143143
* Request cookies.
@@ -190,7 +190,7 @@ public interface Context extends Registry {
190190
* @param name Path key.
191191
* @return Associated value or a missing value, but never a <code>null</code> reference.
192192
*/
193-
@Nonnull Value path(@Nonnull String name);
193+
@Nonnull ValueNode path(@Nonnull String name);
194194

195195
/**
196196
* Convert the {@link #pathMap()} to the given type.
@@ -202,10 +202,10 @@ public interface Context extends Registry {
202202
@Nonnull <T> T path(@Nonnull Class<T> type);
203203

204204
/**
205-
* Convert {@link #pathMap()} to a {@link Value} object.
205+
* Convert {@link #pathMap()} to a {@link ValueNode} object.
206206
* @return A value object.
207207
*/
208-
@Nonnull Value path();
208+
@Nonnull ValueNode path();
209209

210210
/**
211211
* Path map represent all the path keys with their values.
@@ -238,9 +238,9 @@ public interface Context extends Registry {
238238
*/
239239

240240
/**
241-
* Query string as {@link Value} object.
241+
* Query string as {@link ValueNode} object.
242242
*
243-
* @return Query string as {@link Value} object.
243+
* @return Query string as {@link ValueNode} object.
244244
*/
245245
@Nonnull QueryString query();
246246

@@ -260,7 +260,7 @@ public interface Context extends Registry {
260260
* @param name Parameter name.
261261
* @return A query value.
262262
*/
263-
@Nonnull Value query(@Nonnull String name);
263+
@Nonnull ValueNode query(@Nonnull String name);
264264

265265
/**
266266
* Query string with the leading <code>?</code> or empty string. This is the raw query string,
@@ -312,19 +312,19 @@ public interface Context extends Registry {
312312
*/
313313

314314
/**
315-
* Request headers as {@link Value}.
315+
* Request headers as {@link ValueNode}.
316316
*
317-
* @return Request headers as {@link Value}.
317+
* @return Request headers as {@link ValueNode}.
318318
*/
319-
@Nonnull Value header();
319+
@Nonnull ValueNode header();
320320

321321
/**
322322
* Get a header that matches the given name.
323323
*
324324
* @param name Header name. Case insensitive.
325325
* @return A header value or missing value, never a <code>null</code> reference.
326326
*/
327-
@Nonnull Value header(@Nonnull String name);
327+
@Nonnull ValueNode header(@Nonnull String name);
328328

329329
/**
330330
* Header as single-value map.
@@ -415,10 +415,10 @@ public interface Context extends Registry {
415415
*/
416416

417417
/**
418-
* Formdata as {@link Value}. This method is for <code>application/form-url-encoded</code>
418+
* Formdata as {@link ValueNode}. This method is for <code>application/form-url-encoded</code>
419419
* request.
420420
*
421-
* @return Formdata as {@link Value}. This method is for <code>application/form-url-encoded</code>
421+
* @return Formdata as {@link ValueNode}. This method is for <code>application/form-url-encoded</code>
422422
* request.
423423
*/
424424
@Nonnull Formdata form();
@@ -446,7 +446,7 @@ public interface Context extends Registry {
446446
* @param name Field name.
447447
* @return Form value.
448448
*/
449-
@Nonnull Value form(@Nonnull String name);
449+
@Nonnull ValueNode form(@Nonnull String name);
450450

451451
/**
452452
* Convert formdata to the given type. Only for <code>application/form-url-encoded</code>
@@ -480,7 +480,7 @@ public interface Context extends Registry {
480480
* @param name Field name.
481481
* @return Multipart value.
482482
*/
483-
@Nonnull Value multipart(@Nonnull String name);
483+
@Nonnull ValueNode multipart(@Nonnull String name);
484484

485485
/**
486486
* Convert multipart data to the given type.

jooby/src/main/java/io/jooby/DefaultContext.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public interface DefaultContext extends Context {
8484
* @param name Attribute's name.
8585
* @return Flash attribute.
8686
*/
87-
@Override default @Nonnull Value flash(@Nonnull String name) {
87+
@Override default @Nonnull ValueNode flash(@Nonnull String name) {
8888
return Value.create(this, name, flash().get(name));
8989
}
9090

@@ -121,12 +121,12 @@ public interface DefaultContext extends Context {
121121
return session;
122122
}
123123

124-
@Override default @Nonnull Value cookie(@Nonnull String name) {
124+
@Override default @Nonnull ValueNode cookie(@Nonnull String name) {
125125
String value = cookieMap().get(name);
126126
return value == null ? Value.missing(name) : Value.value(this, name, value);
127127
}
128128

129-
@Override @Nonnull default Value path(@Nonnull String name) {
129+
@Override @Nonnull default ValueNode path(@Nonnull String name) {
130130
String value = pathMap().get(name);
131131
return value == null
132132
? new MissingValue(name)
@@ -137,15 +137,15 @@ public interface DefaultContext extends Context {
137137
return path().to(type);
138138
}
139139

140-
@Override @Nonnull default Value path() {
140+
@Override @Nonnull default ValueNode path() {
141141
HashValue path = new HashValue(this, null);
142142
for (Map.Entry<String, String> entry : pathMap().entrySet()) {
143143
path.put(entry.getKey(), entry.getValue());
144144
}
145145
return path;
146146
}
147147

148-
@Override @Nonnull default Value query(@Nonnull String name) {
148+
@Override @Nonnull default ValueNode query(@Nonnull String name) {
149149
return query().get(name);
150150
}
151151

@@ -165,7 +165,7 @@ public interface DefaultContext extends Context {
165165
return query().toMultimap();
166166
}
167167

168-
@Override @Nonnull default Value header(@Nonnull String name) {
168+
@Override @Nonnull default ValueNode header(@Nonnull String name) {
169169
return header().get(name);
170170
}
171171

@@ -178,7 +178,7 @@ public interface DefaultContext extends Context {
178178
}
179179

180180
@Override default boolean accept(@Nonnull MediaType contentType) {
181-
Value accept = header(ACCEPT);
181+
ValueNode accept = header(ACCEPT);
182182
return accept.isMissing() ? true : contentType.matches(accept.value());
183183
}
184184

@@ -203,17 +203,17 @@ public interface DefaultContext extends Context {
203203
}
204204

205205
@Override @Nullable default MediaType getRequestType() {
206-
Value contentType = header("Content-Type");
206+
ValueNode contentType = header("Content-Type");
207207
return contentType.isMissing() ? null : MediaType.valueOf(contentType.value());
208208
}
209209

210210
@Override @Nonnull default MediaType getRequestType(MediaType defaults) {
211-
Value contentType = header("Content-Type");
211+
ValueNode contentType = header("Content-Type");
212212
return contentType.isMissing() ? defaults : MediaType.valueOf(contentType.value());
213213
}
214214

215215
@Override default long getRequestLength() {
216-
Value contentLength = header("Content-Length");
216+
ValueNode contentLength = header("Content-Length");
217217
return contentLength.isMissing() ? -1 : contentLength.longValue();
218218
}
219219

@@ -234,15 +234,15 @@ public interface DefaultContext extends Context {
234234
return form().toMap();
235235
}
236236

237-
@Override @Nonnull default Value form(@Nonnull String name) {
237+
@Override @Nonnull default ValueNode form(@Nonnull String name) {
238238
return form().get(name);
239239
}
240240

241241
@Override @Nonnull default <T> T form(@Nonnull Class<T> type) {
242242
return form().to(type);
243243
}
244244

245-
@Override @Nonnull default Value multipart(@Nonnull String name) {
245+
@Override @Nonnull default ValueNode multipart(@Nonnull String name) {
246246
return multipart().get(name);
247247
}
248248

@@ -259,9 +259,9 @@ public interface DefaultContext extends Context {
259259
}
260260

261261
@Override @Nonnull default List<FileUpload> files() {
262-
Value multipart = multipart();
262+
ValueNode multipart = multipart();
263263
List<FileUpload> result = new ArrayList<>();
264-
for (Value value : multipart) {
264+
for (ValueNode value : multipart) {
265265
if (value.isUpload()) {
266266
result.add((FileUpload) value);
267267
}
@@ -270,12 +270,12 @@ public interface DefaultContext extends Context {
270270
}
271271

272272
@Override @Nonnull default List<FileUpload> files(@Nonnull String name) {
273-
Value multipart = multipart(name);
273+
ValueNode multipart = multipart(name);
274274
if (multipart instanceof FileUpload) {
275275
return Collections.singletonList((FileUpload) multipart);
276276
}
277277
List<FileUpload> result = new ArrayList<>();
278-
for (Value value : multipart) {
278+
for (ValueNode value : multipart) {
279279
if (value instanceof FileUpload) {
280280
result.add((FileUpload) value);
281281
} else {
@@ -286,7 +286,7 @@ public interface DefaultContext extends Context {
286286
}
287287

288288
@Override @Nonnull default FileUpload file(@Nonnull String name) {
289-
Value value = multipart(name);
289+
ValueNode value = multipart(name);
290290
if (value instanceof FileUpload) {
291291
return (FileUpload) value;
292292
}
@@ -301,7 +301,7 @@ public interface DefaultContext extends Context {
301301
return body().to(type);
302302
}
303303

304-
@Override default @Nullable <T> T convert(Value value, Class<T> type) {
304+
@Override default @Nullable <T> T convert(ValueNode value, Class<T> type) {
305305
T result = ValueConverters.convert(value, type, getRouter());
306306
if (result == null) {
307307
throw new TypeMismatchException(value.name(), type);

jooby/src/main/java/io/jooby/FileUpload.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* @since 2.0.0
3939
* @author edgar
4040
*/
41-
public interface FileUpload extends Value {
41+
public interface FileUpload extends ValueNode {
4242
/**
4343
* Name of file upload.
4444
* @return Name of file upload.
@@ -52,19 +52,19 @@ public interface FileUpload extends Value {
5252
*/
5353
@Nullable String getContentType();
5454

55-
@Override default Value get(@Nonnull int index) {
55+
@Override default ValueNode get(@Nonnull int index) {
5656
return index == 0 ? this : get(Integer.toString(index));
5757
}
5858

59-
@Override default Value get(@Nonnull String name) {
59+
@Override default ValueNode get(@Nonnull String name) {
6060
return new MissingValue(name);
6161
}
6262

6363
@Override default int size() {
6464
return 1;
6565
}
6666

67-
@Nonnull @Override default Iterator<Value> iterator() {
67+
@Nonnull @Override default Iterator<ValueNode> iterator() {
6868
Iterator iterator = Collections.singletonList(this).iterator();
6969
return iterator;
7070
}

jooby/src/main/java/io/jooby/Formdata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @author edgar
1919
* @since 2.0.0
2020
*/
21-
public interface Formdata extends Value {
21+
public interface Formdata extends ValueNode {
2222

2323
/**
2424
* Add a form field.
@@ -27,7 +27,7 @@ public interface Formdata extends Value {
2727
* @param value Form value.
2828
* @return This formdata.
2929
*/
30-
@Nonnull Formdata put(@Nonnull String path, @Nonnull Value value);
30+
@Nonnull Formdata put(@Nonnull String path, @Nonnull ValueNode value);
3131

3232
/**
3333
* Add a form field.

0 commit comments

Comments
 (0)