/** {@inheritDoc} */
  @Override
  public void accumulate(NamedList stv) {
    if (computeCount) {
      count += (Long) stv.get("count");
    }
    if (computeMissing) {
      missing += (Long) stv.get("missing");
    }
    if (computeCalcDistinct) {
      distinctValues.addAll((Collection<T>) stv.get("distinctValues"));
      countDistinct = distinctValues.size();
    }

    if (computeMinOrMax) {
      updateMinMax((T) stv.get("min"), (T) stv.get("max"));
    }

    if (computeCardinality) {
      byte[] data = (byte[]) stv.get("cardinality");
      HLL other = HLL.fromBytes(data);
      if (hll.getType().equals(HLLType.EMPTY)) {
        // The HLL.union method goes out of it's way not to modify the "other" HLL.
        // Which means in the case of merging into an "EMPTY" HLL (garunteed to happen at
        // least once in every coordination of shard requests) it always clones all
        // of the internal storage -- but since we're going to throw "other" away after
        // the merge, this just means a short term doubling of RAM that we can skip.
        hll = other;
      } else {
        hll.union(other);
      }
    }

    updateTypeSpecificStats(stv);

    NamedList f = (NamedList) stv.get(FACETS);
    if (f == null) {
      return;
    }

    for (int i = 0; i < f.size(); i++) {
      String field = f.getName(i);
      NamedList vals = (NamedList) f.getVal(i);
      Map<String, StatsValues> addTo = facets.get(field);
      if (addTo == null) {
        addTo = new HashMap<>();
        facets.put(field, addTo);
      }
      for (int j = 0; j < vals.size(); j++) {
        String val = vals.getName(j);
        StatsValues vvals = addTo.get(val);
        if (vvals == null) {
          vvals = StatsValuesFactory.createStatsValues(statsField);
          addTo.put(val, vvals);
        }
        vvals.accumulate((NamedList) vals.getVal(j));
      }
    }
  }
 public void accumulate(T value, int count) {
   this.count += count;
   if (calcDistinct) {
     distinctValues.add(value);
     countDistinct = distinctValues.size();
   }
   updateMinMax(value, value);
   updateTypeSpecificStats(value, count);
 }
  public void accumulate(T value, int count) {
    assert null != value : "Can't accumulate null";

    if (computeCount) {
      this.count += count;
    }
    if (computeCalcDistinct) {
      distinctValues.add(value);
      countDistinct = distinctValues.size();
    }
    if (computeMinOrMax) {
      updateMinMax(value, value);
    }
    if (computeCardinality) {
      if (null == hasher) {
        assert value instanceof Number : "pre-hashed value support only works with numeric longs";
        hll.addRaw(((Number) value).longValue());
      } else {
        hll.addRaw(hash(value));
      }
    }
    updateTypeSpecificStats(value, count);
  }
  /** {@inheritDoc} */
  @Override
  public void accumulate(NamedList stv) {
    count += (Long) stv.get("count");
    missing += (Long) stv.get("missing");
    if (calcDistinct) {
      distinctValues.addAll((Collection<T>) stv.get("distinctValues"));
      countDistinct = distinctValues.size();
    }

    updateMinMax((T) stv.get("min"), (T) stv.get("max"));
    updateTypeSpecificStats(stv);

    NamedList f = (NamedList) stv.get(FACETS);
    if (f == null) {
      return;
    }

    for (int i = 0; i < f.size(); i++) {
      String field = f.getName(i);
      NamedList vals = (NamedList) f.getVal(i);
      Map<String, StatsValues> addTo = facets.get(field);
      if (addTo == null) {
        addTo = new HashMap<String, StatsValues>();
        facets.put(field, addTo);
      }
      for (int j = 0; j < vals.size(); j++) {
        String val = vals.getName(j);
        StatsValues vvals = addTo.get(val);
        if (vvals == null) {
          vvals = StatsValuesFactory.createStatsValues(qcontext, sf, calcDistinct);
          addTo.put(val, vvals);
        }
        vvals.accumulate((NamedList) vals.getVal(j));
      }
    }
  }