211 lines
7.1 KiB
Java
211 lines
7.1 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: classes.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;
|
|
|
|
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 fromByteArray(byte[] bArr) {
|
|
Preconditions.a(bArr);
|
|
Preconditions.a(bArr.length == 40, "Expected Stats.BYTES = %s remaining , got %s", 40, bArr.length);
|
|
return readFrom(ByteBuffer.wrap(bArr).order(ByteOrder.LITTLE_ENDIAN));
|
|
}
|
|
|
|
public static double meanOf(Iterable<? extends Number> iterable) {
|
|
return meanOf(iterable.iterator());
|
|
}
|
|
|
|
public static Stats of(Iterable<? extends Number> iterable) {
|
|
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
|
statsAccumulator.a(iterable);
|
|
return statsAccumulator.a();
|
|
}
|
|
|
|
static Stats readFrom(ByteBuffer byteBuffer) {
|
|
Preconditions.a(byteBuffer);
|
|
Preconditions.a(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());
|
|
}
|
|
|
|
public long count() {
|
|
return this.count;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (obj == null || Stats.class != 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 int hashCode() {
|
|
return Objects.a(Long.valueOf(this.count), Double.valueOf(this.mean), Double.valueOf(this.sumOfSquaresOfDeltas), Double.valueOf(this.min), Double.valueOf(this.max));
|
|
}
|
|
|
|
public double max() {
|
|
Preconditions.b(this.count != 0);
|
|
return this.max;
|
|
}
|
|
|
|
public double mean() {
|
|
Preconditions.b(this.count != 0);
|
|
return this.mean;
|
|
}
|
|
|
|
public double min() {
|
|
Preconditions.b(this.count != 0);
|
|
return this.min;
|
|
}
|
|
|
|
public double populationStandardDeviation() {
|
|
return Math.sqrt(populationVariance());
|
|
}
|
|
|
|
public double populationVariance() {
|
|
Preconditions.b(this.count > 0);
|
|
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
|
|
return Double.NaN;
|
|
}
|
|
if (this.count == 1) {
|
|
return 0.0d;
|
|
}
|
|
return DoubleUtils.a(this.sumOfSquaresOfDeltas) / count();
|
|
}
|
|
|
|
public double sampleStandardDeviation() {
|
|
return Math.sqrt(sampleVariance());
|
|
}
|
|
|
|
public double sampleVariance() {
|
|
Preconditions.b(this.count > 1);
|
|
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
|
|
return Double.NaN;
|
|
}
|
|
return DoubleUtils.a(this.sumOfSquaresOfDeltas) / (this.count - 1);
|
|
}
|
|
|
|
public double sum() {
|
|
return this.mean * this.count;
|
|
}
|
|
|
|
double sumOfSquaresOfDeltas() {
|
|
return this.sumOfSquaresOfDeltas;
|
|
}
|
|
|
|
public byte[] toByteArray() {
|
|
ByteBuffer order = ByteBuffer.allocate(40).order(ByteOrder.LITTLE_ENDIAN);
|
|
writeTo(order);
|
|
return order.array();
|
|
}
|
|
|
|
public String toString() {
|
|
if (count() <= 0) {
|
|
MoreObjects.ToStringHelper a = MoreObjects.a(this);
|
|
a.a("count", this.count);
|
|
return a.toString();
|
|
}
|
|
MoreObjects.ToStringHelper a2 = MoreObjects.a(this);
|
|
a2.a("count", this.count);
|
|
a2.a("mean", this.mean);
|
|
a2.a("populationStandardDeviation", populationStandardDeviation());
|
|
a2.a("min", this.min);
|
|
a2.a("max", this.max);
|
|
return a2.toString();
|
|
}
|
|
|
|
void writeTo(ByteBuffer byteBuffer) {
|
|
Preconditions.a(byteBuffer);
|
|
Preconditions.a(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 double meanOf(Iterator<? extends Number> it) {
|
|
Preconditions.a(it.hasNext());
|
|
double doubleValue = it.next().doubleValue();
|
|
long j = 1;
|
|
while (it.hasNext()) {
|
|
double doubleValue2 = it.next().doubleValue();
|
|
j++;
|
|
doubleValue = (Doubles.b(doubleValue2) && Doubles.b(doubleValue)) ? doubleValue + ((doubleValue2 - doubleValue) / j) : StatsAccumulator.a(doubleValue, doubleValue2);
|
|
}
|
|
return doubleValue;
|
|
}
|
|
|
|
public static Stats of(Iterator<? extends Number> it) {
|
|
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
|
statsAccumulator.a(it);
|
|
return statsAccumulator.a();
|
|
}
|
|
|
|
public static Stats of(double... dArr) {
|
|
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
|
statsAccumulator.a(dArr);
|
|
return statsAccumulator.a();
|
|
}
|
|
|
|
public static double meanOf(double... dArr) {
|
|
Preconditions.a(dArr.length > 0);
|
|
double d = dArr[0];
|
|
for (int i = 1; i < dArr.length; i++) {
|
|
double d2 = dArr[i];
|
|
d = (Doubles.b(d2) && Doubles.b(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.a(d, d2);
|
|
}
|
|
return d;
|
|
}
|
|
|
|
public static Stats of(int... iArr) {
|
|
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
|
statsAccumulator.a(iArr);
|
|
return statsAccumulator.a();
|
|
}
|
|
|
|
public static Stats of(long... jArr) {
|
|
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
|
statsAccumulator.a(jArr);
|
|
return statsAccumulator.a();
|
|
}
|
|
|
|
public static double meanOf(int... iArr) {
|
|
Preconditions.a(iArr.length > 0);
|
|
double d = iArr[0];
|
|
for (int i = 1; i < iArr.length; i++) {
|
|
double d2 = iArr[i];
|
|
d = (Doubles.b(d2) && Doubles.b(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.a(d, d2);
|
|
}
|
|
return d;
|
|
}
|
|
|
|
public static double meanOf(long... jArr) {
|
|
Preconditions.a(jArr.length > 0);
|
|
double d = jArr[0];
|
|
for (int i = 1; i < jArr.length; i++) {
|
|
double d2 = jArr[i];
|
|
d = (Doubles.b(d2) && Doubles.b(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.a(d, d2);
|
|
}
|
|
return d;
|
|
}
|
|
}
|