jimu-decompiled/sources/com/squareup/haha/guava/base/Joiner.java
2025-05-13 19:24:51 +02:00

212 lines
6.8 KiB
Java

package com.squareup.haha.guava.base;
import com.squareup.haha.guava.collect.ImmutableList;
import com.squareup.haha.guava.collect.Iterators;
import com.squareup.haha.guava.collect.Lists$RandomAccessReverseList;
import com.squareup.haha.guava.collect.Lists$ReverseList;
import com.squareup.haha.guava.collect.Multiset;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.RandomAccess;
import java.util.Set;
/* loaded from: classes.dex */
public class Joiner {
private final String separator;
public static final class MapJoiner {
public /* synthetic */ MapJoiner(Joiner joiner, String str, byte b) {
this(joiner, str);
}
private MapJoiner(Joiner joiner, String str) {
Joiner.checkNotNull(str);
}
}
/* synthetic */ Joiner(Joiner joiner, byte b) {
this(joiner);
}
static String badPositionIndex(int i, int i2, String str) {
if (i < 0) {
return format("%s (%s) must not be negative", str, Integer.valueOf(i));
}
if (i2 >= 0) {
return format("%s (%s) must not be greater than size (%s)", str, Integer.valueOf(i), Integer.valueOf(i2));
}
throw new IllegalArgumentException("negative size: " + i2);
}
public static void checkArgument(boolean z) {
if (!z) {
throw new IllegalArgumentException();
}
}
public static int checkElementIndex(int i, int i2) {
String format;
if (i >= 0 && i < i2) {
return i;
}
if (i < 0) {
format = format("%s (%s) must not be negative", "index", Integer.valueOf(i));
} else {
if (i2 < 0) {
throw new IllegalArgumentException("negative size: " + i2);
}
format = format("%s (%s) must be less than size (%s)", "index", Integer.valueOf(i), Integer.valueOf(i2));
}
throw new IndexOutOfBoundsException(format);
}
public static <T> T checkNotNull(T t) {
if (t != null) {
return t;
}
throw new NullPointerException();
}
public static int checkPositionIndex(int i, int i2) {
if (i < 0 || i > i2) {
throw new IndexOutOfBoundsException(badPositionIndex(i, i2, "index"));
}
return i;
}
public static void checkPositionIndexes(int i, int i2, int i3) {
if (i < 0 || i2 < i || i2 > i3) {
throw new IndexOutOfBoundsException((i < 0 || i > i3) ? badPositionIndex(i, i3, "start index") : (i2 < 0 || i2 > i3) ? badPositionIndex(i2, i3, "end index") : format("end index (%s) must not be less than start index (%s)", Integer.valueOf(i2), Integer.valueOf(i)));
}
}
public static void checkRemove(boolean z) {
if (!z) {
throw new IllegalStateException("no calls to next() since the last call to remove()");
}
}
public static boolean equal(Object obj, Object obj2) {
if (obj != obj2) {
return obj != null && obj.equals(obj2);
}
return true;
}
public static boolean equalsImpl(Set<?> set, Object obj) {
if (set == obj) {
return true;
}
if (obj instanceof Set) {
Set set2 = (Set) obj;
try {
if (set.size() == set2.size()) {
if (set.containsAll(set2)) {
return true;
}
}
} catch (ClassCastException | NullPointerException unused) {
}
}
return false;
}
static String format(String str, Object... objArr) {
int indexOf;
String valueOf = String.valueOf(str);
StringBuilder sb = new StringBuilder(valueOf.length() + (objArr.length * 16));
int i = 0;
int i2 = 0;
while (i < objArr.length && (indexOf = valueOf.indexOf("%s", i2)) != -1) {
sb.append(valueOf.substring(i2, indexOf));
sb.append(objArr[i]);
i2 = indexOf + 2;
i++;
}
sb.append(valueOf.substring(i2));
if (i < objArr.length) {
sb.append(" [");
sb.append(objArr[i]);
for (int i3 = i + 1; i3 < objArr.length; i3++) {
sb.append(", ");
sb.append(objArr[i3]);
}
sb.append(']');
}
return sb.toString();
}
public static boolean removeAllImpl(Set<?> set, Iterator<?> it) {
boolean z = false;
while (it.hasNext()) {
z |= set.remove(it.next());
}
return z;
}
public static <T> List<T> reverse(List<T> list) {
return list instanceof ImmutableList ? ((ImmutableList) list).reverse() : list instanceof Lists$ReverseList ? ((Lists$ReverseList) list).forwardList : list instanceof RandomAccess ? new Lists$RandomAccessReverseList(list) : new Lists$ReverseList(list);
}
public final StringBuilder appendTo(StringBuilder sb, Iterator<?> it) {
try {
checkNotNull(sb);
if (it.hasNext()) {
sb.append(toString(it.next()));
while (it.hasNext()) {
sb.append((CharSequence) this.separator);
sb.append(toString(it.next()));
}
}
return sb;
} catch (IOException e) {
throw new AssertionError(e);
}
}
CharSequence toString(Object obj) {
checkNotNull(obj);
return obj instanceof CharSequence ? (CharSequence) obj : obj.toString();
}
public Joiner useForNull(final String str) {
checkNotNull(str);
return new Joiner(this) { // from class: com.squareup.haha.guava.base.Joiner.1
{
byte b = 0;
}
@Override // com.squareup.haha.guava.base.Joiner
final CharSequence toString(Object obj) {
return obj == null ? str : Joiner.this.toString(obj);
}
@Override // com.squareup.haha.guava.base.Joiner
public final Joiner useForNull(String str2) {
throw new UnsupportedOperationException("already specified useForNull");
}
};
}
public Joiner(String str) {
this.separator = (String) checkNotNull(str);
}
public static boolean removeAllImpl(Set<?> set, Collection<?> collection) {
checkNotNull(collection);
if (collection instanceof Multiset) {
collection = ((Multiset) collection).elementSet();
}
if ((collection instanceof Set) && collection.size() > set.size()) {
return Iterators.removeAll(set.iterator(), collection);
}
return removeAllImpl(set, collection.iterator());
}
private Joiner(Joiner joiner) {
this.separator = joiner.separator;
}
}