what-the-bank/sources/com/google/common/collect/DiscreteDomain.java

227 lines
7.2 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Ints;
import java.io.Serializable;
import java.lang.Comparable;
import java.math.BigInteger;
import java.util.NoSuchElementException;
import org.bouncycastle.asn1.cmp.PKIFailureInfo;
/* loaded from: classes2.dex */
public abstract class DiscreteDomain<C extends Comparable> {
final boolean supportsFastOffset;
public abstract long distance(C c, C c2);
public abstract C next(C c);
public abstract C previous(C c);
public static DiscreteDomain<Integer> integers() {
return IntegerDomain.INSTANCE;
}
/* loaded from: classes2.dex */
static final class IntegerDomain extends DiscreteDomain<Integer> implements Serializable {
private static final IntegerDomain INSTANCE = new IntegerDomain();
private static final long serialVersionUID = 0;
IntegerDomain() {
super(true);
}
@Override // com.google.common.collect.DiscreteDomain
public final Integer next(Integer num) {
int intValue = num.intValue();
if (intValue == Integer.MAX_VALUE) {
return null;
}
return Integer.valueOf(intValue + 1);
}
@Override // com.google.common.collect.DiscreteDomain
public final Integer previous(Integer num) {
int intValue = num.intValue();
if (intValue == Integer.MIN_VALUE) {
return null;
}
return Integer.valueOf(intValue - 1);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.DiscreteDomain
public final Integer offset(Integer num, long j) {
CollectPreconditions.checkNonnegative(j, "distance");
return Integer.valueOf(Ints.checkedCast(num.longValue() + j));
}
@Override // com.google.common.collect.DiscreteDomain
public final long distance(Integer num, Integer num2) {
return num2.intValue() - num.intValue();
}
@Override // com.google.common.collect.DiscreteDomain
public final Integer minValue() {
return Integer.valueOf(PKIFailureInfo.systemUnavail);
}
@Override // com.google.common.collect.DiscreteDomain
public final Integer maxValue() {
return Integer.MAX_VALUE;
}
public final String toString() {
return "DiscreteDomain.integers()";
}
private Object readResolve() {
return INSTANCE;
}
}
public static DiscreteDomain<Long> longs() {
return LongDomain.INSTANCE;
}
/* loaded from: classes2.dex */
static final class LongDomain extends DiscreteDomain<Long> implements Serializable {
private static final LongDomain INSTANCE = new LongDomain();
private static final long serialVersionUID = 0;
LongDomain() {
super(true);
}
@Override // com.google.common.collect.DiscreteDomain
public final Long next(Long l) {
long longValue = l.longValue();
if (longValue == Long.MAX_VALUE) {
return null;
}
return Long.valueOf(longValue + 1);
}
@Override // com.google.common.collect.DiscreteDomain
public final Long previous(Long l) {
long longValue = l.longValue();
if (longValue == Long.MIN_VALUE) {
return null;
}
return Long.valueOf(longValue - 1);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.DiscreteDomain
public final Long offset(Long l, long j) {
CollectPreconditions.checkNonnegative(j, "distance");
long longValue = l.longValue() + j;
if (longValue < 0) {
Preconditions.checkArgument(l.longValue() < 0, "overflow");
}
return Long.valueOf(longValue);
}
@Override // com.google.common.collect.DiscreteDomain
public final long distance(Long l, Long l2) {
long longValue = l2.longValue() - l.longValue();
if (l2.longValue() > l.longValue() && longValue < 0) {
return Long.MAX_VALUE;
}
if (l2.longValue() >= l.longValue() || longValue <= 0) {
return longValue;
}
return Long.MIN_VALUE;
}
@Override // com.google.common.collect.DiscreteDomain
public final Long minValue() {
return Long.MIN_VALUE;
}
@Override // com.google.common.collect.DiscreteDomain
public final Long maxValue() {
return Long.MAX_VALUE;
}
public final String toString() {
return "DiscreteDomain.longs()";
}
private Object readResolve() {
return INSTANCE;
}
}
public static DiscreteDomain<BigInteger> bigIntegers() {
return BigIntegerDomain.INSTANCE;
}
/* loaded from: classes2.dex */
static final class BigIntegerDomain extends DiscreteDomain<BigInteger> implements Serializable {
private static final long serialVersionUID = 0;
private static final BigIntegerDomain INSTANCE = new BigIntegerDomain();
private static final BigInteger MIN_LONG = BigInteger.valueOf(Long.MIN_VALUE);
private static final BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE);
BigIntegerDomain() {
super(true);
}
@Override // com.google.common.collect.DiscreteDomain
public final BigInteger next(BigInteger bigInteger) {
return bigInteger.add(BigInteger.ONE);
}
@Override // com.google.common.collect.DiscreteDomain
public final BigInteger previous(BigInteger bigInteger) {
return bigInteger.subtract(BigInteger.ONE);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.DiscreteDomain
public final BigInteger offset(BigInteger bigInteger, long j) {
CollectPreconditions.checkNonnegative(j, "distance");
return bigInteger.add(BigInteger.valueOf(j));
}
@Override // com.google.common.collect.DiscreteDomain
public final long distance(BigInteger bigInteger, BigInteger bigInteger2) {
return bigInteger2.subtract(bigInteger).max(MIN_LONG).min(MAX_LONG).longValue();
}
public final String toString() {
return "DiscreteDomain.bigIntegers()";
}
private Object readResolve() {
return INSTANCE;
}
}
protected DiscreteDomain() {
this(false);
}
private DiscreteDomain(boolean z) {
this.supportsFastOffset = z;
}
/* JADX INFO: Access modifiers changed from: package-private */
public C offset(C c, long j) {
CollectPreconditions.checkNonnegative(j, "distance");
for (long j2 = 0; j2 < j; j2++) {
c = next(c);
}
return c;
}
public C minValue() {
throw new NoSuchElementException();
}
public C maxValue() {
throw new NoSuchElementException();
}
}