Skip to content

Commit fc7516c

Browse files
committed
value api: move Value to value package
- code cleanup
1 parent 9c33a12 commit fc7516c

File tree

55 files changed

+530
-590
lines changed

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

+530
-590
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.channels.ReadableByteChannel;
1111
import java.nio.charset.Charset;
1212
import java.nio.file.Path;
13+
import java.util.Iterator;
1314
import java.util.List;
1415
import java.util.Set;
1516

@@ -19,6 +20,8 @@
1920
import io.jooby.internal.ByteArrayBody;
2021
import io.jooby.internal.FileBody;
2122
import io.jooby.internal.InputStreamBody;
23+
import io.jooby.internal.MissingValue;
24+
import io.jooby.value.Value;
2225

2326
/**
2427
* HTTP body value. Allows to access HTTP body as string, byte[], stream, etc..
@@ -45,6 +48,26 @@ public interface Body extends Value {
4548
return new String(bytes, charset);
4649
}
4750

51+
@Override
52+
default int size() {
53+
return 1;
54+
}
55+
56+
@Override
57+
default Value get(int index) {
58+
return get(Integer.toString(index));
59+
}
60+
61+
@Override
62+
default Value get(@NonNull String name) {
63+
return new MissingValue(name);
64+
}
65+
66+
@Override
67+
default Iterator<Value> iterator() {
68+
return List.of((Value) this).iterator();
69+
}
70+
4871
/**
4972
* HTTP body as byte array.
5073
*

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

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
import edu.umd.cs.findbugs.annotations.Nullable;
3333
import io.jooby.buffer.DataBuffer;
3434
import io.jooby.buffer.DataBufferFactory;
35-
import io.jooby.exception.TypeMismatchException;
3635
import io.jooby.internal.LocaleUtils;
3736
import io.jooby.internal.ParamLookupImpl;
3837
import io.jooby.internal.ReadOnlyContext;
3938
import io.jooby.internal.WebSocketSender;
39+
import io.jooby.value.Value;
40+
import io.jooby.value.ValueFactory;
4041

4142
/**
4243
* HTTP context allows you to interact with the HTTP Request and manipulate the HTTP Response.
@@ -135,16 +136,16 @@ private static Selector single() {
135136
* @param value Attribute value.
136137
* @return This router.
137138
*/
138-
@NonNull Context setAttribute(@NonNull String key, Object value);
139+
Context setAttribute(@NonNull String key, Object value);
139140

140141
/**
141142
* Get the HTTP router (usually this represents an instance of {@link Jooby}.
142143
*
143144
* @return HTTP router (usually this represents an instance of {@link Jooby}.
144145
*/
145-
@NonNull Router getRouter();
146+
Router getRouter();
146147

147-
@NonNull DataBufferFactory getBufferFactory();
148+
DataBufferFactory getBufferFactory();
148149

149150
/**
150151
* Forward executing to another route. We use the given path to find a matching route.
@@ -154,33 +155,7 @@ private static Selector single() {
154155
* @param path Path to forward the request.
155156
* @return Forward result.
156157
*/
157-
@NonNull Object forward(@NonNull String path);
158-
159-
/**
160-
* Converts a value (single or hash) into the given type.
161-
*
162-
* @param value Value to convert.
163-
* @param type Expected type.
164-
* @param <T> Generic type.
165-
* @return Converted value.
166-
*/
167-
default @NonNull <T> T convert(@NonNull Value value, @NonNull Class<T> type) {
168-
T result = convertOrNull(value, type);
169-
if (result == null) {
170-
throw new TypeMismatchException(value.name(), type);
171-
}
172-
return result;
173-
}
174-
175-
/**
176-
* Converts a value (single or hash) into the given type.
177-
*
178-
* @param value Value to convert.
179-
* @param type Expected type.
180-
* @param <T> Generic type.
181-
* @return Converted value or <code>null</code>.
182-
*/
183-
@Nullable <T> T convertOrNull(@NonNull Value value, @NonNull Class<T> type);
158+
Object forward(@NonNull String path);
184159

185160
/*
186161
* **********************************************************************************************
@@ -193,7 +168,7 @@ private static Selector single() {
193168
*
194169
* @return Flash map.
195170
*/
196-
@NonNull FlashMap flash();
171+
FlashMap flash();
197172

198173
/**
199174
* Flash map or null when no flash cookie exists.
@@ -202,13 +177,15 @@ private static Selector single() {
202177
*/
203178
@Nullable FlashMap flashOrNull();
204179

180+
ValueFactory getValueFactory();
181+
205182
/**
206183
* Get a flash attribute.
207184
*
208185
* @param name Attribute's name.
209186
* @return Flash attribute.
210187
*/
211-
@NonNull Value flash(@NonNull String name);
188+
Value flash(@NonNull String name);
212189

213190
/**
214191
* Find a session or creates a new session.

0 commit comments

Comments
 (0)