@@ -65,10 +65,22 @@ public boolean isObject() {
65
65
return true ;
66
66
}
67
67
68
- public AbstractObject object () {
68
+ public AbstractObject object (boolean strict ) throws AbstractCoercingException {
69
69
return this ;
70
70
}
71
71
72
+ public AbstractArray array (boolean strict ) throws AbstractCoercingException {
73
+ if (strict )
74
+ throw new AbstractCoercingException (Type .ARRAY , Type .OBJECT );
75
+ AbstractArray array = new AbstractArray ();
76
+ for (int i = 0 ; i < size (); i ++) {
77
+ if (!has (String .valueOf (i )))
78
+ throw new AbstractCoercingException (Type .ARRAY , this );
79
+ array .add (get (String .valueOf (i )));
80
+ }
81
+ return array ;
82
+ }
83
+
72
84
public AbstractElement get (String key ) {
73
85
return entries .get (key );
74
86
}
@@ -91,6 +103,8 @@ public AbstractElement query(String query) {
91
103
}
92
104
93
105
public AbstractElement query (String query , AbstractElement orElse ) {
106
+ if (orElse == null )
107
+ orElse = AbstractNull .VALUE ;
94
108
AbstractElement value = query (query );
95
109
return (value != null && !value .isNull ()) ? value : orElse ;
96
110
}
@@ -127,18 +141,6 @@ public int size() {
127
141
return entries .size ();
128
142
}
129
143
130
- public AbstractArray array (boolean strict ) throws AbstractCoercingException {
131
- if (strict )
132
- throw new AbstractCoercingException (Type .ARRAY , Type .OBJECT );
133
- AbstractArray array = new AbstractArray ();
134
- for (int i = 0 ; i < size (); i ++) {
135
- if (!has (String .valueOf (i )))
136
- throw new AbstractCoercingException (Type .ARRAY , this );
137
- array .add (get (String .valueOf (i )));
138
- }
139
- return array ;
140
- }
141
-
142
144
public AbstractObject object (String key ) throws AbstractCoercingException {
143
145
return query (key , AbstractNull .VALUE ).object ();
144
146
}
@@ -168,23 +170,23 @@ public String string(String key) throws AbstractCoercingException {
168
170
}
169
171
170
172
public String string (String key , String orElse ) throws AbstractCoercingException {
171
- return query (key , new AbstractPrimitive (orElse )).string ();
173
+ return query (key , orElse == null ? AbstractNull . VALUE : new AbstractPrimitive (orElse )).string ();
172
174
}
173
175
174
176
public Boolean bool (String key ) throws AbstractCoercingException {
175
177
return query (key , AbstractNull .VALUE ).bool ();
176
178
}
177
179
178
180
public Boolean bool (String key , Boolean orElse ) throws AbstractCoercingException {
179
- return query (key , new AbstractPrimitive (orElse )).bool ();
181
+ return query (key , orElse == null ? AbstractNull . VALUE : new AbstractPrimitive (orElse )).bool ();
180
182
}
181
183
182
184
public Number number (String key ) throws AbstractCoercingException {
183
185
return query (key , AbstractNull .VALUE ).number ();
184
186
}
185
187
186
188
public Number number (String key , Number orElse ) throws AbstractCoercingException {
187
- return query (key , new AbstractPrimitive (orElse )).number ();
189
+ return query (key , orElse == null ? AbstractNull . VALUE : new AbstractPrimitive (orElse )).number ();
188
190
}
189
191
190
192
public Object toObject () {
0 commit comments