QueryServiceUtil { @SuppressWarnings("unchecked") public static <T> List<T> findItems(QueryService<T, ?> s, QueryExpr itemExpr, int maxNumOfItems) { QueryParams qp = new QueryParams(); qp.setQueryExpression(itemExpr); if (s instanceof PageQueryService) { List<T> items = ((PageQueryService<T, ?>) s).getItems(qp, 0, maxNumOfItems); return items; } else if (s instanceof IdQueryService) { IdQueryService<T, Object> qs = (IdQueryService<T, Object>) s; List<Object> ids = qs.findIds(qp, 0, maxNumOfItems); List<T> items = qs.getItems(ids); return items; } else { throw new RuntimeException("Unsupported service type found: " + s); } } private  QueryServiceUtil(); static T getItem(QueryService<T, ?> s, QueryExpr itemExpr); static T findItem(QueryService<T, ?> s, QueryExpr itemExpr); @SuppressWarnings("unchecked") static List<T> findItems(QueryService<T, ?> s, QueryExpr itemExpr, int maxNumOfItems); static T findEqItem(QueryService<T, ?> s, QueryAttr qAttr, Object value);  }
@Test public void testFindAllItemsOnIdQueryService() { assertEquals("[0, 1, 2, 3]", QueryServiceUtil.findItems(idQueryService, null, 100).toString()); }
@Test public void testFindAllItemsOnPageQueryService() { assertEquals("[0, 1, 2, 3]", QueryServiceUtil.findItems(pageQueryService, null, 100).toString()); }