mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 17:42:33 -06:00
207 lines
7.9 KiB
Java
207 lines
7.9 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 io.sentry.protocol.MetricSummary;
|
|
import java.io.Serializable;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.util.Iterator;
|
|
import javax.annotation.CheckForNull;
|
|
import tech.rabbit.r1launcher.BuildConfig;
|
|
|
|
@ElementTypesAreNonnullByDefault
|
|
/* loaded from: classes3.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;
|
|
|
|
public long count() {
|
|
return this.count;
|
|
}
|
|
|
|
public double sum() {
|
|
return this.mean * this.count;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public double sumOfSquaresOfDeltas() {
|
|
return this.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 double mean() {
|
|
Preconditions.checkState(this.count != 0);
|
|
return this.mean;
|
|
}
|
|
|
|
public double populationVariance() {
|
|
Preconditions.checkState(this.count > 0);
|
|
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
|
|
return Double.NaN;
|
|
}
|
|
return this.count == 1 ? BuildConfig.SENTRY_SAMPLE_RATE : DoubleUtils.ensureNonNegative(this.sumOfSquaresOfDeltas) / count();
|
|
}
|
|
|
|
public double populationStandardDeviation() {
|
|
return Math.sqrt(populationVariance());
|
|
}
|
|
|
|
public double sampleVariance() {
|
|
Preconditions.checkState(this.count > 1);
|
|
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
|
|
return Double.NaN;
|
|
}
|
|
return DoubleUtils.ensureNonNegative(this.sumOfSquaresOfDeltas) / (this.count - 1);
|
|
}
|
|
|
|
public double sampleStandardDeviation() {
|
|
return Math.sqrt(sampleVariance());
|
|
}
|
|
|
|
public double min() {
|
|
Preconditions.checkState(this.count != 0);
|
|
return this.min;
|
|
}
|
|
|
|
public double max() {
|
|
Preconditions.checkState(this.count != 0);
|
|
return this.max;
|
|
}
|
|
|
|
public boolean equals(@CheckForNull 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 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 String toString() {
|
|
if (count() > 0) {
|
|
return MoreObjects.toStringHelper(this).add(MetricSummary.JsonKeys.COUNT, this.count).add("mean", this.mean).add("populationStandardDeviation", populationStandardDeviation()).add(MetricSummary.JsonKeys.MIN, this.min).add(MetricSummary.JsonKeys.MAX, this.max).toString();
|
|
}
|
|
return MoreObjects.toStringHelper(this).add(MetricSummary.JsonKeys.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 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 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());
|
|
}
|
|
}
|