public static Event[] all() { ArrayList<HashMap<String, Object>> event_arr = modelCollection.all("event"); // get all postures ArrayList<Event> collection = new ArrayList<>(); for (HashMap<String, Object> item : event_arr) { Event model = new Event(); model.id = (int) item.get("id"); model.createdDate = (Date) item.get("createdDate"); model.time = (Date) item.get("time"); String[] list = model.postureList.split(","); Converter converter = Converter.getInstance(); for (int i = 0; i < list.length; i++) { model.postures.add(Posture.find(converter.toInt(list[i]))); } model.modifiedDate = (Date) item.get("modifiedDate"); collection.add(model); } return collection.toArray(new Event[collection.size()]); }
public static Event find(int id) { HashMap<String, Object> event_map = modelCollection.find("event", id); if (event_map == null) { return null; } Event event = new Event(); // create event and return its value event.id = (int) event_map.get("id"); event.createdDate = (Date) event_map.get("createdDate"); event.time = (Date) event_map.get("time"); event.postureList = (String) event_map.get("postureList"); String[] list = event.postureList.split(","); Converter converter = Converter.getInstance(); for (int i = 0; i < list.length; i++) { event.postures.add(Posture.find(converter.toInt(list[i]))); } event.modifiedDate = (Date) event_map.get("modifiedDate"); return event; }
public static Event[] where(String colName, String operator, String value) { ArrayList<HashMap<String, Object>> event_arr = modelCollection.where("event", colName, operator, value); ArrayList<Event> collection = new ArrayList<>(); // create array of event and return its value for (HashMap<String, Object> item : event_arr) { Event model = new Event(); model.id = (int) item.get("id"); model.createdDate = (Date) item.get("createdDate"); model.time = (Date) item.get("time"); String[] list = model.postureList.split(","); Converter converter = Converter.getInstance(); for (int i = 0; i < list.length; i++) { model.postures.add(Posture.find(converter.toInt(list[i]))); } model.modifiedDate = (Date) item.get("modifiedDate"); collection.add(model); } return collection.toArray(new Event[collection.size()]); }