@Test public void testToJson() { long[] items = new long[10]; for (int i = 0; i < items.length; i++) { items[i] = (2300000000000000L + 101) + (items.length - 1 - i); } ArrayUtil.reverse(items); ApiLogger.debug(Arrays.toString(items)); int count = 20; int page = 1; long[] expecteds = Arrays.copyOf(items, items.length); ArrayUtil.reverse(expecteds); PaginationParam paginationParam = new PaginationParam.Builder().count(count).page(page).build(); PageWrapper<long[]> pageWrapper = PageWrapperUtil.paginationAndReverse(items, paginationParam); ApiLogger.debug(paginationParam + ", " + PageWrapperUtil.toJson(pageWrapper, "ids", pageWrapper.result)); }
public static <T> String toJson(PageWrapper<T> pageWrapper, String name, long[] values) { JsonBuilder json = new JsonBuilder(); if (values == null) { json.append(name, "[]"); } else { json.appendStrArr(name, values); } appendJson(json, pageWrapper); json.flip(); return json.toString(); }
PageWrapperUtil { public static <T> String toJson(PageWrapper<T> pageWrapper, String name, long[] values) { JsonBuilder json = new JsonBuilder(); if (values == null) { json.append(name, "[]"); } else { json.appendStrArr(name, values); } appendJson(json, pageWrapper); json.flip(); return json.toString(); } }
PageWrapperUtil { public static <T> String toJson(PageWrapper<T> pageWrapper, String name, long[] values) { JsonBuilder json = new JsonBuilder(); if (values == null) { json.append(name, "[]"); } else { json.appendStrArr(name, values); } appendJson(json, pageWrapper); json.flip(); return json.toString(); }  }
PageWrapperUtil { public static <T> String toJson(PageWrapper<T> pageWrapper, String name, long[] values) { JsonBuilder json = new JsonBuilder(); if (values == null) { json.append(name, "[]"); } else { json.appendStrArr(name, values); } appendJson(json, pageWrapper); json.flip(); return json.toString(); }  static String toJson(PageWrapper<T> pageWrapper, String name, long[] values); static String toJson(PageWrapper<T> pageWrapper, String name, Jsonable[] values); static PageWrapper<long[]> wrap(long[] ids, int count); static int getPageOffset(int page, int count); static PageWrapper<long[]> paginationAndReverse(long[] ids, PaginationParam paginationParam); static PageWrapper<long[]> paginationAndReverse(long[] ids, int idsLen, long sinceId, long maxId, int count, int page); static int[] calculatePaginationByReverse(long[] ids, int idsLen, long sinceId, long maxId, int count, int page); static void calculateCursorByReverse(PageWrapper<T> wrapper, long[] ids, int offset, int limit, int count); }
PageWrapperUtil { public static <T> String toJson(PageWrapper<T> pageWrapper, String name, long[] values) { JsonBuilder json = new JsonBuilder(); if (values == null) { json.append(name, "[]"); } else { json.appendStrArr(name, values); } appendJson(json, pageWrapper); json.flip(); return json.toString(); }  static String toJson(PageWrapper<T> pageWrapper, String name, long[] values); static String toJson(PageWrapper<T> pageWrapper, String name, Jsonable[] values); static PageWrapper<long[]> wrap(long[] ids, int count); static int getPageOffset(int page, int count); static PageWrapper<long[]> paginationAndReverse(long[] ids, PaginationParam paginationParam); static PageWrapper<long[]> paginationAndReverse(long[] ids, int idsLen, long sinceId, long maxId, int count, int page); static int[] calculatePaginationByReverse(long[] ids, int idsLen, long sinceId, long maxId, int count, int page); static void calculateCursorByReverse(PageWrapper<T> wrapper, long[] ids, int offset, int limit, int count);  }