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

411 lines
16 KiB
Java

package com.google.common.base;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
/* loaded from: classes2.dex */
public final class Splitter {
private final int limit;
private final boolean omitEmptyStrings;
private final Strategy strategy;
private final CharMatcher trimmer;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public interface Strategy {
Iterator<String> iterator(Splitter splitter, CharSequence charSequence);
}
private Splitter(Strategy strategy) {
this(strategy, false, CharMatcher.none(), Integer.MAX_VALUE);
}
private Splitter(Strategy strategy, boolean z, CharMatcher charMatcher, int i) {
this.strategy = strategy;
this.omitEmptyStrings = z;
this.trimmer = charMatcher;
this.limit = i;
}
public static Splitter on(char c) {
return on(CharMatcher.is(c));
}
public static Splitter on(CharMatcher charMatcher) {
Preconditions.checkNotNull(charMatcher);
return new Splitter(new AnonymousClass1(charMatcher));
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.google.common.base.Splitter$1, reason: invalid class name */
/* loaded from: classes2.dex */
public class AnonymousClass1 implements Strategy {
final CharMatcher val$separatorMatcher;
AnonymousClass1(CharMatcher charMatcher) {
this.val$separatorMatcher = charMatcher;
}
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
return new SplittingIterator(this, splitter, charSequence) { // from class: com.google.common.base.Splitter.1.1
final AnonymousClass1 this$0;
@Override // com.google.common.base.Splitter.SplittingIterator
int separatorEnd(int i) {
return i + 1;
}
{
this.this$0 = this;
}
@Override // com.google.common.base.Splitter.SplittingIterator
int separatorStart(int i) {
return this.this$0.val$separatorMatcher.indexIn(this.toSplit, i);
}
};
}
}
public static Splitter on(String str) {
Preconditions.checkArgument(str.length() != 0, "The separator may not be the empty string.");
if (str.length() == 1) {
return on(str.charAt(0));
}
return new Splitter(new AnonymousClass2(str));
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.google.common.base.Splitter$2, reason: invalid class name */
/* loaded from: classes2.dex */
public class AnonymousClass2 implements Strategy {
final String val$separator;
AnonymousClass2(String str) {
this.val$separator = str;
}
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
return new SplittingIterator(this, splitter, charSequence) { // from class: com.google.common.base.Splitter.2.1
final AnonymousClass2 this$0;
{
this.this$0 = this;
}
/* JADX WARN: Code restructure failed: missing block: B:10:0x0027, code lost:
r6 = r6 + 1;
*/
@Override // com.google.common.base.Splitter.SplittingIterator
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public int separatorStart(int r6) {
/*
r5 = this;
com.google.common.base.Splitter$2 r0 = r5.this$0
java.lang.String r0 = r0.val$separator
int r0 = r0.length()
java.lang.CharSequence r1 = r5.toSplit
int r1 = r1.length()
Le:
int r2 = r1 - r0
if (r6 > r2) goto L2e
r2 = 0
L13:
if (r2 >= r0) goto L2d
java.lang.CharSequence r3 = r5.toSplit
int r4 = r2 + r6
char r3 = r3.charAt(r4)
com.google.common.base.Splitter$2 r4 = r5.this$0
java.lang.String r4 = r4.val$separator
char r4 = r4.charAt(r2)
if (r3 == r4) goto L2a
int r6 = r6 + 1
goto Le
L2a:
int r2 = r2 + 1
goto L13
L2d:
return r6
L2e:
r6 = -1
return r6
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.base.Splitter.AnonymousClass2.AnonymousClass1.separatorStart(int):int");
}
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorEnd(int i) {
return i + this.this$0.val$separator.length();
}
};
}
}
public static Splitter on(Pattern pattern) {
return on(new JdkPattern(pattern));
}
private static Splitter on(CommonPattern commonPattern) {
Preconditions.checkArgument(!commonPattern.matcher("").matches(), "The pattern may not match the empty string: %s", commonPattern);
return new Splitter(new Strategy(commonPattern) { // from class: com.google.common.base.Splitter.3
final CommonPattern val$separatorPattern;
{
this.val$separatorPattern = commonPattern;
}
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
return new SplittingIterator(this, splitter, charSequence, this.val$separatorPattern.matcher(charSequence)) { // from class: com.google.common.base.Splitter.3.1
final CommonMatcher val$matcher;
{
this.val$matcher = r4;
}
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorStart(int i) {
if (this.val$matcher.find(i)) {
return this.val$matcher.start();
}
return -1;
}
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorEnd(int i) {
return this.val$matcher.end();
}
};
}
});
}
public static Splitter onPattern(String str) {
return on(Platform.compilePattern(str));
}
public static Splitter fixedLength(int i) {
Preconditions.checkArgument(i > 0, "The length may not be less than 1");
return new Splitter(new AnonymousClass4(i));
}
/* renamed from: com.google.common.base.Splitter$4, reason: invalid class name */
/* loaded from: classes2.dex */
class AnonymousClass4 implements Strategy {
final int val$length;
AnonymousClass4(int i) {
this.val$length = i;
}
@Override // com.google.common.base.Splitter.Strategy
public SplittingIterator iterator(Splitter splitter, CharSequence charSequence) {
return new SplittingIterator(this, splitter, charSequence) { // from class: com.google.common.base.Splitter.4.1
final AnonymousClass4 this$0;
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorEnd(int i) {
return i;
}
{
this.this$0 = this;
}
@Override // com.google.common.base.Splitter.SplittingIterator
public int separatorStart(int i) {
int i2 = i + this.this$0.val$length;
if (i2 >= this.toSplit.length()) {
return -1;
}
return i2;
}
};
}
}
public final Splitter omitEmptyStrings() {
return new Splitter(this.strategy, true, this.trimmer, this.limit);
}
public final Splitter limit(int i) {
Preconditions.checkArgument(i > 0, "must be greater than zero: %s", i);
return new Splitter(this.strategy, this.omitEmptyStrings, this.trimmer, i);
}
public final Splitter trimResults() {
return trimResults(CharMatcher.whitespace());
}
public final Splitter trimResults(CharMatcher charMatcher) {
Preconditions.checkNotNull(charMatcher);
return new Splitter(this.strategy, this.omitEmptyStrings, charMatcher, this.limit);
}
public final Iterable<String> split(CharSequence charSequence) {
Preconditions.checkNotNull(charSequence);
return new Iterable<String>(this, charSequence) { // from class: com.google.common.base.Splitter.5
final Splitter this$0;
final CharSequence val$sequence;
{
this.this$0 = this;
this.val$sequence = charSequence;
}
@Override // java.lang.Iterable
public Iterator<String> iterator() {
return this.this$0.splittingIterator(this.val$sequence);
}
public String toString() {
Joiner on = Joiner.on(", ");
StringBuilder sb = new StringBuilder();
sb.append('[');
StringBuilder appendTo = on.appendTo(sb, (Iterable<?>) this);
appendTo.append(']');
return appendTo.toString();
}
};
}
/* JADX INFO: Access modifiers changed from: private */
public Iterator<String> splittingIterator(CharSequence charSequence) {
return this.strategy.iterator(this, charSequence);
}
public final List<String> splitToList(CharSequence charSequence) {
Preconditions.checkNotNull(charSequence);
Iterator<String> splittingIterator = splittingIterator(charSequence);
ArrayList arrayList = new ArrayList();
while (splittingIterator.hasNext()) {
arrayList.add(splittingIterator.next());
}
return Collections.unmodifiableList(arrayList);
}
public final MapSplitter withKeyValueSeparator(String str) {
return withKeyValueSeparator(on(str));
}
public final MapSplitter withKeyValueSeparator(char c) {
return withKeyValueSeparator(on(c));
}
public final MapSplitter withKeyValueSeparator(Splitter splitter) {
return new MapSplitter(this, splitter, null);
}
/* loaded from: classes2.dex */
public static final class MapSplitter {
private static final String INVALID_ENTRY_MESSAGE = "Chunk [%s] is not a valid entry";
private final Splitter entrySplitter;
private final Splitter outerSplitter;
/* synthetic */ MapSplitter(Splitter splitter, Splitter splitter2, AnonymousClass1 anonymousClass1) {
this(splitter, splitter2);
}
private MapSplitter(Splitter splitter, Splitter splitter2) {
this.outerSplitter = splitter;
this.entrySplitter = (Splitter) Preconditions.checkNotNull(splitter2);
}
public final Map<String, String> split(CharSequence charSequence) {
LinkedHashMap linkedHashMap = new LinkedHashMap();
for (String str : this.outerSplitter.split(charSequence)) {
Iterator splittingIterator = this.entrySplitter.splittingIterator(str);
Preconditions.checkArgument(splittingIterator.hasNext(), INVALID_ENTRY_MESSAGE, str);
String str2 = (String) splittingIterator.next();
Preconditions.checkArgument(!linkedHashMap.containsKey(str2), "Duplicate key [%s] found.", str2);
Preconditions.checkArgument(splittingIterator.hasNext(), INVALID_ENTRY_MESSAGE, str);
linkedHashMap.put(str2, (String) splittingIterator.next());
Preconditions.checkArgument(!splittingIterator.hasNext(), INVALID_ENTRY_MESSAGE, str);
}
return Collections.unmodifiableMap(linkedHashMap);
}
}
/* loaded from: classes2.dex */
static abstract class SplittingIterator extends AbstractIterator<String> {
int limit;
int offset = 0;
final boolean omitEmptyStrings;
final CharSequence toSplit;
final CharMatcher trimmer;
abstract int separatorEnd(int i);
abstract int separatorStart(int i);
protected SplittingIterator(Splitter splitter, CharSequence charSequence) {
this.trimmer = splitter.trimmer;
this.omitEmptyStrings = splitter.omitEmptyStrings;
this.limit = splitter.limit;
this.toSplit = charSequence;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.base.AbstractIterator
public String computeNext() {
int separatorStart;
int i = this.offset;
while (true) {
int i2 = this.offset;
if (i2 != -1) {
separatorStart = separatorStart(i2);
if (separatorStart == -1) {
separatorStart = this.toSplit.length();
this.offset = -1;
} else {
this.offset = separatorEnd(separatorStart);
}
int i3 = this.offset;
if (i3 == i) {
int i4 = i3 + 1;
this.offset = i4;
if (i4 > this.toSplit.length()) {
this.offset = -1;
}
} else {
while (i < separatorStart && this.trimmer.matches(this.toSplit.charAt(i))) {
i++;
}
while (separatorStart > i && this.trimmer.matches(this.toSplit.charAt(separatorStart - 1))) {
separatorStart--;
}
if (!this.omitEmptyStrings || i != separatorStart) {
break;
}
i = this.offset;
}
} else {
return endOfData();
}
}
int i5 = this.limit;
if (i5 == 1) {
separatorStart = this.toSplit.length();
this.offset = -1;
while (separatorStart > i && this.trimmer.matches(this.toSplit.charAt(separatorStart - 1))) {
separatorStart--;
}
} else {
this.limit = i5 - 1;
}
return this.toSplit.subSequence(i, separatorStart).toString();
}
}
}