private Map<Integer, List<Long>> splitUidsByBatch(List<Long> uids, int batchSize) {
Map<Integer, List<Long>> batchMap = new HashMap<Integer, List<Long>>(); int batch = uids.size() / batchSize; int batchRemainder = uids.size() % batchSize; for (int i = 0; i <= batch; i++) { int fromIndex = i * batchSize; int toIndex; if (i < batch) { toIndex = (i + 1) * batchSize; } else { toIndex = i * batchSize + batchRemainder; } List<Long> subUidList = uids.subList(fromIndex, toIndex); if (subUidList != null && subUidList.size() != 0) { batchMap.put(i, subUidList); } } return batchMap; }