123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package com.luticate.utils.dbo;
-
- import org.json.JSONArray;
- import org.json.JSONObject;
-
- import java.util.HashMap;
- import java.util.List;
- import java.util.Vector;
-
- /**
- *
- * Created by robin on 11/27/15.
- */
- public class LuPaginatedDbo<T extends LuDbo> extends LuDbo {
-
- private transient Class<T> _clazz;
-
- private List<T> _data = new Vector<>();
-
- private int _count;
-
- public LuPaginatedDbo(Class<T> clazz)
- {
- _clazz = clazz;
- }
-
- public List<T> getData() {
- return _data;
- }
-
- public void setData(List<T> data) {
- _data = data;
- }
-
- public int getCount() {
- return _count;
- }
-
- public void setCount(int count) {
- _count = count;
- }
-
- @Override
- public void fromJson(JSONObject json) throws Exception {
- _count = json.getInt("count");
- JSONArray array = json.getJSONArray("data");
-
- for (int i = 0; i < array.length(); ++i) {
- T dbo = _clazz.newInstance();
- dbo.fromJson(array.getJSONObject(i));
- _data.add(dbo);
- }
- }
-
- @Override
- public HashMap<String, Object> toArray() {
- HashMap<String, Object> array = new HashMap<>();
- array.put("count", _count);
- Vector<HashMap<String, Object>> data = new Vector<>();
- for (T value : _data) {
- data.add(value.toArray());
- }
- array.put("data", data);
- return array;
- }
- }
|