FacetFieldValuesProvider extends SortableDataProvider<FacetField.Count, FieldValuesOrder> implements ListProvider<FacetField.Count> { @Override public Iterator<FacetField.Count> iterator(long first, long count) { return getList().listIterator((int) first); } FacetFieldValuesProvider(IModel<FacetField> model, FieldValueConverterProvider fieldValueConverterProvider);  FacetFieldValuesProvider(IModel<FacetField> model, Collection<String> lowPriorityValues, FieldValueConverterProvider fieldValueConverterProvider);  FacetFieldValuesProvider(IModel<FacetField> model, int max, Collection<String> lowPriorityValues, FieldValueConverterProvider fieldValueConverterProvider);  FacetFieldValuesProvider(IModel<FacetField> model, int max, SortParam<FieldValuesOrder> sort, FieldValueConverterProvider fieldValueConverterProvider);  FacetFieldValuesProvider(IModel<FacetField> model, int max, Collection<String> lowPriorityValues, SortParam<FieldValuesOrder> sort, FieldValueConverterProvider fieldValueConverterProvider); @Override Iterator<FacetField.Count> iterator(long first, long count); @Override List<FacetField.Count> getList(); @Override long size(); @Override IModel<FacetField.Count> model(FacetField.Count object); @Override void detach();  }
@Test public void testIteratorCountOrder() { final FacetFieldValuesProvider instance = new FacetFieldValuesProvider(Model.of(facetField), 10, LOW_PRIORITY_VALUES, new SortParam<FieldValuesOrder>(FieldValuesOrder.COUNT, true), valueConverterProvider); long first = 0; long count = 100; final Iterator<? extends FacetField.Count> result = instance.iterator(first, count); assertTrue(result.hasNext()); FacetField.Count valueCount = result.next(); assertEquals(101, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(102, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(103, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(104, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(500, valueCount.getCount()); assertFalse(result.hasNext()); }
@Test public void testIteratorCountOrderDescending() { final FacetFieldValuesProvider instance = new FacetFieldValuesProvider(Model.of(facetField), 10, LOW_PRIORITY_VALUES, new SortParam<FieldValuesOrder>(FieldValuesOrder.COUNT, false), valueConverterProvider); long first = 0; long count = 100; final Iterator<? extends FacetField.Count> result = instance.iterator(first, count); assertTrue(result.hasNext()); FacetField.Count valueCount = result.next(); assertEquals(104, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(103, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(102, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(101, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(500, valueCount.getCount()); assertFalse(result.hasNext()); }
@Test public void testIteratorCountOrderDefaultPriority() { final FacetFieldValuesProvider instance = new FacetFieldValuesProvider(Model.of(facetField), 10, new SortParam<FieldValuesOrder>(FieldValuesOrder.COUNT, false), valueConverterProvider); long first = 0; long count = 100; final Iterator<? extends FacetField.Count> result = instance.iterator(first, count); assertTrue(result.hasNext()); FacetField.Count valueCount = result.next(); assertEquals(500, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(104, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(103, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(102, valueCount.getCount()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals(101, valueCount.getCount()); assertFalse(result.hasNext()); }
@Test public void testIteratorNameOrderDescending() { final FacetFieldValuesProvider instance = new FacetFieldValuesProvider(Model.of(facetField), 10, LOW_PRIORITY_VALUES, new SortParam<FieldValuesOrder>(FieldValuesOrder.NAME, false), valueConverterProvider); final long first = 0; final long count = 100; final Iterator<? extends FacetField.Count> result = instance.iterator(first, count); assertTrue(result.hasNext()); FacetField.Count valueCount = result.next(); assertEquals("Xlow priority", valueCount.getName()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals("third value", valueCount.getName()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals("second value*", valueCount.getName()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals("FOURTH value", valueCount.getName()); assertTrue(result.hasNext()); valueCount = result.next(); assertEquals("first value", valueCount.getName()); assertFalse(result.hasNext()); }
@Test public void testIteratorNameOrderCollation() { facetField = new FacetField("field"); facetField.add("a value", 1); facetField.add("some other value", 1); facetField.add("जात", 1); facetField.add("Etwas anderes", 1); facetField.add("één nederlandse waarde", 1); final FacetFieldValuesProvider instance = new FacetFieldValuesProvider(Model.of(facetField), 10, LOW_PRIORITY_VALUES, new SortParam<FieldValuesOrder>(FieldValuesOrder.NAME, true), valueConverterProvider) { @Override protected Locale getLocale() { return Locale.ENGLISH; } }; final long first = 0; final long count = 100; final Iterator<? extends FacetField.Count> result = instance.iterator(first, count); assertTrue(result.hasNext()); assertEquals("a value", result.next().getName()); assertTrue(result.hasNext()); assertEquals("één nederlandse waarde", result.next().getName()); assertTrue(result.hasNext()); assertEquals("Etwas anderes", result.next().getName()); assertTrue(result.hasNext()); assertEquals("some other value", result.next().getName()); assertTrue(result.hasNext()); assertEquals("जात", result.next().getName()); assertFalse(result.hasNext()); }
@Test public void testIteratorOffset() { final FacetFieldValuesProvider instance = new FacetFieldValuesProvider(Model.of(facetField), 10, LOW_PRIORITY_VALUES, new SortParam<FieldValuesOrder>(FieldValuesOrder.COUNT, true), valueConverterProvider); final long first = 2; final long count = 100; final Iterator<? extends FacetField.Count> result = instance.iterator(first, count); assertTrue(result.hasNext()); FacetField.Count valueCount = result.next(); assertEquals(103, valueCount.getCount()); }