class AverageState implements Comparable<AverageState> {

        private double sum = 0;
        private long count = 0;
        private final KahanSummationForDouble kahanSummationForDouble = new KahanSummationForDouble();

        public Double value() {
            if (count > 0) {
                return sum / count;
            } else {
                return null;
            }
        }

        public void addNumber(double number, boolean isIntegral) {
            this.sum = isIntegral ? this.sum + number : kahanSummationForDouble.sum(this.sum, number);
            this.count++;
        }

        public void removeNumber(double number, boolean isIntegral) {
            this.sum = isIntegral ? this.sum - number : kahanSummationForDouble.sum(this.sum, -number);
            this.count--;
        }

        public void reduce(@NotNull AverageState other, boolean isIntegral) {
            this.count += other.count;
            this.sum = isIntegral ? this.sum + other.sum : kahanSummationForDouble.sum(this.sum, other.sum);
        }

        @Override
        public int compareTo(AverageState o) {<FILL_FUNCTION_BODY>}

        @Override
        public String toString() {
            return "sum: " + sum + " count: " + count;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            AverageState that = (AverageState) o;
            return Objects.equals(that.value(), value());
        }

        @Override
        public int hashCode() {
            return Objects.hash(value());
        }
    }

            if (o == null) {
                return 1;
            } else {
                int compare = Double.compare(sum, o.sum);
                if (compare == 0) {
                    return Long.compare(count, o.count);
                }
                return compare;
            }
        
<methods>public non-sealed void <init>() ,public DocValueAggregator<?> getDocValueAggregator(io.crate.expression.reference.doc.lucene.LuceneReferenceResolver, List<io.crate.metadata.Reference>, io.crate.metadata.doc.DocTableInfo, List<Literal<?>>) ,public boolean isRemovableCumulative() ,public transient abstract io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState iterate(io.crate.data.breaker.RamAccounting, io.crate.memory.MemoryManager, io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState, Input<?>[]) throws org.elasticsearch.common.breaker.CircuitBreakingException,public abstract io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState newState(io.crate.data.breaker.RamAccounting, org.elasticsearch.Version, org.elasticsearch.Version, io.crate.memory.MemoryManager) ,public AggregationFunction<?,java.lang.Double> optimizeForExecutionAsWindowFunction() ,public abstract DataType<?> partialType() ,public abstract io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState reduce(io.crate.data.breaker.RamAccounting, io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState, io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState) ,public io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState removeFromAggregatedState(io.crate.data.breaker.RamAccounting, io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState, Input<?>[]) ,public abstract java.lang.Double terminatePartial(io.crate.data.breaker.RamAccounting, io.crate.execution.engine.aggregation.impl.average.AverageAggregation.AverageState) <variables>