| 830 | } |
| 831 | |
| 832 | private static List<JSONArray> partition(JSONArray jarray) throws JSONException { |
| 833 | Log.i("Cloud batch size=" + jarray.length() + "/" + BATCH_SIZE); |
| 834 | if (jarray.length() <= BATCH_SIZE) |
| 835 | return Arrays.asList(jarray); |
| 836 | |
| 837 | int count = 0; |
| 838 | List<JSONArray> jpartitions = new ArrayList<>(); |
| 839 | for (int i = 0; i < jarray.length(); i += BATCH_SIZE) { |
| 840 | JSONArray jpartition = new JSONArray(); |
| 841 | for (int j = 0; j < BATCH_SIZE && i + j < jarray.length(); j++) { |
| 842 | count++; |
| 843 | jpartition.put(jarray.get(i + j)); |
| 844 | } |
| 845 | jpartitions.add(jpartition); |
| 846 | } |
| 847 | |
| 848 | Log.i("Cloud partitions=" + jpartitions.size()); |
| 849 | |
| 850 | if (count != jarray.length()) |
| 851 | throw new IllegalArgumentException("Partition error size=" + count + "/" + jarray.length()); |
| 852 | |
| 853 | return jpartitions; |
| 854 | } |
| 855 | } |