449 lines
14 KiB
Java
449 lines
14 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.collect.ImmutableCollection;
|
|
import java.io.InvalidObjectException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.Serializable;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Comparator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.ListIterator;
|
|
import java.util.RandomAccess;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class ImmutableList<E> extends ImmutableCollection<E> implements List<E>, RandomAccess {
|
|
|
|
public static final class Builder<E> extends ImmutableCollection.ArrayBasedBuilder<E> {
|
|
public Builder() {
|
|
this(4);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableCollection.Builder
|
|
public /* bridge */ /* synthetic */ ImmutableCollection.Builder a(Object obj) {
|
|
a((Builder<E>) obj);
|
|
return this;
|
|
}
|
|
|
|
Builder(int i) {
|
|
super(i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder
|
|
public Builder<E> a(E e) {
|
|
super.a((Builder<E>) e);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection.Builder
|
|
public Builder<E> a(Iterator<? extends E> it) {
|
|
super.a((Iterator) it);
|
|
return this;
|
|
}
|
|
|
|
public ImmutableList<E> a() {
|
|
this.c = true;
|
|
return ImmutableList.asImmutableList(this.a, this.b);
|
|
}
|
|
}
|
|
|
|
private static class ReverseImmutableList<E> extends ImmutableList<E> {
|
|
private final transient ImmutableList<E> a;
|
|
|
|
ReverseImmutableList(ImmutableList<E> immutableList) {
|
|
this.a = immutableList;
|
|
}
|
|
|
|
private int c(int i) {
|
|
return (size() - 1) - i;
|
|
}
|
|
|
|
private int d(int i) {
|
|
return size() - i;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
return this.a.contains(obj);
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public E get(int i) {
|
|
Preconditions.a(i, size());
|
|
return this.a.get(c(i));
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public int indexOf(Object obj) {
|
|
int lastIndexOf = this.a.lastIndexOf(obj);
|
|
if (lastIndexOf >= 0) {
|
|
return c(lastIndexOf);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return this.a.isPartialView();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet
|
|
public /* bridge */ /* synthetic */ Iterator iterator() {
|
|
return super.iterator();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public int lastIndexOf(Object obj) {
|
|
int indexOf = this.a.indexOf(obj);
|
|
if (indexOf >= 0) {
|
|
return c(indexOf);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public /* bridge */ /* synthetic */ ListIterator listIterator() {
|
|
return super.listIterator();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList
|
|
public ImmutableList<E> reverse() {
|
|
return this.a;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
|
public int size() {
|
|
return this.a.size();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public /* bridge */ /* synthetic */ ListIterator listIterator(int i) {
|
|
return super.listIterator(i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public ImmutableList<E> subList(int i, int i2) {
|
|
Preconditions.b(i, i2, size());
|
|
return this.a.subList(d(i2), d(i)).reverse();
|
|
}
|
|
}
|
|
|
|
static class SerializedForm implements Serializable {
|
|
final Object[] a;
|
|
|
|
SerializedForm(Object[] objArr) {
|
|
this.a = objArr;
|
|
}
|
|
|
|
Object readResolve() {
|
|
return ImmutableList.copyOf(this.a);
|
|
}
|
|
}
|
|
|
|
class SubList extends ImmutableList<E> {
|
|
final transient int a;
|
|
final transient int b;
|
|
|
|
SubList(int i, int i2) {
|
|
this.a = i;
|
|
this.b = i2;
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public E get(int i) {
|
|
Preconditions.a(i, this.b);
|
|
return ImmutableList.this.get(i + this.a);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return true;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet
|
|
public /* bridge */ /* synthetic */ Iterator iterator() {
|
|
return super.iterator();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public /* bridge */ /* synthetic */ ListIterator listIterator() {
|
|
return super.listIterator();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
|
public int size() {
|
|
return this.b;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public /* bridge */ /* synthetic */ ListIterator listIterator(int i) {
|
|
return super.listIterator(i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableList, java.util.List
|
|
public ImmutableList<E> subList(int i, int i2) {
|
|
Preconditions.b(i, i2, this.b);
|
|
ImmutableList immutableList = ImmutableList.this;
|
|
int i3 = this.a;
|
|
return immutableList.subList(i + i3, i2 + i3);
|
|
}
|
|
}
|
|
|
|
ImmutableList() {
|
|
}
|
|
|
|
static <E> ImmutableList<E> asImmutableList(Object[] objArr) {
|
|
return asImmutableList(objArr, objArr.length);
|
|
}
|
|
|
|
public static <E> Builder<E> builder() {
|
|
return new Builder<>();
|
|
}
|
|
|
|
private static <E> ImmutableList<E> construct(Object... objArr) {
|
|
ObjectArrays.a(objArr);
|
|
return asImmutableList(objArr);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> copyOf(Iterable<? extends E> iterable) {
|
|
Preconditions.a(iterable);
|
|
return iterable instanceof Collection ? copyOf((Collection) iterable) : copyOf(iterable.iterator());
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of() {
|
|
return (ImmutableList<E>) RegularImmutableList.c;
|
|
}
|
|
|
|
private void readObject(ObjectInputStream objectInputStream) throws InvalidObjectException {
|
|
throw new InvalidObjectException("Use SerializedForm");
|
|
}
|
|
|
|
public static <E extends Comparable<? super E>> ImmutableList<E> sortedCopyOf(Iterable<? extends E> iterable) {
|
|
Comparable[] comparableArr = (Comparable[]) Iterables.a((Iterable) iterable, (Object[]) new Comparable[0]);
|
|
ObjectArrays.a(comparableArr);
|
|
Arrays.sort(comparableArr);
|
|
return asImmutableList(comparableArr);
|
|
}
|
|
|
|
@Override // java.util.List
|
|
@Deprecated
|
|
public final void add(int i, E e) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // java.util.List
|
|
@Deprecated
|
|
public final boolean addAll(int i, Collection<? extends E> collection) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
public final ImmutableList<E> asList() {
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
return indexOf(obj) >= 0;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
int copyIntoArray(Object[] objArr, int i) {
|
|
int size = size();
|
|
for (int i2 = 0; i2 < size; i2++) {
|
|
objArr[i + i2] = get(i2);
|
|
}
|
|
return i + size;
|
|
}
|
|
|
|
@Override // java.util.Collection, java.util.List
|
|
public boolean equals(Object obj) {
|
|
return Lists.a(this, obj);
|
|
}
|
|
|
|
@Override // java.util.Collection, java.util.List
|
|
public int hashCode() {
|
|
int size = size();
|
|
int i = 1;
|
|
for (int i2 = 0; i2 < size; i2++) {
|
|
i = ~(~((i * 31) + get(i2).hashCode()));
|
|
}
|
|
return i;
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public int indexOf(Object obj) {
|
|
if (obj == null) {
|
|
return -1;
|
|
}
|
|
return Lists.b(this, obj);
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public int lastIndexOf(Object obj) {
|
|
if (obj == null) {
|
|
return -1;
|
|
}
|
|
return Lists.d(this, obj);
|
|
}
|
|
|
|
@Override // java.util.List
|
|
@Deprecated
|
|
public final E remove(int i) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public ImmutableList<E> reverse() {
|
|
return size() <= 1 ? this : new ReverseImmutableList(this);
|
|
}
|
|
|
|
@Override // java.util.List
|
|
@Deprecated
|
|
public final E set(int i, E e) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
ImmutableList<E> subListUnchecked(int i, int i2) {
|
|
return new SubList(i, i2 - i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
Object writeReplace() {
|
|
return new SerializedForm(toArray());
|
|
}
|
|
|
|
static <E> ImmutableList<E> asImmutableList(Object[] objArr, int i) {
|
|
return i == 0 ? of() : new RegularImmutableList(objArr, i);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e) {
|
|
return construct(e);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet
|
|
public UnmodifiableIterator<E> iterator() {
|
|
return listIterator();
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public ImmutableList<E> subList(int i, int i2) {
|
|
Preconditions.b(i, i2, size());
|
|
int i3 = i2 - i;
|
|
return i3 == size() ? this : i3 == 0 ? of() : subListUnchecked(i, i2);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2) {
|
|
return construct(e, e2);
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public UnmodifiableListIterator<E> listIterator() {
|
|
return listIterator(0);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3) {
|
|
return construct(e, e2, e3);
|
|
}
|
|
|
|
@Override // java.util.List
|
|
public UnmodifiableListIterator<E> listIterator(int i) {
|
|
return new AbstractIndexedListIterator<E>(size(), i) { // from class: com.google.common.collect.ImmutableList.1
|
|
@Override // com.google.common.collect.AbstractIndexedListIterator
|
|
protected E a(int i2) {
|
|
return ImmutableList.this.get(i2);
|
|
}
|
|
};
|
|
}
|
|
|
|
public static <E> ImmutableList<E> copyOf(Collection<? extends E> collection) {
|
|
if (collection instanceof ImmutableCollection) {
|
|
ImmutableList<E> asList = ((ImmutableCollection) collection).asList();
|
|
return asList.isPartialView() ? asImmutableList(asList.toArray()) : asList;
|
|
}
|
|
return construct(collection.toArray());
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4) {
|
|
return construct(e, e2, e3, e4);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> sortedCopyOf(Comparator<? super E> comparator, Iterable<? extends E> iterable) {
|
|
Preconditions.a(comparator);
|
|
Object[] e = Iterables.e(iterable);
|
|
ObjectArrays.a(e);
|
|
Arrays.sort(e, comparator);
|
|
return asImmutableList(e);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5) {
|
|
return construct(e, e2, e3, e4, e5);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5, E e6) {
|
|
return construct(e, e2, e3, e4, e5, e6);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5, E e6, E e7) {
|
|
return construct(e, e2, e3, e4, e5, e6, e7);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> copyOf(Iterator<? extends E> it) {
|
|
if (!it.hasNext()) {
|
|
return of();
|
|
}
|
|
E next = it.next();
|
|
if (!it.hasNext()) {
|
|
return of((Object) next);
|
|
}
|
|
Builder builder = new Builder();
|
|
builder.a((Builder) next);
|
|
builder.a((Iterator) it);
|
|
return builder.a();
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5, E e6, E e7, E e8) {
|
|
return construct(e, e2, e3, e4, e5, e6, e7, e8);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) {
|
|
return construct(e, e2, e3, e4, e5, e6, e7, e8, e9);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) {
|
|
return construct(e, e2, e3, e4, e5, e6, e7, e8, e9, e10);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11) {
|
|
return construct(e, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11);
|
|
}
|
|
|
|
@SafeVarargs
|
|
public static <E> ImmutableList<E> of(E e, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11, E e12, E... eArr) {
|
|
Object[] objArr = new Object[eArr.length + 12];
|
|
objArr[0] = e;
|
|
objArr[1] = e2;
|
|
objArr[2] = e3;
|
|
objArr[3] = e4;
|
|
objArr[4] = e5;
|
|
objArr[5] = e6;
|
|
objArr[6] = e7;
|
|
objArr[7] = e8;
|
|
objArr[8] = e9;
|
|
objArr[9] = e10;
|
|
objArr[10] = e11;
|
|
objArr[11] = e12;
|
|
System.arraycopy(eArr, 0, objArr, 12, eArr.length);
|
|
return construct(objArr);
|
|
}
|
|
|
|
public static <E> ImmutableList<E> copyOf(E[] eArr) {
|
|
if (eArr.length == 0) {
|
|
return of();
|
|
}
|
|
return construct((Object[]) eArr.clone());
|
|
}
|
|
}
|