Patch implements a DocValuesStatsCollector. Note some key design decisions:
A DocValuesStats is responsible for providing the specific DocValuesIterator for a LeafReaderContext. It then accumulates the value, computes missing and other statistics. It computes missing and count, leaving min and max to the actual implementation. Also, this stats does not define a mean, as at least for now I'm not sure how the mean value of a SortedSetDocValues is defined.
An abstract NumericDocValuesStats implementation for single-numeric DV fields, which also adds a mean statistic, with two concrete implementations: LongNumericDocValuesStats and DoubleNumericDocValuesStats.
This hierarchy should allow us to add further statistics for SortedSet and SortedNumeric DV fields. I did not implement them yet, as I'm not sure about some of the statistics (e.g. should the mean stat of a SortedNumeric be the mean across all values, or the minimum per document or ...). Let's discuss that separately.
Also, note that I had to make DocValuesIterator public in order to declare it in this collector.
If you're OK with the design and implementation, I want to separate DovValuesStats to its own file, for clarity. I did not do it yet though.