what-the-bank/sources/com/google/common/math/Stats.java

207 lines
7.7 KiB
Java

package com.google.common.math;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Doubles;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Iterator;
/* loaded from: classes2.dex */
public final class Stats implements Serializable {
static final int BYTES = 40;
private static final long serialVersionUID = 0;
private final long count;
private final double max;
private final double mean;
private final double min;
private final double sumOfSquaresOfDeltas;
/* JADX INFO: Access modifiers changed from: package-private */
public Stats(long j, double d, double d2, double d3, double d4) {
this.count = j;
this.mean = d;
this.sumOfSquaresOfDeltas = d2;
this.min = d3;
this.max = d4;
}
public static Stats of(Iterable<? extends Number> iterable) {
StatsAccumulator statsAccumulator = new StatsAccumulator();
statsAccumulator.addAll(iterable);
return statsAccumulator.snapshot();
}
public static Stats of(Iterator<? extends Number> it) {
StatsAccumulator statsAccumulator = new StatsAccumulator();
statsAccumulator.addAll(it);
return statsAccumulator.snapshot();
}
public static Stats of(double... dArr) {
StatsAccumulator statsAccumulator = new StatsAccumulator();
statsAccumulator.addAll(dArr);
return statsAccumulator.snapshot();
}
public static Stats of(int... iArr) {
StatsAccumulator statsAccumulator = new StatsAccumulator();
statsAccumulator.addAll(iArr);
return statsAccumulator.snapshot();
}
public static Stats of(long... jArr) {
StatsAccumulator statsAccumulator = new StatsAccumulator();
statsAccumulator.addAll(jArr);
return statsAccumulator.snapshot();
}
public final double mean() {
Preconditions.checkState(this.count != 0);
return this.mean;
}
public final double populationVariance() {
Preconditions.checkState(this.count > 0);
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
return Double.NaN;
}
if (this.count == 1) {
return 0.0d;
}
return DoubleUtils.ensureNonNegative(this.sumOfSquaresOfDeltas) / count();
}
public final double populationStandardDeviation() {
return Math.sqrt(populationVariance());
}
public final double sampleVariance() {
Preconditions.checkState(this.count > 1);
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
return Double.NaN;
}
return DoubleUtils.ensureNonNegative(this.sumOfSquaresOfDeltas) / (this.count - 1);
}
public final double sampleStandardDeviation() {
return Math.sqrt(sampleVariance());
}
public final double min() {
Preconditions.checkState(this.count != 0);
return this.min;
}
public final double max() {
Preconditions.checkState(this.count != 0);
return this.max;
}
public final boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Stats stats = (Stats) obj;
return this.count == stats.count && Double.doubleToLongBits(this.mean) == Double.doubleToLongBits(stats.mean) && Double.doubleToLongBits(this.sumOfSquaresOfDeltas) == Double.doubleToLongBits(stats.sumOfSquaresOfDeltas) && Double.doubleToLongBits(this.min) == Double.doubleToLongBits(stats.min) && Double.doubleToLongBits(this.max) == Double.doubleToLongBits(stats.max);
}
public final int hashCode() {
return Objects.hashCode(Long.valueOf(this.count), Double.valueOf(this.mean), Double.valueOf(this.sumOfSquaresOfDeltas), Double.valueOf(this.min), Double.valueOf(this.max));
}
public final String toString() {
if (count() > 0) {
return MoreObjects.toStringHelper(this).add("count", this.count).add("mean", this.mean).add("populationStandardDeviation", populationStandardDeviation()).add("min", this.min).add("max", this.max).toString();
}
return MoreObjects.toStringHelper(this).add("count", this.count).toString();
}
public static double meanOf(Iterable<? extends Number> iterable) {
return meanOf(iterable.iterator());
}
public static double meanOf(Iterator<? extends Number> it) {
Preconditions.checkArgument(it.hasNext());
double doubleValue = it.next().doubleValue();
long j = 1;
while (it.hasNext()) {
double doubleValue2 = it.next().doubleValue();
j++;
doubleValue = (Doubles.isFinite(doubleValue2) && Doubles.isFinite(doubleValue)) ? doubleValue + ((doubleValue2 - doubleValue) / j) : StatsAccumulator.calculateNewMeanNonFinite(doubleValue, doubleValue2);
}
return doubleValue;
}
public static double meanOf(double... dArr) {
Preconditions.checkArgument(dArr.length > 0);
double d = dArr[0];
for (int i = 1; i < dArr.length; i++) {
double d2 = dArr[i];
d = (Doubles.isFinite(d2) && Doubles.isFinite(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.calculateNewMeanNonFinite(d, d2);
}
return d;
}
public static double meanOf(int... iArr) {
Preconditions.checkArgument(iArr.length > 0);
double d = iArr[0];
for (int i = 1; i < iArr.length; i++) {
double d2 = iArr[i];
d = (Doubles.isFinite(d2) && Doubles.isFinite(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.calculateNewMeanNonFinite(d, d2);
}
return d;
}
public static double meanOf(long... jArr) {
Preconditions.checkArgument(jArr.length > 0);
double d = jArr[0];
for (int i = 1; i < jArr.length; i++) {
double d2 = jArr[i];
d = (Doubles.isFinite(d2) && Doubles.isFinite(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.calculateNewMeanNonFinite(d, d2);
}
return d;
}
public final byte[] toByteArray() {
ByteBuffer order = ByteBuffer.allocate(40).order(ByteOrder.LITTLE_ENDIAN);
writeTo(order);
return order.array();
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void writeTo(ByteBuffer byteBuffer) {
Preconditions.checkNotNull(byteBuffer);
Preconditions.checkArgument(byteBuffer.remaining() >= 40, "Expected at least Stats.BYTES = %s remaining , got %s", 40, byteBuffer.remaining());
byteBuffer.putLong(this.count).putDouble(this.mean).putDouble(this.sumOfSquaresOfDeltas).putDouble(this.min).putDouble(this.max);
}
public static Stats fromByteArray(byte[] bArr) {
Preconditions.checkNotNull(bArr);
Preconditions.checkArgument(bArr.length == 40, "Expected Stats.BYTES = %s remaining , got %s", 40, bArr.length);
return readFrom(ByteBuffer.wrap(bArr).order(ByteOrder.LITTLE_ENDIAN));
}
/* JADX INFO: Access modifiers changed from: package-private */
public static Stats readFrom(ByteBuffer byteBuffer) {
Preconditions.checkNotNull(byteBuffer);
Preconditions.checkArgument(byteBuffer.remaining() >= 40, "Expected at least Stats.BYTES = %s remaining , got %s", 40, byteBuffer.remaining());
return new Stats(byteBuffer.getLong(), byteBuffer.getDouble(), byteBuffer.getDouble(), byteBuffer.getDouble(), byteBuffer.getDouble());
}
/* JADX INFO: Access modifiers changed from: package-private */
public final double sumOfSquaresOfDeltas() {
return this.sumOfSquaresOfDeltas;
}
public final double sum() {
return this.mean * this.count;
}
public final long count() {
return this.count;
}
}