Rabbit-R1/android (non root)/java/sources/com/google/common/base/Joiner.java
2024-05-21 17:08:36 -04:00

248 lines
8.9 KiB
Java

package com.google.common.base;
import java.io.IOException;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes2.dex */
public class Joiner {
private final String separator;
public static Joiner on(String str) {
return new Joiner(str);
}
public static Joiner on(char c) {
return new Joiner(String.valueOf(c));
}
private Joiner(String str) {
this.separator = (String) Preconditions.checkNotNull(str);
}
private Joiner(Joiner joiner) {
this.separator = joiner.separator;
}
public <A extends Appendable> A appendTo(A a, Iterable<? extends Object> iterable) throws IOException {
return (A) appendTo((Joiner) a, iterable.iterator());
}
public <A extends Appendable> A appendTo(A a, Iterator<? extends Object> it) throws IOException {
Preconditions.checkNotNull(a);
if (it.hasNext()) {
a.append(toString(it.next()));
while (it.hasNext()) {
a.append(this.separator);
a.append(toString(it.next()));
}
}
return a;
}
public final <A extends Appendable> A appendTo(A a, Object[] objArr) throws IOException {
return (A) appendTo((Joiner) a, (Iterable<? extends Object>) Arrays.asList(objArr));
}
public final <A extends Appendable> A appendTo(A a, @CheckForNull Object obj, @CheckForNull Object obj2, Object... objArr) throws IOException {
return (A) appendTo((Joiner) a, iterable(obj, obj2, objArr));
}
public final StringBuilder appendTo(StringBuilder sb, Iterable<? extends Object> iterable) {
return appendTo(sb, iterable.iterator());
}
public final StringBuilder appendTo(StringBuilder sb, Iterator<? extends Object> it) {
try {
appendTo((Joiner) sb, it);
return sb;
} catch (IOException e) {
throw new AssertionError(e);
}
}
public final StringBuilder appendTo(StringBuilder sb, Object[] objArr) {
return appendTo(sb, (Iterable<? extends Object>) Arrays.asList(objArr));
}
public final StringBuilder appendTo(StringBuilder sb, @CheckForNull Object obj, @CheckForNull Object obj2, Object... objArr) {
return appendTo(sb, iterable(obj, obj2, objArr));
}
public final String join(Iterable<? extends Object> iterable) {
return join(iterable.iterator());
}
public final String join(Iterator<? extends Object> it) {
return appendTo(new StringBuilder(), it).toString();
}
public final String join(Object[] objArr) {
return join(Arrays.asList(objArr));
}
public final String join(@CheckForNull Object obj, @CheckForNull Object obj2, Object... objArr) {
return join(iterable(obj, obj2, objArr));
}
public Joiner useForNull(final String str) {
Preconditions.checkNotNull(str);
return new Joiner(this) { // from class: com.google.common.base.Joiner.1
@Override // com.google.common.base.Joiner
CharSequence toString(@CheckForNull Object obj) {
return obj == null ? str : Joiner.this.toString(obj);
}
@Override // com.google.common.base.Joiner
public Joiner useForNull(String str2) {
throw new UnsupportedOperationException("already specified useForNull");
}
@Override // com.google.common.base.Joiner
public Joiner skipNulls() {
throw new UnsupportedOperationException("already specified useForNull");
}
};
}
public Joiner skipNulls() {
return new Joiner(this) { // from class: com.google.common.base.Joiner.2
@Override // com.google.common.base.Joiner
public <A extends Appendable> A appendTo(A a, Iterator<? extends Object> it) throws IOException {
Preconditions.checkNotNull(a, "appendable");
Preconditions.checkNotNull(it, "parts");
while (true) {
if (!it.hasNext()) {
break;
}
Object next = it.next();
if (next != null) {
a.append(Joiner.this.toString(next));
break;
}
}
while (it.hasNext()) {
Object next2 = it.next();
if (next2 != null) {
a.append(Joiner.this.separator);
a.append(Joiner.this.toString(next2));
}
}
return a;
}
@Override // com.google.common.base.Joiner
public Joiner useForNull(String str) {
throw new UnsupportedOperationException("already specified skipNulls");
}
@Override // com.google.common.base.Joiner
public MapJoiner withKeyValueSeparator(String str) {
throw new UnsupportedOperationException("can't use .skipNulls() with maps");
}
};
}
public MapJoiner withKeyValueSeparator(char c) {
return withKeyValueSeparator(String.valueOf(c));
}
public MapJoiner withKeyValueSeparator(String str) {
return new MapJoiner(str);
}
/* loaded from: classes2.dex */
public static final class MapJoiner {
private final Joiner joiner;
private final String keyValueSeparator;
private MapJoiner(Joiner joiner, String str) {
this.joiner = joiner;
this.keyValueSeparator = (String) Preconditions.checkNotNull(str);
}
public <A extends Appendable> A appendTo(A a, Map<?, ?> map) throws IOException {
return (A) appendTo((MapJoiner) a, (Iterable<? extends Map.Entry<?, ?>>) map.entrySet());
}
public StringBuilder appendTo(StringBuilder sb, Map<?, ?> map) {
return appendTo(sb, (Iterable<? extends Map.Entry<?, ?>>) map.entrySet());
}
public <A extends Appendable> A appendTo(A a, Iterable<? extends Map.Entry<?, ?>> iterable) throws IOException {
return (A) appendTo((MapJoiner) a, iterable.iterator());
}
public <A extends Appendable> A appendTo(A a, Iterator<? extends Map.Entry<?, ?>> it) throws IOException {
Preconditions.checkNotNull(a);
if (it.hasNext()) {
Map.Entry<?, ?> next = it.next();
a.append(this.joiner.toString(next.getKey()));
a.append(this.keyValueSeparator);
a.append(this.joiner.toString(next.getValue()));
while (it.hasNext()) {
a.append(this.joiner.separator);
Map.Entry<?, ?> next2 = it.next();
a.append(this.joiner.toString(next2.getKey()));
a.append(this.keyValueSeparator);
a.append(this.joiner.toString(next2.getValue()));
}
}
return a;
}
public StringBuilder appendTo(StringBuilder sb, Iterable<? extends Map.Entry<?, ?>> iterable) {
return appendTo(sb, iterable.iterator());
}
public StringBuilder appendTo(StringBuilder sb, Iterator<? extends Map.Entry<?, ?>> it) {
try {
appendTo((MapJoiner) sb, it);
return sb;
} catch (IOException e) {
throw new AssertionError(e);
}
}
public String join(Map<?, ?> map) {
return join(map.entrySet());
}
public String join(Iterable<? extends Map.Entry<?, ?>> iterable) {
return join(iterable.iterator());
}
public String join(Iterator<? extends Map.Entry<?, ?>> it) {
return appendTo(new StringBuilder(), it).toString();
}
public MapJoiner useForNull(String str) {
return new MapJoiner(this.joiner.useForNull(str), this.keyValueSeparator);
}
}
CharSequence toString(@CheckForNull Object obj) {
java.util.Objects.requireNonNull(obj);
return obj instanceof CharSequence ? (CharSequence) obj : obj.toString();
}
private static Iterable<Object> iterable(@CheckForNull final Object obj, @CheckForNull final Object obj2, final Object[] objArr) {
Preconditions.checkNotNull(objArr);
return new AbstractList<Object>() { // from class: com.google.common.base.Joiner.3
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public int size() {
return objArr.length + 2;
}
@Override // java.util.AbstractList, java.util.List
@CheckForNull
public Object get(int i) {
return i != 0 ? i != 1 ? objArr[i - 2] : obj2 : obj;
}
};
}
}