@Test public void testDoSearch() { WPage page = new WPage(); int total = 10; page.setSize(3); WPageIterator<Integer> wpIterator = new WPageIterator<Integer>(page) { @Override public void doSearch() { update(ValuePlus.lst(1, 2, 3), total); } }; assertTrue(wpIterator.hasNext()); assertEquals(1, wpIterator.getPage().getPageNo()); assertEquals(1, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(1, wpIterator.getPage().getPageNo()); assertEquals(2, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(1, wpIterator.getPage().getPageNo()); assertEquals(3, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(2, wpIterator.getPage().getPageNo()); assertEquals(1, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(2, wpIterator.getPage().getPageNo()); assertEquals(2, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(2, wpIterator.getPage().getPageNo()); assertEquals(3, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(3, wpIterator.getPage().getPageNo()); assertEquals(1, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(3, wpIterator.getPage().getPageNo()); assertEquals(2, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(3, wpIterator.getPage().getPageNo()); assertEquals(3, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertTrue(wpIterator.hasNext()); assertEquals(4, wpIterator.getPage().getPageNo()); assertEquals(1, wpIterator.next().intValue()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertFalse(wpIterator.hasNext()); assertEquals(4, wpIterator.getPage().getPageNo()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); assertFalse(wpIterator.hasNext()); assertEquals(4, wpIterator.getPage().getPageNo()); assertEquals(total, wpIterator.getPage().getTotal().intValue()); try { page.setFrom(0); page.setSize(20); int total2 = 10; wpIterator = new WPageIterator<Integer>(page) { @Override public void doSearch() { update(ValuePlus.lst(1, 2, 3), total2); } }; int index = 0; while (wpIterator.hasNext()) { assertEquals(index++, wpIterator.getPage().getFrom()); Integer item = wpIterator.next(); LOG.info("---------------------------------------------" + item + "->" + wpIterator.getPage().toText()); assertNotNull(item); if (index % 3 == 1) { assertEquals(1, item.intValue()); } else if (index % 3 == 2) { assertEquals(2, item.intValue()); } else if (index % 3 == 0) { assertEquals(3, item.intValue()); } else { fail("OMG!"); } assertEquals(index, wpIterator.getPage().getFrom()); assertEquals(total2, wpIterator.getPage().getTotal().intValue()); } } catch (Exception e) { LOG.error(e.getMessage(), e); fail(e.getMessage()); } }
public abstract void doSearch();
WPageIterator implements Iterator<T> { public abstract void doSearch(); }
WPageIterator implements Iterator<T> { public abstract void doSearch(); WPageIterator();  WPageIterator(WPage page); }
WPageIterator implements Iterator<T> { public abstract void doSearch(); WPageIterator();  WPageIterator(WPage page); WPage getPage(); void reset(WPage page); @Override boolean hasNext(); @Override T next(); void update(List<T> data, int total); abstract void doSearch(); }
WPageIterator implements Iterator<T> { public abstract void doSearch(); WPageIterator();  WPageIterator(WPage page); WPage getPage(); void reset(WPage page); @Override boolean hasNext(); @Override T next(); void update(List<T> data, int total); abstract void doSearch();  }