55 */
66package io .jooby ;
77
8- import io .jooby .internal .ArrayValue ;
9- import io .jooby .internal .HashValue ;
10- import io .jooby .internal .MissingValue ;
11- import io .jooby .internal .SingleValue ;
12-
138import javax .annotation .Nonnull ;
14- import javax .annotation .Nullable ;
15- import java .time .Instant ;
16- import java .time .LocalDateTime ;
17- import java .time .ZoneOffset ;
18- import java .time .format .DateTimeParseException ;
19- import java .util .Collection ;
209import java .util .Collections ;
2110import java .util .Iterator ;
22- import java .util .LinkedHashMap ;
23- import java .util .List ;
24- import java .util .Map ;
2511import java .util .NoSuchElementException ;
26- import java .util .Optional ;
27- import java .util .Set ;
2812import java .util .function .BiFunction ;
29- import java .util .function .Function ;
3013
3114/**
3215 * Unified API for HTTP value. This API plays two role:
5235 */
5336public interface ValueNode extends Iterable <ValueNode >, Value {
5437
55- /**
56- * True if this value is an array/sequence (not single or hash).
57- *
58- * @return True if this value is an array/sequence.
59- */
60- default boolean isArray () {
61- return this instanceof ArrayValue ;
62- }
63-
64- /**
65- * True if this is a hash/object value (not single or array).
66- *
67- * @return True if this is a hash/object value (not single or array).
68- */
69- default boolean isObject () {
70- return this instanceof HashValue ;
71- }
72-
73- /**
74- * True if this is a file upload (not single, not array, not hash).
75- *
76- * @return True for file upload.
77- */
78- default boolean isUpload () {
79- return this instanceof FileUpload ;
80- }
81-
82- /* ***********************************************************************************************
83- * Node methods
84- * ***********************************************************************************************
85- */
86-
8738 /**
8839 * Get a value at the given position.
8940 *
@@ -109,53 +60,6 @@ default int size() {
10960 return 0 ;
11061 }
11162
112- /**
113- * Get a value or empty optional.
114- *
115- * @param type Item type.
116- * @param <T> Item type.
117- * @return Value or empty optional.
118- */
119- @ Nonnull default <T > Optional <T > toOptional (@ Nonnull Class <T > type ) {
120- try {
121- return Optional .ofNullable (to (type ));
122- } catch (MissingValueException x ) {
123- return Optional .empty ();
124- }
125- }
126-
127- /**
128- * Get list of the given type.
129- *
130- * @param type Type to convert.
131- * @param <T> Item type.
132- * @return List of items.
133- */
134- @ Nonnull default <T > List <T > toList (@ Nonnull Class <T > type ) {
135- return Collections .singletonList (to (type ));
136- }
137-
138- /**
139- * Get set of the given type.
140- *
141- * @param type Type to convert.
142- * @param <T> Item type.
143- * @return Set of items.
144- */
145- @ Nonnull default <T > Set <T > toSet (@ Nonnull Class <T > type ) {
146- return Collections .singleton (to (type ));
147- }
148-
149- /**
150- * Convert this value to the given type. Support values are single-value, array-value and
151- * object-value. Object-value can be converted to a JavaBean type.
152- *
153- * @param type Type to convert.
154- * @param <T> Element type.
155- * @return Instance of the type.
156- */
157- @ Nonnull <T > T to (@ Nonnull Class <T > type );
158-
15963 /**
16064 * Value iterator.
16165 *
@@ -165,31 +69,6 @@ default int size() {
16569 return Collections .emptyIterator ();
16670 }
16771
168- /**
169- * Name of this value or <code>null</code>.
170- *
171- * @return Name of this value or <code>null</code>.
172- */
173- @ Nullable String name ();
174-
175- /**
176- * Value as multi-value map.
177- *
178- * @return Value as multi-value map.
179- */
180- @ Nullable Map <String , List <String >> toMultimap ();
181-
182- /**
183- * Value as single-value map.
184- *
185- * @return Value as single-value map.
186- */
187- default @ Nonnull Map <String , String > toMap () {
188- Map <String , String > map = new LinkedHashMap <>();
189- toMultimap ().forEach ((k , v ) -> map .put (k , v .get (0 )));
190- return map ;
191- }
192-
19372 /**
19473 * Process the given expression and resolve value references.
19574 *
0 commit comments