what-the-bank/sources/com/google/common/base/Joiner.java

270 lines
9.2 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
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;
/* 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<?> iterable) throws IOException {
return (A) appendTo((Joiner) a, iterable.iterator());
}
public <A extends Appendable> A appendTo(A a, Iterator<?> 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<?>) Arrays.asList(objArr));
}
public final <A extends Appendable> A appendTo(A a, Object obj, Object obj2, Object... objArr) throws IOException {
return (A) appendTo((Joiner) a, iterable(obj, obj2, objArr));
}
public final StringBuilder appendTo(StringBuilder sb, Iterable<?> iterable) {
return appendTo(sb, iterable.iterator());
}
public final StringBuilder appendTo(StringBuilder sb, Iterator<?> 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<?>) Arrays.asList(objArr));
}
public final StringBuilder appendTo(StringBuilder sb, Object obj, Object obj2, Object... objArr) {
return appendTo(sb, iterable(obj, obj2, objArr));
}
public final String join(Iterable<?> iterable) {
return join(iterable.iterator());
}
public final String join(Iterator<?> it) {
return appendTo(new StringBuilder(), it).toString();
}
public final String join(Object[] objArr) {
return join(Arrays.asList(objArr));
}
public final String join(Object obj, Object obj2, Object... objArr) {
return join(iterable(obj, obj2, objArr));
}
public Joiner useForNull(String str) {
Preconditions.checkNotNull(str);
return new Joiner(this, this, str) { // from class: com.google.common.base.Joiner.1
final Joiner this$0;
final String val$nullText;
{
this.this$0 = this;
this.val$nullText = str;
}
@Override // com.google.common.base.Joiner
CharSequence toString(Object obj) {
return obj == null ? this.val$nullText : this.this$0.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, this) { // from class: com.google.common.base.Joiner.2
final Joiner this$0;
{
this.this$0 = this;
}
@Override // com.google.common.base.Joiner
public <A extends Appendable> A appendTo(A a, Iterator<?> 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(this.this$0.toString(next));
break;
}
}
while (it.hasNext()) {
Object next2 = it.next();
if (next2 != null) {
a.append(this.this$0.separator);
a.append(this.this$0.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 final <A extends Appendable> A appendTo(A a, Map<?, ?> map) throws IOException {
return (A) appendTo((MapJoiner) a, (Iterable<? extends Map.Entry<?, ?>>) map.entrySet());
}
public final StringBuilder appendTo(StringBuilder sb, Map<?, ?> map) {
return appendTo(sb, (Iterable<? extends Map.Entry<?, ?>>) map.entrySet());
}
public final <A extends Appendable> A appendTo(A a, Iterable<? extends Map.Entry<?, ?>> iterable) throws IOException {
return (A) appendTo((MapJoiner) a, iterable.iterator());
}
public final <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 final StringBuilder appendTo(StringBuilder sb, Iterable<? extends Map.Entry<?, ?>> iterable) {
return appendTo(sb, iterable.iterator());
}
public final StringBuilder appendTo(StringBuilder sb, Iterator<? extends Map.Entry<?, ?>> it) {
try {
appendTo((MapJoiner) sb, it);
return sb;
} catch (IOException e) {
throw new AssertionError(e);
}
}
public final String join(Map<?, ?> map) {
return join(map.entrySet());
}
public final String join(Iterable<? extends Map.Entry<?, ?>> iterable) {
return join(iterable.iterator());
}
public final String join(Iterator<? extends Map.Entry<?, ?>> it) {
return appendTo(new StringBuilder(), it).toString();
}
public final MapJoiner useForNull(String str) {
return new MapJoiner(this.joiner.useForNull(str), this.keyValueSeparator);
}
}
CharSequence toString(Object obj) {
Preconditions.checkNotNull(obj);
return obj instanceof CharSequence ? (CharSequence) obj : obj.toString();
}
private static Iterable<Object> iterable(Object obj, Object obj2, Object[] objArr) {
Preconditions.checkNotNull(objArr);
return new AbstractList<Object>(objArr, obj, obj2) { // from class: com.google.common.base.Joiner.3
final Object val$first;
final Object[] val$rest;
final Object val$second;
{
this.val$rest = objArr;
this.val$first = obj;
this.val$second = obj2;
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public int size() {
return this.val$rest.length + 2;
}
@Override // java.util.AbstractList, java.util.List
public Object get(int i) {
return i != 0 ? i != 1 ? this.val$rest[i - 2] : this.val$second : this.val$first;
}
};
}
}