Rabbit-R1/switch port/java/sources/com/google/common/primitives/Floats.java
2024-05-21 17:08:36 -04:00

426 lines
13 KiB
Java

package com.google.common.primitives;
import com.google.common.base.Converter;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
public final class Floats extends FloatsMethodsForWeb {
public static final int BYTES = 4;
public static boolean isFinite(float f) {
return Float.NEGATIVE_INFINITY < f && f < Float.POSITIVE_INFINITY;
}
private Floats() {
}
public static int hashCode(float f) {
return Float.valueOf(f).hashCode();
}
public static int compare(float f, float f2) {
return Float.compare(f, f2);
}
public static boolean contains(float[] fArr, float f) {
for (float f2 : fArr) {
if (f2 == f) {
return true;
}
}
return false;
}
public static int indexOf(float[] fArr, float f) {
return indexOf(fArr, f, 0, fArr.length);
}
/* JADX INFO: Access modifiers changed from: private */
public static int indexOf(float[] fArr, float f, int i, int i2) {
while (i < i2) {
if (fArr[i] == f) {
return i;
}
i++;
}
return -1;
}
/* JADX WARN: Code restructure failed: missing block: B:15:0x0025, code lost:
r0 = r0 + 1;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static int indexOf(float[] r5, float[] r6) {
/*
java.lang.String r0 = "array"
com.google.common.base.Preconditions.checkNotNull(r5, r0)
java.lang.String r0 = "target"
com.google.common.base.Preconditions.checkNotNull(r6, r0)
int r0 = r6.length
r1 = 0
if (r0 != 0) goto Lf
return r1
Lf:
r0 = r1
L10:
int r2 = r5.length
int r3 = r6.length
int r2 = r2 - r3
int r2 = r2 + 1
if (r0 >= r2) goto L2c
r2 = r1
L18:
int r3 = r6.length
if (r2 >= r3) goto L2b
int r3 = r0 + r2
r3 = r5[r3]
r4 = r6[r2]
int r3 = (r3 > r4 ? 1 : (r3 == r4 ? 0 : -1))
if (r3 == 0) goto L28
int r0 = r0 + 1
goto L10
L28:
int r2 = r2 + 1
goto L18
L2b:
return r0
L2c:
r5 = -1
return r5
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.primitives.Floats.indexOf(float[], float[]):int");
}
public static int lastIndexOf(float[] fArr, float f) {
return lastIndexOf(fArr, f, 0, fArr.length);
}
/* JADX INFO: Access modifiers changed from: private */
public static int lastIndexOf(float[] fArr, float f, int i, int i2) {
for (int i3 = i2 - 1; i3 >= i; i3--) {
if (fArr[i3] == f) {
return i3;
}
}
return -1;
}
public static float min(float... fArr) {
Preconditions.checkArgument(fArr.length > 0);
float f = fArr[0];
for (int i = 1; i < fArr.length; i++) {
f = Math.min(f, fArr[i]);
}
return f;
}
public static float max(float... fArr) {
Preconditions.checkArgument(fArr.length > 0);
float f = fArr[0];
for (int i = 1; i < fArr.length; i++) {
f = Math.max(f, fArr[i]);
}
return f;
}
public static float constrainToRange(float f, float f2, float f3) {
if (f2 <= f3) {
return Math.min(Math.max(f, f2), f3);
}
throw new IllegalArgumentException(Strings.lenientFormat("min (%s) must be less than or equal to max (%s)", Float.valueOf(f2), Float.valueOf(f3)));
}
public static float[] concat(float[]... fArr) {
int i = 0;
for (float[] fArr2 : fArr) {
i += fArr2.length;
}
float[] fArr3 = new float[i];
int i2 = 0;
for (float[] fArr4 : fArr) {
System.arraycopy(fArr4, 0, fArr3, i2, fArr4.length);
i2 += fArr4.length;
}
return fArr3;
}
/* loaded from: classes3.dex */
private static final class FloatConverter extends Converter<String, Float> implements Serializable {
static final FloatConverter INSTANCE = new FloatConverter();
private static final long serialVersionUID = 1;
private Object readResolve() {
return INSTANCE;
}
public String toString() {
return "Floats.stringConverter()";
}
private FloatConverter() {
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.base.Converter
public Float doForward(String str) {
return Float.valueOf(str);
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.base.Converter
public String doBackward(Float f) {
return f.toString();
}
}
public static Converter<String, Float> stringConverter() {
return FloatConverter.INSTANCE;
}
public static float[] ensureCapacity(float[] fArr, int i, int i2) {
Preconditions.checkArgument(i >= 0, "Invalid minLength: %s", i);
Preconditions.checkArgument(i2 >= 0, "Invalid padding: %s", i2);
return fArr.length < i ? Arrays.copyOf(fArr, i + i2) : fArr;
}
public static String join(String str, float... fArr) {
Preconditions.checkNotNull(str);
if (fArr.length == 0) {
return "";
}
StringBuilder sb = new StringBuilder(fArr.length * 12);
sb.append(fArr[0]);
for (int i = 1; i < fArr.length; i++) {
sb.append(str).append(fArr[i]);
}
return sb.toString();
}
public static Comparator<float[]> lexicographicalComparator() {
return LexicographicalComparator.INSTANCE;
}
/* loaded from: classes3.dex */
private enum LexicographicalComparator implements Comparator<float[]> {
INSTANCE;
@Override // java.lang.Enum
public String toString() {
return "Floats.lexicographicalComparator()";
}
@Override // java.util.Comparator
public int compare(float[] fArr, float[] fArr2) {
int min = Math.min(fArr.length, fArr2.length);
for (int i = 0; i < min; i++) {
int compare = Float.compare(fArr[i], fArr2[i]);
if (compare != 0) {
return compare;
}
}
return fArr.length - fArr2.length;
}
}
public static void sortDescending(float[] fArr) {
Preconditions.checkNotNull(fArr);
sortDescending(fArr, 0, fArr.length);
}
public static void sortDescending(float[] fArr, int i, int i2) {
Preconditions.checkNotNull(fArr);
Preconditions.checkPositionIndexes(i, i2, fArr.length);
Arrays.sort(fArr, i, i2);
reverse(fArr, i, i2);
}
public static void reverse(float[] fArr) {
Preconditions.checkNotNull(fArr);
reverse(fArr, 0, fArr.length);
}
public static void reverse(float[] fArr, int i, int i2) {
Preconditions.checkNotNull(fArr);
Preconditions.checkPositionIndexes(i, i2, fArr.length);
for (int i3 = i2 - 1; i < i3; i3--) {
float f = fArr[i];
fArr[i] = fArr[i3];
fArr[i3] = f;
i++;
}
}
public static float[] toArray(Collection<? extends Number> collection) {
if (collection instanceof FloatArrayAsList) {
return ((FloatArrayAsList) collection).toFloatArray();
}
Object[] array = collection.toArray();
int length = array.length;
float[] fArr = new float[length];
for (int i = 0; i < length; i++) {
fArr[i] = ((Number) Preconditions.checkNotNull(array[i])).floatValue();
}
return fArr;
}
public static List<Float> asList(float... fArr) {
if (fArr.length == 0) {
return Collections.emptyList();
}
return new FloatArrayAsList(fArr);
}
/* loaded from: classes3.dex */
private static class FloatArrayAsList extends AbstractList<Float> implements RandomAccess, Serializable {
private static final long serialVersionUID = 0;
final float[] array;
final int end;
final int start;
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public boolean isEmpty() {
return false;
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public int size() {
return this.end - this.start;
}
FloatArrayAsList(float[] fArr) {
this(fArr, 0, fArr.length);
}
FloatArrayAsList(float[] fArr, int i, int i2) {
this.array = fArr;
this.start = i;
this.end = i2;
}
@Override // java.util.AbstractList, java.util.List
public Float get(int i) {
Preconditions.checkElementIndex(i, size());
return Float.valueOf(this.array[this.start + i]);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public boolean contains(@CheckForNull Object obj) {
return (obj instanceof Float) && Floats.indexOf(this.array, ((Float) obj).floatValue(), this.start, this.end) != -1;
}
@Override // java.util.AbstractList, java.util.List
public int indexOf(@CheckForNull Object obj) {
int indexOf;
if (!(obj instanceof Float) || (indexOf = Floats.indexOf(this.array, ((Float) obj).floatValue(), this.start, this.end)) < 0) {
return -1;
}
return indexOf - this.start;
}
@Override // java.util.AbstractList, java.util.List
public int lastIndexOf(@CheckForNull Object obj) {
int lastIndexOf;
if (!(obj instanceof Float) || (lastIndexOf = Floats.lastIndexOf(this.array, ((Float) obj).floatValue(), this.start, this.end)) < 0) {
return -1;
}
return lastIndexOf - this.start;
}
@Override // java.util.AbstractList, java.util.List
public Float set(int i, Float f) {
Preconditions.checkElementIndex(i, size());
float[] fArr = this.array;
int i2 = this.start;
float f2 = fArr[i2 + i];
fArr[i2 + i] = ((Float) Preconditions.checkNotNull(f)).floatValue();
return Float.valueOf(f2);
}
@Override // java.util.AbstractList, java.util.List
public List<Float> subList(int i, int i2) {
Preconditions.checkPositionIndexes(i, i2, size());
if (i == i2) {
return Collections.emptyList();
}
float[] fArr = this.array;
int i3 = this.start;
return new FloatArrayAsList(fArr, i + i3, i3 + i2);
}
@Override // java.util.AbstractList, java.util.Collection, java.util.List
public boolean equals(@CheckForNull Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof FloatArrayAsList) {
FloatArrayAsList floatArrayAsList = (FloatArrayAsList) obj;
int size = size();
if (floatArrayAsList.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (this.array[this.start + i] != floatArrayAsList.array[floatArrayAsList.start + i]) {
return false;
}
}
return true;
}
return super.equals(obj);
}
@Override // java.util.AbstractList, java.util.Collection, java.util.List
public int hashCode() {
int i = 1;
for (int i2 = this.start; i2 < this.end; i2++) {
i = (i * 31) + Floats.hashCode(this.array[i2]);
}
return i;
}
@Override // java.util.AbstractCollection
public String toString() {
StringBuilder sb = new StringBuilder(size() * 12);
sb.append('[').append(this.array[this.start]);
int i = this.start;
while (true) {
i++;
if (i < this.end) {
sb.append(", ").append(this.array[i]);
} else {
return sb.append(']').toString();
}
}
}
float[] toFloatArray() {
return Arrays.copyOfRange(this.array, this.start, this.end);
}
}
@CheckForNull
public static Float tryParse(String str) {
if (!Doubles.FLOATING_POINT_PATTERN.matcher(str).matches()) {
return null;
}
try {
return Float.valueOf(Float.parseFloat(str));
} catch (NumberFormatException unused) {
return null;
}
}
}