package com.google.common.collect; import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.math.IntMath; import com.google.common.primitives.Ints; import java.io.Serializable; import java.math.RoundingMode; import java.util.AbstractList; import java.util.AbstractSequentialList; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.RandomAccess; import java.util.concurrent.CopyOnWriteArrayList; /* loaded from: classes2.dex */ public final class Lists { private Lists() { } public static ArrayList newArrayList() { return new ArrayList<>(); } @SafeVarargs public static ArrayList newArrayList(E... eArr) { Preconditions.checkNotNull(eArr); ArrayList arrayList = new ArrayList<>(computeArrayListCapacity(eArr.length)); Collections.addAll(arrayList, eArr); return arrayList; } public static ArrayList newArrayList(Iterable iterable) { Preconditions.checkNotNull(iterable); if (iterable instanceof Collection) { return new ArrayList<>((Collection) iterable); } return newArrayList(iterable.iterator()); } public static ArrayList newArrayList(Iterator it) { ArrayList newArrayList = newArrayList(); Iterators.addAll(newArrayList, it); return newArrayList; } static int computeArrayListCapacity(int i) { CollectPreconditions.checkNonnegative(i, "arraySize"); return Ints.saturatedCast(i + 5 + (i / 10)); } public static ArrayList newArrayListWithCapacity(int i) { CollectPreconditions.checkNonnegative(i, "initialArraySize"); return new ArrayList<>(i); } public static ArrayList newArrayListWithExpectedSize(int i) { return new ArrayList<>(computeArrayListCapacity(i)); } public static LinkedList newLinkedList() { return new LinkedList<>(); } public static LinkedList newLinkedList(Iterable iterable) { LinkedList newLinkedList = newLinkedList(); Iterables.addAll(newLinkedList, iterable); return newLinkedList; } public static CopyOnWriteArrayList newCopyOnWriteArrayList() { return new CopyOnWriteArrayList<>(); } public static CopyOnWriteArrayList newCopyOnWriteArrayList(Iterable iterable) { Collection newArrayList; if (iterable instanceof Collection) { newArrayList = (Collection) iterable; } else { newArrayList = newArrayList(iterable); } return new CopyOnWriteArrayList<>(newArrayList); } public static List asList(E e, E[] eArr) { return new OnePlusArrayList(e, eArr); } public static List asList(E e, E e2, E[] eArr) { return new TwoPlusArrayList(e, e2, eArr); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class OnePlusArrayList extends AbstractList implements Serializable, RandomAccess { private static final long serialVersionUID = 0; final E first; final E[] rest; OnePlusArrayList(E e, E[] eArr) { this.first = e; this.rest = (E[]) ((Object[]) Preconditions.checkNotNull(eArr)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return IntMath.saturatedAdd(this.rest.length, 1); } @Override // java.util.AbstractList, java.util.List public E get(int i) { Preconditions.checkElementIndex(i, size()); return i == 0 ? this.first : this.rest[i - 1]; } } /* loaded from: classes2.dex */ static class TwoPlusArrayList extends AbstractList implements Serializable, RandomAccess { private static final long serialVersionUID = 0; final E first; final E[] rest; final E second; TwoPlusArrayList(E e, E e2, E[] eArr) { this.first = e; this.second = e2; this.rest = (E[]) ((Object[]) Preconditions.checkNotNull(eArr)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return IntMath.saturatedAdd(this.rest.length, 2); } @Override // java.util.AbstractList, java.util.List public E get(int i) { if (i == 0) { return this.first; } if (i == 1) { return this.second; } Preconditions.checkElementIndex(i, size()); return this.rest[i - 2]; } } public static List> cartesianProduct(List> list) { return CartesianList.create(list); } @SafeVarargs public static List> cartesianProduct(List... listArr) { return cartesianProduct(Arrays.asList(listArr)); } public static List transform(List list, Function function) { if (list instanceof RandomAccess) { return new TransformingRandomAccessList(list, function); } return new TransformingSequentialList(list, function); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class TransformingSequentialList extends AbstractSequentialList implements Serializable { private static final long serialVersionUID = 0; final List fromList; final Function function; TransformingSequentialList(List list, Function function) { this.fromList = (List) Preconditions.checkNotNull(list); this.function = (Function) Preconditions.checkNotNull(function); } @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List public void clear() { this.fromList.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.fromList.size(); } @Override // java.util.AbstractSequentialList, java.util.AbstractList, java.util.List public ListIterator listIterator(int i) { return new TransformedListIterator(this, this.fromList.listIterator(i)) { // from class: com.google.common.collect.Lists.TransformingSequentialList.1 final TransformingSequentialList this$0; { this.this$0 = this; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.TransformedIterator public T transform(F f) { return this.this$0.function.apply(f); } }; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class TransformingRandomAccessList extends AbstractList implements RandomAccess, Serializable { private static final long serialVersionUID = 0; final List fromList; final Function function; TransformingRandomAccessList(List list, Function function) { this.fromList = (List) Preconditions.checkNotNull(list); this.function = (Function) Preconditions.checkNotNull(function); } @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List public void clear() { this.fromList.clear(); } @Override // java.util.AbstractList, java.util.List public T get(int i) { return this.function.apply(this.fromList.get(i)); } @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List public Iterator iterator() { return listIterator(); } @Override // java.util.AbstractList, java.util.List public ListIterator listIterator(int i) { return new TransformedListIterator(this, this.fromList.listIterator(i)) { // from class: com.google.common.collect.Lists.TransformingRandomAccessList.1 final TransformingRandomAccessList this$0; { this.this$0 = this; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.TransformedIterator public T transform(F f) { return this.this$0.function.apply(f); } }; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public boolean isEmpty() { return this.fromList.isEmpty(); } @Override // java.util.AbstractList, java.util.List public T remove(int i) { return this.function.apply(this.fromList.remove(i)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.fromList.size(); } } public static List> partition(List list, int i) { Preconditions.checkNotNull(list); Preconditions.checkArgument(i > 0); if (list instanceof RandomAccess) { return new RandomAccessPartition(list, i); } return new Partition(list, i); } /* loaded from: classes2.dex */ static class Partition extends AbstractList> { final List list; final int size; Partition(List list, int i) { this.list = list; this.size = i; } @Override // java.util.AbstractList, java.util.List public List get(int i) { Preconditions.checkElementIndex(i, size()); int i2 = this.size; int i3 = i * i2; return this.list.subList(i3, Math.min(i2 + i3, this.list.size())); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return IntMath.divide(this.list.size(), this.size, RoundingMode.CEILING); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public boolean isEmpty() { return this.list.isEmpty(); } } /* loaded from: classes2.dex */ static class RandomAccessPartition extends Partition implements RandomAccess { RandomAccessPartition(List list, int i) { super(list, i); } } public static ImmutableList charactersOf(String str) { return new StringAsImmutableList((String) Preconditions.checkNotNull(str)); } public static List charactersOf(CharSequence charSequence) { return new CharSequenceAsList((CharSequence) Preconditions.checkNotNull(charSequence)); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class StringAsImmutableList extends ImmutableList { private final String string; /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableCollection public final boolean isPartialView() { return false; } @Override // com.google.common.collect.ImmutableList, java.util.List public final /* bridge */ /* synthetic */ List subList(int i, int i2) { return subList(i, i2); } StringAsImmutableList(String str) { this.string = str; } @Override // com.google.common.collect.ImmutableList, java.util.List public final int indexOf(Object obj) { if (obj instanceof Character) { return this.string.indexOf(((Character) obj).charValue()); } return -1; } @Override // com.google.common.collect.ImmutableList, java.util.List public final int lastIndexOf(Object obj) { if (obj instanceof Character) { return this.string.lastIndexOf(((Character) obj).charValue()); } return -1; } @Override // com.google.common.collect.ImmutableList, java.util.List public final ImmutableList subList(int i, int i2) { Preconditions.checkPositionIndexes(i, i2, size()); return Lists.charactersOf(this.string.substring(i, i2)); } @Override // java.util.List public final Character get(int i) { Preconditions.checkElementIndex(i, size()); return Character.valueOf(this.string.charAt(i)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public final int size() { return this.string.length(); } } /* loaded from: classes2.dex */ static final class CharSequenceAsList extends AbstractList { private final CharSequence sequence; CharSequenceAsList(CharSequence charSequence) { this.sequence = charSequence; } @Override // java.util.AbstractList, java.util.List public final Character get(int i) { Preconditions.checkElementIndex(i, size()); return Character.valueOf(this.sequence.charAt(i)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public final int size() { return this.sequence.length(); } } public static List reverse(List list) { if (list instanceof ImmutableList) { return ((ImmutableList) list).reverse(); } if (list instanceof ReverseList) { return ((ReverseList) list).getForwardList(); } if (list instanceof RandomAccess) { return new RandomAccessReverseList(list); } return new ReverseList(list); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class ReverseList extends AbstractList { private final List forwardList; ReverseList(List list) { this.forwardList = (List) Preconditions.checkNotNull(list); } private int reverseIndex(int i) { int size = size(); Preconditions.checkElementIndex(i, size); return (size - 1) - i; } /* JADX INFO: Access modifiers changed from: private */ public int reversePosition(int i) { int size = size(); Preconditions.checkPositionIndex(i, size); return size - i; } @Override // java.util.AbstractList, java.util.List public void add(int i, T t) { this.forwardList.add(reversePosition(i), t); } @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List public void clear() { this.forwardList.clear(); } @Override // java.util.AbstractList, java.util.List public T remove(int i) { return this.forwardList.remove(reverseIndex(i)); } @Override // java.util.AbstractList protected void removeRange(int i, int i2) { subList(i, i2).clear(); } @Override // java.util.AbstractList, java.util.List public T set(int i, T t) { return this.forwardList.set(reverseIndex(i), t); } @Override // java.util.AbstractList, java.util.List public T get(int i) { return this.forwardList.get(reverseIndex(i)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.forwardList.size(); } @Override // java.util.AbstractList, java.util.List public List subList(int i, int i2) { Preconditions.checkPositionIndexes(i, i2, size()); return Lists.reverse(this.forwardList.subList(reversePosition(i2), reversePosition(i))); } @Override // java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List public Iterator iterator() { return listIterator(); } @Override // java.util.AbstractList, java.util.List public ListIterator listIterator(int i) { return new ListIterator(this, this.forwardList.listIterator(reversePosition(i))) { // from class: com.google.common.collect.Lists.ReverseList.1 boolean canRemoveOrSet; final ReverseList this$0; final ListIterator val$forwardIterator; { this.this$0 = this; this.val$forwardIterator = r2; } @Override // java.util.ListIterator public void add(T t) { this.val$forwardIterator.add(t); this.val$forwardIterator.previous(); this.canRemoveOrSet = false; } @Override // java.util.ListIterator, java.util.Iterator public boolean hasNext() { return this.val$forwardIterator.hasPrevious(); } @Override // java.util.ListIterator public boolean hasPrevious() { return this.val$forwardIterator.hasNext(); } @Override // java.util.ListIterator, java.util.Iterator public T next() { if (!hasNext()) { throw new NoSuchElementException(); } this.canRemoveOrSet = true; return (T) this.val$forwardIterator.previous(); } @Override // java.util.ListIterator public int nextIndex() { return this.this$0.reversePosition(this.val$forwardIterator.nextIndex()); } @Override // java.util.ListIterator public T previous() { if (!hasPrevious()) { throw new NoSuchElementException(); } this.canRemoveOrSet = true; return (T) this.val$forwardIterator.next(); } @Override // java.util.ListIterator public int previousIndex() { return nextIndex() - 1; } @Override // java.util.ListIterator, java.util.Iterator public void remove() { CollectPreconditions.checkRemove(this.canRemoveOrSet); this.val$forwardIterator.remove(); this.canRemoveOrSet = false; } @Override // java.util.ListIterator public void set(T t) { Preconditions.checkState(this.canRemoveOrSet); this.val$forwardIterator.set(t); } }; } List getForwardList() { return this.forwardList; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class RandomAccessReverseList extends ReverseList implements RandomAccess { RandomAccessReverseList(List list) { super(list); } } /* JADX INFO: Access modifiers changed from: package-private */ public static int hashCodeImpl(List list) { Iterator it = list.iterator(); int i = 1; while (it.hasNext()) { Object next = it.next(); i = ~(~((i * 31) + (next == null ? 0 : next.hashCode()))); } return i; } /* JADX INFO: Access modifiers changed from: package-private */ public static boolean equalsImpl(List list, Object obj) { if (obj == Preconditions.checkNotNull(list)) { return true; } if (!(obj instanceof List)) { return false; } List list2 = (List) obj; int size = list.size(); if (size != list2.size()) { return false; } if (!(list instanceof RandomAccess) || !(list2 instanceof RandomAccess)) { return Iterators.elementsEqual(list.iterator(), list2.iterator()); } for (int i = 0; i < size; i++) { if (!Objects.equal(list.get(i), list2.get(i))) { return false; } } return true; } /* JADX INFO: Access modifiers changed from: package-private */ public static boolean addAllImpl(List list, int i, Iterable iterable) { ListIterator listIterator = list.listIterator(i); Iterator it = iterable.iterator(); boolean z = false; while (it.hasNext()) { listIterator.add(it.next()); z = true; } return z; } /* JADX INFO: Access modifiers changed from: package-private */ public static int indexOfImpl(List list, Object obj) { if (list instanceof RandomAccess) { return indexOfRandomAccess(list, obj); } ListIterator listIterator = list.listIterator(); while (listIterator.hasNext()) { if (Objects.equal(obj, listIterator.next())) { return listIterator.previousIndex(); } } return -1; } private static int indexOfRandomAccess(List list, Object obj) { int size = list.size(); int i = 0; if (obj == null) { while (i < size) { if (list.get(i) == null) { return i; } i++; } return -1; } while (i < size) { if (obj.equals(list.get(i))) { return i; } i++; } return -1; } /* JADX INFO: Access modifiers changed from: package-private */ public static int lastIndexOfImpl(List list, Object obj) { if (list instanceof RandomAccess) { return lastIndexOfRandomAccess(list, obj); } ListIterator listIterator = list.listIterator(list.size()); while (listIterator.hasPrevious()) { if (Objects.equal(obj, listIterator.previous())) { return listIterator.nextIndex(); } } return -1; } private static int lastIndexOfRandomAccess(List list, Object obj) { if (obj == null) { for (int size = list.size() - 1; size >= 0; size--) { if (list.get(size) == null) { return size; } } return -1; } for (int size2 = list.size() - 1; size2 >= 0; size2--) { if (obj.equals(list.get(size2))) { return size2; } } return -1; } /* JADX INFO: Access modifiers changed from: package-private */ public static ListIterator listIteratorImpl(List list, int i) { return new AbstractListWrapper(list).listIterator(i); } /* JADX INFO: Access modifiers changed from: package-private */ public static List subListImpl(List list, int i, int i2) { List list2; if (list instanceof RandomAccess) { list2 = new RandomAccessListWrapper(list) { // from class: com.google.common.collect.Lists.1 private static final long serialVersionUID = 0; @Override // java.util.AbstractList, java.util.List public ListIterator listIterator(int i3) { return this.backingList.listIterator(i3); } }; } else { list2 = new AbstractListWrapper(list) { // from class: com.google.common.collect.Lists.2 private static final long serialVersionUID = 0; @Override // java.util.AbstractList, java.util.List public ListIterator listIterator(int i3) { return this.backingList.listIterator(i3); } }; } return list2.subList(i, i2); } /* loaded from: classes2.dex */ static class AbstractListWrapper extends AbstractList { final List backingList; AbstractListWrapper(List list) { this.backingList = (List) Preconditions.checkNotNull(list); } @Override // java.util.AbstractList, java.util.List public void add(int i, E e) { this.backingList.add(i, e); } @Override // java.util.AbstractList, java.util.List public boolean addAll(int i, Collection collection) { return this.backingList.addAll(i, collection); } @Override // java.util.AbstractList, java.util.List public E get(int i) { return this.backingList.get(i); } @Override // java.util.AbstractList, java.util.List public E remove(int i) { return this.backingList.remove(i); } @Override // java.util.AbstractList, java.util.List public E set(int i, E e) { return this.backingList.set(i, e); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public boolean contains(Object obj) { return this.backingList.contains(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.backingList.size(); } } /* loaded from: classes2.dex */ static class RandomAccessListWrapper extends AbstractListWrapper implements RandomAccess { RandomAccessListWrapper(List list) { super(list); } } /* JADX INFO: Access modifiers changed from: package-private */ public static List cast(Iterable iterable) { return (List) iterable; } }