Custom JSONList implementation based on ArrayList to replace com.alibaba.fastjson.JSONList Maintains same API as fastjson but uses standard Java List implementation @author Lemon
| 12 | * @author Lemon |
| 13 | */ |
| 14 | public interface JSONList<M extends Map<String, Object>, L extends List<Object>> extends List<Object> { |
| 15 | public static final String TAG = "JSONList"; |
| 16 | |
| 17 | ///** |
| 18 | // * Create an empty JSONList |
| 19 | // */ |
| 20 | //default JSONList() { |
| 21 | // super(); |
| 22 | //} |
| 23 | // |
| 24 | //private int initialCapacity = 10; |
| 25 | ///** |
| 26 | // * Create a JSONList with initial capacity |
| 27 | // * @param initialCapacity the initial capacity |
| 28 | // */ |
| 29 | //default JSONList(int initialCapacity) { |
| 30 | // super(initialCapacity); |
| 31 | //} |
| 32 | // |
| 33 | ///** |
| 34 | // * Create a JSONList from a Collection |
| 35 | // * @param collection the collection to copy from |
| 36 | // */ |
| 37 | //default JSONList(Collection<?> collection) { |
| 38 | // super(collection); |
| 39 | //} |
| 40 | // |
| 41 | ///** |
| 42 | // * Create a JSONList from a JSON string |
| 43 | // * @param json JSON string |
| 44 | // */ |
| 45 | //default JSONList(String json) { |
| 46 | // this(); |
| 47 | // List<Object> list = JSON.parseArray(json); |
| 48 | // if (list != null) { |
| 49 | // addAll(list); |
| 50 | // } |
| 51 | //} |
| 52 | // |
| 53 | /** |
| 54 | * Get a JSONMap at the specified index |
| 55 | * @param index the index |
| 56 | * @return the JSONMap or null if not a JSONMap |
| 57 | */ |
| 58 | default M getJSONObject(int index) { |
| 59 | if (index < 0 || index >= size()) { |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | Object obj = get(index); |
| 64 | if (obj instanceof Map<?, ?>) { |
| 65 | return JSON.createJSONObject((Map<? extends String, ?>) obj); |
| 66 | } |
| 67 | |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected