### Question:
NativeDistinctValuesProgressor extends NativeIndexProgressor<KEY,VALUE> { @Override public boolean next() { try { while ( seeker.next() ) { KEY key = seeker.get().key(); if ( first ) { first = false; countForCurrentValue = 1; layout.copyKey( key, prev ); } else if ( comparator.compare( prev, key ) == 0 ) { countForCurrentValue++; } else { boolean accepted = client.acceptNode( countForCurrentValue, extractValues( prev ) ); countForCurrentValue = 1; layout.copyKey( key, prev ); if ( accepted ) { return true; } } } boolean finalResult = !first && !last && client.acceptNode( countForCurrentValue, extractValues( prev ) ); last = true; return finalResult; } catch ( IOException e ) { throw new UncheckedIOException( e ); } } NativeDistinctValuesProgressor( RawCursor<Hit<KEY,VALUE>,IOException> seeker, NodeValueClient client,
            Collection<RawCursor<Hit<KEY,VALUE>,IOException>> toRemoveFromOnClose, IndexLayout<KEY,VALUE> layout,
            Comparator<KEY> comparator ); @Override boolean next();  }### Answer:
@Test public void shouldCountDistinctValues() { Value[] strings = generateRandomStrings(); DataCursor source = new DataCursor( asHitData( strings ) ); GatheringNodeValueClient client = new GatheringNodeValueClient(); NativeDistinctValuesProgressor<StringIndexKey,NativeIndexValue> progressor = new NativeDistinctValuesProgressor<>( source, client, new ArrayList<>(), layout, layout::compareValue ); client.initialize( null, progressor, new IndexQuery[0], IndexOrder.NONE, true ); Map<Value,MutableInt> expectedCounts = asDistinctCounts( strings ); int uniqueValues = 0; int nonUniqueValues = 0; while ( progressor.next() ) { Value string = client.values[0]; MutableInt expectedCount = expectedCounts.remove( string ); assertNotNull( expectedCount ); assertEquals( expectedCount.intValue(), client.reference ); if ( expectedCount.intValue() > 1 ) { nonUniqueValues++; } else { uniqueValues++; } } assertTrue( expectedCounts.isEmpty() ); assertTrue( uniqueValues > 0 ); assertTrue( nonUniqueValues > 0 ); }