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: classes3.dex */ public abstract class ImmutableList extends ImmutableCollection implements List, RandomAccess { public static final UnmodifiableListIterator EMPTY_ITR = new Itr(RegularImmutableList.EMPTY, 0); @Override // com.google.common.collect.ImmutableCollection public final ImmutableList asList() { return this; } public static ImmutableList of() { return RegularImmutableList.EMPTY; } public static ImmutableList of(Object obj) { return construct(obj); } public static ImmutableList of(Object obj, Object obj2) { return construct(obj, obj2); } public static ImmutableList of(Object obj, Object obj2, Object obj3) { return construct(obj, obj2, obj3); } public static ImmutableList of(Object obj, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6, Object obj7) { return construct(obj, obj2, obj3, obj4, obj5, obj6, obj7); } public static ImmutableList copyOf(Collection collection) { if (collection instanceof ImmutableCollection) { ImmutableList asList = ((ImmutableCollection) collection).asList(); return asList.isPartialView() ? asImmutableList(asList.toArray()) : asList; } return construct(collection.toArray()); } public static ImmutableList copyOf(Object[] objArr) { if (objArr.length == 0) { return of(); } return construct((Object[]) objArr.clone()); } public static ImmutableList sortedCopyOf(Comparator comparator, Iterable iterable) { Preconditions.checkNotNull(comparator); Object[] array = Iterables.toArray(iterable); ObjectArrays.checkElementsNotNull(array); Arrays.sort(array, comparator); return asImmutableList(array); } public static ImmutableList construct(Object... objArr) { return asImmutableList(ObjectArrays.checkElementsNotNull(objArr)); } public static ImmutableList asImmutableList(Object[] objArr) { return asImmutableList(objArr, objArr.length); } public static ImmutableList asImmutableList(Object[] objArr, int i) { if (i == 0) { return of(); } return new RegularImmutableList(objArr, i); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List public UnmodifiableIterator iterator() { return listIterator(); } @Override // java.util.List public UnmodifiableListIterator listIterator() { return listIterator(0); } @Override // java.util.List public UnmodifiableListIterator listIterator(int i) { Preconditions.checkPositionIndex(i, size()); return isEmpty() ? EMPTY_ITR : new Itr(this, i); } public static class Itr extends AbstractIndexedListIterator { public final ImmutableList list; public Itr(ImmutableList immutableList, int i) { super(immutableList.size(), i); this.list = immutableList; } @Override // com.google.common.collect.AbstractIndexedListIterator public Object get(int i) { return this.list.get(i); } } @Override // java.util.List public int indexOf(Object obj) { if (obj == null) { return -1; } return Lists.indexOfImpl(this, obj); } @Override // java.util.List public int lastIndexOf(Object obj) { if (obj == null) { return -1; } return Lists.lastIndexOfImpl(this, obj); } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection public boolean contains(Object obj) { return indexOf(obj) >= 0; } @Override // java.util.List public ImmutableList subList(int i, int i2) { Preconditions.checkPositionIndexes(i, i2, size()); int i3 = i2 - i; if (i3 == size()) { return this; } if (i3 == 0) { return of(); } return subListUnchecked(i, i2); } public ImmutableList subListUnchecked(int i, int i2) { return new SubList(i, i2 - i); } public class SubList extends ImmutableList { public final transient int length; public final transient int offset; @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.length; } @Override // com.google.common.collect.ImmutableList, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List 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 // com.google.common.collect.ImmutableList, java.util.List public /* bridge */ /* synthetic */ ListIterator listIterator(int i) { return super.listIterator(i); } public SubList(int i, int i2) { this.offset = i; this.length = i2; } @Override // com.google.common.collect.ImmutableCollection public Object[] internalArray() { return ImmutableList.this.internalArray(); } @Override // com.google.common.collect.ImmutableCollection public int internalArrayStart() { return ImmutableList.this.internalArrayStart() + this.offset; } @Override // com.google.common.collect.ImmutableCollection public int internalArrayEnd() { return ImmutableList.this.internalArrayStart() + this.offset + this.length; } @Override // java.util.List public Object get(int i) { Preconditions.checkElementIndex(i, this.length); return ImmutableList.this.get(i + this.offset); } @Override // com.google.common.collect.ImmutableList, java.util.List public ImmutableList subList(int i, int i2) { Preconditions.checkPositionIndexes(i, i2, this.length); ImmutableList immutableList = ImmutableList.this; int i3 = this.offset; return immutableList.subList(i + i3, i2 + i3); } } @Override // java.util.List public final boolean addAll(int i, Collection collection) { throw new UnsupportedOperationException(); } @Override // java.util.List public final Object set(int i, Object obj) { throw new UnsupportedOperationException(); } @Override // java.util.List public final void add(int i, Object obj) { throw new UnsupportedOperationException(); } @Override // java.util.List public final Object remove(int i) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ImmutableCollection public int copyIntoArray(Object[] objArr, int i) { int size = size(); for (int i2 = 0; i2 < size; i2++) { objArr[i + i2] = get(i2); } return i + size; } public ImmutableList reverse() { return size() <= 1 ? this : new ReverseImmutableList(this); } public static class ReverseImmutableList extends ImmutableList { public final transient ImmutableList forwardList; @Override // com.google.common.collect.ImmutableList public ImmutableList reverse() { return this.forwardList; } @Override // com.google.common.collect.ImmutableList, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List 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 // com.google.common.collect.ImmutableList, java.util.List public /* bridge */ /* synthetic */ ListIterator listIterator(int i) { return super.listIterator(i); } public ReverseImmutableList(ImmutableList immutableList) { this.forwardList = immutableList; } public final int reverseIndex(int i) { return (size() - 1) - i; } public final int reversePosition(int i) { return size() - i; } @Override // com.google.common.collect.ImmutableList, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection public boolean contains(Object obj) { return this.forwardList.contains(obj); } @Override // com.google.common.collect.ImmutableList, java.util.List public int indexOf(Object obj) { int lastIndexOf = this.forwardList.lastIndexOf(obj); if (lastIndexOf >= 0) { return reverseIndex(lastIndexOf); } return -1; } @Override // com.google.common.collect.ImmutableList, java.util.List public int lastIndexOf(Object obj) { int indexOf = this.forwardList.indexOf(obj); if (indexOf >= 0) { return reverseIndex(indexOf); } return -1; } @Override // com.google.common.collect.ImmutableList, java.util.List public ImmutableList subList(int i, int i2) { Preconditions.checkPositionIndexes(i, i2, size()); return this.forwardList.subList(reversePosition(i2), reversePosition(i)).reverse(); } @Override // java.util.List public Object get(int i) { Preconditions.checkElementIndex(i, size()); return this.forwardList.get(reverseIndex(i)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.forwardList.size(); } @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return this.forwardList.isPartialView(); } } @Override // java.util.Collection, java.util.List public boolean equals(Object obj) { return Lists.equalsImpl(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; } public static class SerializedForm implements Serializable { private static final long serialVersionUID = 0; public final Object[] elements; public SerializedForm(Object[] objArr) { this.elements = objArr; } public Object readResolve() { return ImmutableList.copyOf(this.elements); } } private void readObject(ObjectInputStream objectInputStream) throws InvalidObjectException { throw new InvalidObjectException("Use SerializedForm"); } @Override // com.google.common.collect.ImmutableCollection public Object writeReplace() { return new SerializedForm(toArray()); } public static final class Builder extends ImmutableCollection.ArrayBasedBuilder { public Builder() { this(4); } public Builder(int i) { super(i); } @Override // com.google.common.collect.ImmutableCollection.ArrayBasedBuilder public Builder add(Object... objArr) { super.add(objArr); return this; } public ImmutableList build() { this.forceCopy = true; return ImmutableList.asImmutableList(this.contents, this.size); } } }