26
26
package com .amihaiemil .docker ;
27
27
28
28
import java .io .IOException ;
29
- import java .util .Collection ;
30
- import java .util .Map ;
31
- import java .util .Set ;
32
- import java .util .function .Supplier ;
33
29
import javax .json .Json ;
34
- import javax .json .JsonArray ;
35
- import javax .json .JsonNumber ;
36
30
import javax .json .JsonObject ;
37
- import javax .json .JsonString ;
38
- import javax .json .JsonValue ;
39
31
import org .apache .http .HttpEntityEnclosingRequest ;
40
32
import org .apache .http .HttpRequest ;
41
33
import org .apache .http .HttpResponse ;
48
40
* @since 0.0.1
49
41
* @todo #108:30min Add tests for PayloadOf.
50
42
*/
51
- final class PayloadOf implements JsonObject {
52
- /**
53
- * The request's payload.
54
- */
55
- private final JsonObject json ;
56
-
43
+ final class PayloadOf extends JsonResource {
57
44
/**
58
45
* Ctor.
59
46
*
60
47
* @param request The http request
61
48
* @throws IllegalStateException if the request's payload cannot be read
62
49
*/
63
50
PayloadOf (final HttpRequest request ) {
64
- this (() -> {
51
+ super (() -> {
65
52
try {
66
53
final JsonObject body ;
67
54
if (request instanceof HttpEntityEnclosingRequest ) {
@@ -87,7 +74,7 @@ final class PayloadOf implements JsonObject {
87
74
* @throws IllegalStateException if the response's payload cannot be read
88
75
*/
89
76
PayloadOf (final HttpResponse response ) {
90
- this (() -> {
77
+ super (() -> {
91
78
try {
92
79
return Json .createReader (
93
80
response .getEntity ().getContent ()
@@ -99,133 +86,4 @@ final class PayloadOf implements JsonObject {
99
86
}
100
87
});
101
88
}
102
-
103
- /**
104
- * Ctor.
105
- * @param json The json.
106
- * @throws IllegalStateException if the payload cannot be read
107
- */
108
- private PayloadOf (final Supplier <JsonObject > json ) {
109
- this .json = json .get ();
110
- }
111
-
112
- @ Override
113
- public JsonArray getJsonArray (final String name ) {
114
- return this .json .getJsonArray (name );
115
- }
116
-
117
- @ Override
118
- public JsonObject getJsonObject (final String name ) {
119
- return this .json .getJsonObject (name );
120
- }
121
-
122
- @ Override
123
- public JsonNumber getJsonNumber (final String name ) {
124
- return this .json .getJsonNumber (name );
125
- }
126
-
127
- @ Override
128
- public JsonString getJsonString (final String name ) {
129
- return this .json .getJsonString (name );
130
- }
131
-
132
- @ Override
133
- public String getString (final String name ) {
134
- return this .json .getString (name );
135
- }
136
-
137
- @ Override
138
- public String getString (final String name , final String defaultValue ) {
139
- return this .json .getString (name , defaultValue );
140
- }
141
-
142
- @ Override
143
- public int getInt (final String name ) {
144
- return this .json .getInt (name );
145
- }
146
-
147
- @ Override
148
- public int getInt (final String name , final int defaultValue ) {
149
- return this .json .getInt (name , defaultValue );
150
- }
151
-
152
- @ Override
153
- public boolean getBoolean (final String name ) {
154
- return this .json .getBoolean (name );
155
- }
156
-
157
- @ Override
158
- public boolean getBoolean (final String name , final boolean defaultValue ) {
159
- return this .json .getBoolean (name , defaultValue );
160
- }
161
-
162
- @ Override
163
- public boolean isNull (final String name ) {
164
- return this .json .isNull (name );
165
- }
166
-
167
- @ Override
168
- public ValueType getValueType () {
169
- return this .json .getValueType ();
170
- }
171
-
172
- @ Override
173
- public int size () {
174
- return this .json .size ();
175
- }
176
-
177
- @ Override
178
- public boolean isEmpty () {
179
- return this .json .isEmpty ();
180
- }
181
-
182
- @ Override
183
- public boolean containsKey (final Object key ) {
184
- return this .json .containsKey (key );
185
- }
186
-
187
- @ Override
188
- public boolean containsValue (final Object value ) {
189
- return this .json .containsValue (value );
190
- }
191
-
192
- @ Override
193
- public JsonValue get (final Object key ) {
194
- return this .json .get (key );
195
- }
196
-
197
- @ Override
198
- public JsonValue put (final String key , final JsonValue value ) {
199
- return this .json .put (key , value );
200
- }
201
-
202
- @ Override
203
- public JsonValue remove (final Object key ) {
204
- return this .json .remove (key );
205
- }
206
-
207
- @ Override
208
- public void putAll (final Map <? extends String , ? extends JsonValue > map ) {
209
- this .json .putAll (map );
210
- }
211
-
212
- @ Override
213
- public void clear () {
214
- this .json .clear ();
215
- }
216
-
217
- @ Override
218
- public Set <String > keySet () {
219
- return this .json .keySet ();
220
- }
221
-
222
- @ Override
223
- public Collection <JsonValue > values () {
224
- return this .json .values ();
225
- }
226
-
227
- @ Override
228
- public Set <Entry <String , JsonValue >> entrySet () {
229
- return this .json .entrySet ();
230
- }
231
89
}
0 commit comments