forked from alibaba/fastjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONArray.java
More file actions
executable file
·368 lines (275 loc) · 8.81 KB
/
JSONArray.java
File metadata and controls
executable file
·368 lines (275 loc) · 8.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*
* Copyright 1999-2101 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.fastjson;
import static com.alibaba.fastjson.util.TypeUtils.castToBigDecimal;
import static com.alibaba.fastjson.util.TypeUtils.castToBigInteger;
import static com.alibaba.fastjson.util.TypeUtils.castToBoolean;
import static com.alibaba.fastjson.util.TypeUtils.castToByte;
import static com.alibaba.fastjson.util.TypeUtils.castToDate;
import static com.alibaba.fastjson.util.TypeUtils.castToDouble;
import static com.alibaba.fastjson.util.TypeUtils.castToFloat;
import static com.alibaba.fastjson.util.TypeUtils.castToInt;
import static com.alibaba.fastjson.util.TypeUtils.castToLong;
import static com.alibaba.fastjson.util.TypeUtils.castToShort;
import static com.alibaba.fastjson.util.TypeUtils.castToSqlDate;
import static com.alibaba.fastjson.util.TypeUtils.castToString;
import static com.alibaba.fastjson.util.TypeUtils.castToTimestamp;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.RandomAccess;
import com.alibaba.fastjson.util.TypeUtils;
/**
* @author wenshao[szujobs@hotmail.com]
*/
public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAccess, Serializable {
private static final long serialVersionUID = 1L;
private final List<Object> list;
protected transient Object relatedArray;
protected transient Type componentType;
public JSONArray(){
this.list = new ArrayList<Object>(10);
}
public JSONArray(List<Object> list){
this.list = list;
}
public JSONArray(int initialCapacity){
this.list = new ArrayList<Object>(initialCapacity);
}
/**
* @since 1.1.16
* @return
*/
public Object getRelatedArray() {
return relatedArray;
}
public void setRelatedArray(Object relatedArray) {
this.relatedArray = relatedArray;
}
public Type getComponentType() {
return componentType;
}
public void setComponentType(Type componentType) {
this.componentType = componentType;
}
public int size() {
return list.size();
}
public boolean isEmpty() {
return list.isEmpty();
}
public boolean contains(Object o) {
return list.contains(o);
}
public Iterator<Object> iterator() {
return list.iterator();
}
public Object[] toArray() {
return list.toArray();
}
public <T> T[] toArray(T[] a) {
return list.toArray(a);
}
public boolean add(Object e) {
return list.add(e);
}
public boolean remove(Object o) {
return list.remove(o);
}
public boolean containsAll(Collection<?> c) {
return list.containsAll(c);
}
public boolean addAll(Collection<? extends Object> c) {
return list.addAll(c);
}
public boolean addAll(int index, Collection<? extends Object> c) {
return list.addAll(index, c);
}
public boolean removeAll(Collection<?> c) {
return list.removeAll(c);
}
public boolean retainAll(Collection<?> c) {
return list.retainAll(c);
}
public void clear() {
list.clear();
}
public Object set(int index, Object element) {
return list.set(index, element);
}
public void add(int index, Object element) {
list.add(index, element);
}
public Object remove(int index) {
return list.remove(index);
}
public int indexOf(Object o) {
return list.indexOf(o);
}
public int lastIndexOf(Object o) {
return list.lastIndexOf(o);
}
public ListIterator<Object> listIterator() {
return list.listIterator();
}
public ListIterator<Object> listIterator(int index) {
return list.listIterator(index);
}
public List<Object> subList(int fromIndex, int toIndex) {
return list.subList(fromIndex, toIndex);
}
public Object get(int index) {
return list.get(index);
}
public JSONObject getJSONObject(int index) {
Object value = list.get(index);
if (value instanceof JSONObject) {
return (JSONObject) value;
}
return (JSONObject) toJSON(value);
}
public JSONArray getJSONArray(int index) {
Object value = list.get(index);
if (value instanceof JSONArray) {
return (JSONArray) value;
}
return (JSONArray) toJSON(value);
}
public <T> T getObject(int index, Class<T> clazz) {
Object obj = list.get(index);
return TypeUtils.castToJavaBean(obj, clazz);
}
public Boolean getBoolean(int index) {
Object value = get(index);
if (value == null) {
return null;
}
return castToBoolean(value);
}
public boolean getBooleanValue(int index) {
Object value = get(index);
if (value == null) {
return false;
}
return castToBoolean(value).booleanValue();
}
public Byte getByte(int index) {
Object value = get(index);
return castToByte(value);
}
public byte getByteValue(int index) {
Object value = get(index);
if (value == null) {
return 0;
}
return castToByte(value).byteValue();
}
public Short getShort(int index) {
Object value = get(index);
return castToShort(value);
}
public short getShortValue(int index) {
Object value = get(index);
if (value == null) {
return 0;
}
return castToShort(value).shortValue();
}
public Integer getInteger(int index) {
Object value = get(index);
return castToInt(value);
}
public int getIntValue(int index) {
Object value = get(index);
if (value == null) {
return 0;
}
return castToInt(value).intValue();
}
public Long getLong(int index) {
Object value = get(index);
return castToLong(value);
}
public long getLongValue(int index) {
Object value = get(index);
if (value == null) {
return 0L;
}
return castToLong(value).longValue();
}
public Float getFloat(int index) {
Object value = get(index);
return castToFloat(value);
}
public float getFloatValue(int index) {
Object value = get(index);
if (value == null) {
return 0F;
}
return castToFloat(value).floatValue();
}
public Double getDouble(int index) {
Object value = get(index);
return castToDouble(value);
}
public double getDoubleValue(int index) {
Object value = get(index);
if (value == null) {
return 0D;
}
return castToDouble(value);
}
public BigDecimal getBigDecimal(int index) {
Object value = get(index);
return castToBigDecimal(value);
}
public BigInteger getBigInteger(int index) {
Object value = get(index);
return castToBigInteger(value);
}
public String getString(int index) {
Object value = get(index);
return castToString(value);
}
public java.util.Date getDate(int index) {
Object value = get(index);
return castToDate(value);
}
public java.sql.Date getSqlDate(int index) {
Object value = get(index);
return castToSqlDate(value);
}
public java.sql.Timestamp getTimestamp(int index) {
Object value = get(index);
return castToTimestamp(value);
}
@Override
public Object clone() {
return new JSONArray(new ArrayList<Object>(list));
}
public boolean equals(Object obj) {
return this.list.equals(obj);
}
public int hashCode() {
return this.list.hashCode();
}
}