153 lines
5.4 KiB
Java
153 lines
5.4 KiB
Java
|
package com.google.common.collect;
|
||
|
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import com.google.common.collect.ImmutableList;
|
||
|
import com.google.common.math.IntMath;
|
||
|
import java.util.AbstractList;
|
||
|
import java.util.Collection;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.List;
|
||
|
import java.util.ListIterator;
|
||
|
import java.util.RandomAccess;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class CartesianList<E> extends AbstractList<List<E>> implements RandomAccess {
|
||
|
private final transient ImmutableList<List<E>> axes;
|
||
|
private final transient int[] axesSizeProduct;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static <E> List<List<E>> create(List<? extends List<? extends E>> list) {
|
||
|
ImmutableList.Builder builder = new ImmutableList.Builder(list.size());
|
||
|
Iterator<? extends List<? extends E>> it = list.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
ImmutableList copyOf = ImmutableList.copyOf((Collection) it.next());
|
||
|
if (copyOf.isEmpty()) {
|
||
|
return ImmutableList.of();
|
||
|
}
|
||
|
builder.add((ImmutableList.Builder) copyOf);
|
||
|
}
|
||
|
return new CartesianList(builder.build());
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public CartesianList(ImmutableList<List<E>> immutableList) {
|
||
|
this.axes = immutableList;
|
||
|
int[] iArr = new int[immutableList.size() + 1];
|
||
|
iArr[immutableList.size()] = 1;
|
||
|
try {
|
||
|
for (int size = immutableList.size() - 1; size >= 0; size--) {
|
||
|
iArr[size] = IntMath.checkedMultiply(iArr[size + 1], immutableList.get(size).size());
|
||
|
}
|
||
|
this.axesSizeProduct = iArr;
|
||
|
} catch (ArithmeticException unused) {
|
||
|
throw new IllegalArgumentException("Cartesian product too large; must have size at most Integer.MAX_VALUE");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public int getAxisIndexForProductIndex(int i, int i2) {
|
||
|
return (i / this.axesSizeProduct[i2 + 1]) % this.axes.get(i2).size();
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public final int indexOf(Object obj) {
|
||
|
if (!(obj instanceof List)) {
|
||
|
return -1;
|
||
|
}
|
||
|
List list = (List) obj;
|
||
|
if (list.size() != this.axes.size()) {
|
||
|
return -1;
|
||
|
}
|
||
|
ListIterator<E> listIterator = list.listIterator();
|
||
|
int i = 0;
|
||
|
while (listIterator.hasNext()) {
|
||
|
int nextIndex = listIterator.nextIndex();
|
||
|
int indexOf = this.axes.get(nextIndex).indexOf(listIterator.next());
|
||
|
if (indexOf == -1) {
|
||
|
return -1;
|
||
|
}
|
||
|
i += indexOf * this.axesSizeProduct[nextIndex + 1];
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public final int lastIndexOf(Object obj) {
|
||
|
if (!(obj instanceof List)) {
|
||
|
return -1;
|
||
|
}
|
||
|
List list = (List) obj;
|
||
|
if (list.size() != this.axes.size()) {
|
||
|
return -1;
|
||
|
}
|
||
|
ListIterator<E> listIterator = list.listIterator();
|
||
|
int i = 0;
|
||
|
while (listIterator.hasNext()) {
|
||
|
int nextIndex = listIterator.nextIndex();
|
||
|
int lastIndexOf = this.axes.get(nextIndex).lastIndexOf(listIterator.next());
|
||
|
if (lastIndexOf == -1) {
|
||
|
return -1;
|
||
|
}
|
||
|
i += lastIndexOf * this.axesSizeProduct[nextIndex + 1];
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public final ImmutableList<E> get(int i) {
|
||
|
Preconditions.checkElementIndex(i, size());
|
||
|
return new ImmutableList<E>(this, i) { // from class: com.google.common.collect.CartesianList.1
|
||
|
final CartesianList this$0;
|
||
|
final int val$index;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
@Override // com.google.common.collect.ImmutableCollection
|
||
|
public boolean isPartialView() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.this$0 = this;
|
||
|
this.val$index = i;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
||
|
public int size() {
|
||
|
return this.this$0.axes.size();
|
||
|
}
|
||
|
|
||
|
@Override // java.util.List
|
||
|
public E get(int i2) {
|
||
|
Preconditions.checkElementIndex(i2, size());
|
||
|
return (E) ((List) this.this$0.axes.get(i2)).get(this.this$0.getAxisIndexForProductIndex(this.val$index, i2));
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
||
|
public final int size() {
|
||
|
return this.axesSizeProduct[0];
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
||
|
public final boolean contains(Object obj) {
|
||
|
if (!(obj instanceof List)) {
|
||
|
return false;
|
||
|
}
|
||
|
List list = (List) obj;
|
||
|
if (list.size() != this.axes.size()) {
|
||
|
return false;
|
||
|
}
|
||
|
Iterator<E> it = list.iterator();
|
||
|
int i = 0;
|
||
|
while (it.hasNext()) {
|
||
|
if (!this.axes.get(i).contains(it.next())) {
|
||
|
return false;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
}
|