@Test public void testFromLink() { PageRequest pl = PageRequest .firstPage(5) .nextRequest("exampleKey", "65f996f8b1024f00a81ef10264459a1d") .page(1).build(); String link = pl.asLink(); assertEquals(pl, PageRequest.fromLink(link)); }
public static PageRequest fromLink(String link) { try { JsonNode n = MAPPER.readTree(new ByteArrayInputStream(Base64 .decode(link, Base64.URL_SAFE))); JsonNode keyNode = n.get(NEXT_KEY_FIELD_NAME); JsonNode docIdNode = n.get(NEXT_DOCID_FIELD_NAME); String docId = null; if (docIdNode != null) { docId = docIdNode.asText(); } KeyIdPair keyIdPair; if (keyNode != null || docId != null) { keyIdPair = new KeyIdPair(keyNode, docId); } else { keyIdPair = null; } int pageSize = n.get(PAGE_SIZE_FIELD_NAME).intValue(); boolean back = n.get(BACK_FIELD_NAME).asInt() == 1; int page = n.get(PAGE_FIELD_NAME).asInt(); return new Builder() .nextKey(keyIdPair) .pageSize(pageSize) .back(back) .page(page) .build(); } catch (Exception e) { throw Exceptions.propagate(e); } }
PageRequest { public static PageRequest fromLink(String link) { try { JsonNode n = MAPPER.readTree(new ByteArrayInputStream(Base64 .decode(link, Base64.URL_SAFE))); JsonNode keyNode = n.get(NEXT_KEY_FIELD_NAME); JsonNode docIdNode = n.get(NEXT_DOCID_FIELD_NAME); String docId = null; if (docIdNode != null) { docId = docIdNode.asText(); } KeyIdPair keyIdPair; if (keyNode != null || docId != null) { keyIdPair = new KeyIdPair(keyNode, docId); } else { keyIdPair = null; } int pageSize = n.get(PAGE_SIZE_FIELD_NAME).intValue(); boolean back = n.get(BACK_FIELD_NAME).asInt() == 1; int page = n.get(PAGE_FIELD_NAME).asInt(); return new Builder() .nextKey(keyIdPair) .pageSize(pageSize) .back(back) .page(page) .build(); } catch (Exception e) { throw Exceptions.propagate(e); } } }
PageRequest { public static PageRequest fromLink(String link) { try { JsonNode n = MAPPER.readTree(new ByteArrayInputStream(Base64 .decode(link, Base64.URL_SAFE))); JsonNode keyNode = n.get(NEXT_KEY_FIELD_NAME); JsonNode docIdNode = n.get(NEXT_DOCID_FIELD_NAME); String docId = null; if (docIdNode != null) { docId = docIdNode.asText(); } KeyIdPair keyIdPair; if (keyNode != null || docId != null) { keyIdPair = new KeyIdPair(keyNode, docId); } else { keyIdPair = null; } int pageSize = n.get(PAGE_SIZE_FIELD_NAME).intValue(); boolean back = n.get(BACK_FIELD_NAME).asInt() == 1; int page = n.get(PAGE_FIELD_NAME).asInt(); return new Builder() .nextKey(keyIdPair) .pageSize(pageSize) .back(back) .page(page) .build(); } catch (Exception e) { throw Exceptions.propagate(e); } } private  PageRequest(Builder b); }
PageRequest { public static PageRequest fromLink(String link) { try { JsonNode n = MAPPER.readTree(new ByteArrayInputStream(Base64 .decode(link, Base64.URL_SAFE))); JsonNode keyNode = n.get(NEXT_KEY_FIELD_NAME); JsonNode docIdNode = n.get(NEXT_DOCID_FIELD_NAME); String docId = null; if (docIdNode != null) { docId = docIdNode.asText(); } KeyIdPair keyIdPair; if (keyNode != null || docId != null) { keyIdPair = new KeyIdPair(keyNode, docId); } else { keyIdPair = null; } int pageSize = n.get(PAGE_SIZE_FIELD_NAME).intValue(); boolean back = n.get(BACK_FIELD_NAME).asInt() == 1; int page = n.get(PAGE_FIELD_NAME).asInt(); return new Builder() .nextKey(keyIdPair) .pageSize(pageSize) .back(back) .page(page) .build(); } catch (Exception e) { throw Exceptions.propagate(e); } } private  PageRequest(Builder b); static ViewQuery applyPagingParameters(ViewQuery q, PageRequest pr); int getPageNo(); static PageRequest firstPage(int pageSize); PageRequest.Builder nextRequest(Object nextStartKey,
			String nextStartDocId); static PageRequest fromLink(String link); String asLink(); JsonNode asJson(); int getPageSize(); Object getStartKey(); String getStartKeyDocId(); PageRequest getPreviousPageRequest(); boolean isBack(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }
PageRequest { public static PageRequest fromLink(String link) { try { JsonNode n = MAPPER.readTree(new ByteArrayInputStream(Base64 .decode(link, Base64.URL_SAFE))); JsonNode keyNode = n.get(NEXT_KEY_FIELD_NAME); JsonNode docIdNode = n.get(NEXT_DOCID_FIELD_NAME); String docId = null; if (docIdNode != null) { docId = docIdNode.asText(); } KeyIdPair keyIdPair; if (keyNode != null || docId != null) { keyIdPair = new KeyIdPair(keyNode, docId); } else { keyIdPair = null; } int pageSize = n.get(PAGE_SIZE_FIELD_NAME).intValue(); boolean back = n.get(BACK_FIELD_NAME).asInt() == 1; int page = n.get(PAGE_FIELD_NAME).asInt(); return new Builder() .nextKey(keyIdPair) .pageSize(pageSize) .back(back) .page(page) .build(); } catch (Exception e) { throw Exceptions.propagate(e); } } private  PageRequest(Builder b); static ViewQuery applyPagingParameters(ViewQuery q, PageRequest pr); int getPageNo(); static PageRequest firstPage(int pageSize); PageRequest.Builder nextRequest(Object nextStartKey,
			String nextStartDocId); static PageRequest fromLink(String link); String asLink(); JsonNode asJson(); int getPageSize(); Object getStartKey(); String getStartKeyDocId(); PageRequest getPreviousPageRequest(); boolean isBack(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }