discord-jadx/app/src/main/java/androidx/core/util/Preconditions.java

115 lines
3.3 KiB
Java

package androidx.core.util;
import android.text.TextUtils;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import b.d.b.a.a;
import java.util.Locale;
import java.util.Objects;
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
/* loaded from: classes.dex */
public final class Preconditions {
private Preconditions() {
}
public static void checkArgument(boolean z2) {
if (!z2) {
throw new IllegalArgumentException();
}
}
public static void checkArgument(boolean z2, @NonNull Object obj) {
if (!z2) {
throw new IllegalArgumentException(String.valueOf(obj));
}
}
public static int checkArgumentInRange(int i, int i2, int i3, @NonNull String str) {
if (i < i2) {
throw new IllegalArgumentException(String.format(Locale.US, "%s is out of range of [%d, %d] (too low)", str, Integer.valueOf(i2), Integer.valueOf(i3)));
} else if (i <= i3) {
return i;
} else {
throw new IllegalArgumentException(String.format(Locale.US, "%s is out of range of [%d, %d] (too high)", str, Integer.valueOf(i2), Integer.valueOf(i3)));
}
}
@IntRange(from = 0)
public static int checkArgumentNonnegative(int i) {
if (i >= 0) {
return i;
}
throw new IllegalArgumentException();
}
@IntRange(from = 0)
public static int checkArgumentNonnegative(int i, @Nullable String str) {
if (i >= 0) {
return i;
}
throw new IllegalArgumentException(str);
}
public static int checkFlagsArgument(int i, int i2) {
if ((i & i2) == i) {
return i;
}
StringBuilder S = a.S("Requested flags 0x");
S.append(Integer.toHexString(i));
S.append(", but only 0x");
S.append(Integer.toHexString(i2));
S.append(" are allowed");
throw new IllegalArgumentException(S.toString());
}
@NonNull
public static <T> T checkNotNull(@Nullable T t) {
Objects.requireNonNull(t);
return t;
}
@NonNull
public static <T> T checkNotNull(@Nullable T t, @NonNull Object obj) {
if (t != null) {
return t;
}
throw new NullPointerException(String.valueOf(obj));
}
public static void checkState(boolean z2) {
checkState(z2, null);
}
public static void checkState(boolean z2, @Nullable String str) {
if (!z2) {
throw new IllegalStateException(str);
}
}
@NonNull
public static <T extends CharSequence> T checkStringNotEmpty(@Nullable T t) {
if (!TextUtils.isEmpty(t)) {
return t;
}
throw new IllegalArgumentException();
}
@NonNull
public static <T extends CharSequence> T checkStringNotEmpty(@Nullable T t, @NonNull Object obj) {
if (!TextUtils.isEmpty(t)) {
return t;
}
throw new IllegalArgumentException(String.valueOf(obj));
}
@NonNull
public static <T extends CharSequence> T checkStringNotEmpty(@Nullable T t, @NonNull String str, @NonNull Object... objArr) {
if (!TextUtils.isEmpty(t)) {
return t;
}
throw new IllegalArgumentException(String.format(str, objArr));
}
}