discord-jadx/app/src/main/java/kotlin/collections/ArrayDeque.java

599 lines
23 KiB
Java

package kotlin.collections;
import d0.d0.f;
import d0.t.c;
import d0.t.e;
import d0.t.j;
import d0.t.k;
import d0.t.n;
import d0.z.d.m;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: ArrayDeque.kt */
public final class ArrayDeque<E> extends e<E> {
public static final Object[] i = new Object[0];
public static final a j = new a(null);
public int k;
public Object[] l = i;
public int m;
/* compiled from: ArrayDeque.kt */
public static final class a {
public a(DefaultConstructorMarker defaultConstructorMarker) {
}
public final int newCapacity$kotlin_stdlib(int i, int i2) {
int i3 = i + (i >> 1);
if (i3 - i2 < 0) {
i3 = i2;
}
return i3 - 2147483639 > 0 ? i2 > 2147483639 ? Integer.MAX_VALUE : 2147483639 : i3;
}
}
public static final /* synthetic */ Object[] access$getElementData$p(ArrayDeque arrayDeque) {
return arrayDeque.l;
}
public static final /* synthetic */ int access$getHead$p(ArrayDeque arrayDeque) {
return arrayDeque.k;
}
public static final /* synthetic */ int access$incremented(ArrayDeque arrayDeque, int i2) {
return arrayDeque.g(i2);
}
public static final int access$negativeMod(ArrayDeque arrayDeque, int i2) {
Objects.requireNonNull(arrayDeque);
return i2 < 0 ? i2 + arrayDeque.l.length : i2;
}
public static final int access$positiveMod(ArrayDeque arrayDeque, int i2) {
Object[] objArr = arrayDeque.l;
return i2 >= objArr.length ? i2 - objArr.length : i2;
}
public static final /* synthetic */ void access$setSize$p(ArrayDeque arrayDeque, int i2) {
arrayDeque.m = i2;
}
@Override // java.util.AbstractList, java.util.List
public void add(int i2, E e) {
c.i.checkPositionIndex$kotlin_stdlib(i2, size());
if (i2 == size()) {
addLast(e);
} else if (i2 == 0) {
addFirst(e);
} else {
e(size() + 1);
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + i2);
if (i2 < ((size() + 1) >> 1)) {
int d = d(access$positiveMod);
int d2 = d(this.k);
int i3 = this.k;
if (d >= i3) {
Object[] objArr = this.l;
objArr[d2] = objArr[i3];
j.copyInto(objArr, objArr, i3, i3 + 1, d + 1);
} else {
Object[] objArr2 = this.l;
j.copyInto(objArr2, objArr2, i3 - 1, i3, objArr2.length);
Object[] objArr3 = this.l;
objArr3[objArr3.length - 1] = objArr3[0];
j.copyInto(objArr3, objArr3, 0, 1, d + 1);
}
this.l[d] = e;
this.k = d2;
} else {
int access$positiveMod2 = access$positiveMod(this, access$getHead$p(this) + size());
if (access$positiveMod < access$positiveMod2) {
Object[] objArr4 = this.l;
j.copyInto(objArr4, objArr4, access$positiveMod + 1, access$positiveMod, access$positiveMod2);
} else {
Object[] objArr5 = this.l;
j.copyInto(objArr5, objArr5, 1, 0, access$positiveMod2);
Object[] objArr6 = this.l;
objArr6[0] = objArr6[objArr6.length - 1];
j.copyInto(objArr6, objArr6, access$positiveMod + 1, access$positiveMod, objArr6.length - 1);
}
this.l[access$positiveMod] = e;
}
this.m = size() + 1;
}
}
@Override // java.util.AbstractList, java.util.AbstractCollection, java.util.List, java.util.Collection
public boolean add(E e) {
addLast(e);
return true;
}
@Override // java.util.AbstractList, java.util.List
public boolean addAll(int i2, Collection<? extends E> collection) {
m.checkNotNullParameter(collection, "elements");
c.i.checkPositionIndex$kotlin_stdlib(i2, size());
if (collection.isEmpty()) {
return false;
}
if (i2 == size()) {
return addAll(collection);
}
e(collection.size() + size());
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + size());
int access$positiveMod2 = access$positiveMod(this, access$getHead$p(this) + i2);
int size = collection.size();
if (i2 < ((size() + 1) >> 1)) {
int i3 = this.k;
int i4 = i3 - size;
if (access$positiveMod2 < i3) {
Object[] objArr = this.l;
j.copyInto(objArr, objArr, i4, i3, objArr.length);
if (size >= access$positiveMod2) {
Object[] objArr2 = this.l;
j.copyInto(objArr2, objArr2, objArr2.length - size, 0, access$positiveMod2);
} else {
Object[] objArr3 = this.l;
j.copyInto(objArr3, objArr3, objArr3.length - size, 0, size);
Object[] objArr4 = this.l;
j.copyInto(objArr4, objArr4, 0, size, access$positiveMod2);
}
} else if (i4 >= 0) {
Object[] objArr5 = this.l;
j.copyInto(objArr5, objArr5, i4, i3, access$positiveMod2);
} else {
Object[] objArr6 = this.l;
i4 += objArr6.length;
int i5 = access$positiveMod2 - i3;
int length = objArr6.length - i4;
if (length >= i5) {
j.copyInto(objArr6, objArr6, i4, i3, access$positiveMod2);
} else {
j.copyInto(objArr6, objArr6, i4, i3, i3 + length);
Object[] objArr7 = this.l;
j.copyInto(objArr7, objArr7, 0, this.k + length, access$positiveMod2);
}
}
this.k = i4;
int i6 = access$positiveMod2 - size;
if (i6 < 0) {
i6 += this.l.length;
}
c(i6, collection);
} else {
int i7 = access$positiveMod2 + size;
if (access$positiveMod2 < access$positiveMod) {
int i8 = size + access$positiveMod;
Object[] objArr8 = this.l;
if (i8 <= objArr8.length) {
j.copyInto(objArr8, objArr8, i7, access$positiveMod2, access$positiveMod);
} else if (i7 >= objArr8.length) {
j.copyInto(objArr8, objArr8, i7 - objArr8.length, access$positiveMod2, access$positiveMod);
} else {
int length2 = access$positiveMod - (i8 - objArr8.length);
j.copyInto(objArr8, objArr8, 0, length2, access$positiveMod);
Object[] objArr9 = this.l;
j.copyInto(objArr9, objArr9, i7, access$positiveMod2, length2);
}
} else {
Object[] objArr10 = this.l;
j.copyInto(objArr10, objArr10, size, 0, access$positiveMod);
Object[] objArr11 = this.l;
if (i7 >= objArr11.length) {
j.copyInto(objArr11, objArr11, i7 - objArr11.length, access$positiveMod2, objArr11.length);
} else {
j.copyInto(objArr11, objArr11, 0, objArr11.length - size, objArr11.length);
Object[] objArr12 = this.l;
j.copyInto(objArr12, objArr12, i7, access$positiveMod2, objArr12.length - size);
}
}
c(access$positiveMod2, collection);
}
return true;
}
@Override // java.util.AbstractCollection, java.util.List, java.util.Collection
public boolean addAll(Collection<? extends E> collection) {
m.checkNotNullParameter(collection, "elements");
if (collection.isEmpty()) {
return false;
}
e(collection.size() + size());
c(access$positiveMod(this, access$getHead$p(this) + size()), collection);
return true;
}
public final void addFirst(E e) {
e(size() + 1);
int d = d(this.k);
this.k = d;
this.l[d] = e;
this.m = size() + 1;
}
public final void addLast(E e) {
e(size() + 1);
this.l[access$positiveMod(this, access$getHead$p(this) + size())] = e;
this.m = size() + 1;
}
public final void c(int i2, Collection<? extends E> collection) {
Iterator<? extends E> it = collection.iterator();
int length = this.l.length;
while (i2 < length && it.hasNext()) {
this.l[i2] = it.next();
i2++;
}
int i3 = this.k;
for (int i4 = 0; i4 < i3 && it.hasNext(); i4++) {
this.l[i4] = it.next();
}
this.m = collection.size() + size();
}
@Override // java.util.AbstractList, java.util.AbstractCollection, java.util.List, java.util.Collection
public void clear() {
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + size());
int i2 = this.k;
if (i2 < access$positiveMod) {
j.fill(this.l, (Object) null, i2, access$positiveMod);
} else if (!isEmpty()) {
Object[] objArr = this.l;
j.fill(objArr, (Object) null, this.k, objArr.length);
j.fill(this.l, (Object) null, 0, access$positiveMod);
}
this.k = 0;
this.m = 0;
}
@Override // java.util.AbstractCollection, java.util.List, java.util.Collection
public boolean contains(Object obj) {
return indexOf(obj) != -1;
}
public final int d(int i2) {
return i2 == 0 ? k.getLastIndex(this.l) : i2 - 1;
}
public final void e(int i2) {
if (i2 >= 0) {
Object[] objArr = this.l;
if (i2 > objArr.length) {
if (objArr == i) {
this.l = new Object[f.coerceAtLeast(i2, 10)];
return;
}
Object[] objArr2 = new Object[j.newCapacity$kotlin_stdlib(objArr.length, i2)];
Object[] objArr3 = this.l;
j.copyInto(objArr3, objArr2, 0, this.k, objArr3.length);
Object[] objArr4 = this.l;
int length = objArr4.length;
int i3 = this.k;
j.copyInto(objArr4, objArr2, length - i3, 0, i3);
this.k = 0;
this.l = objArr2;
return;
}
return;
}
throw new IllegalStateException("Deque is too big.");
}
public final int g(int i2) {
if (i2 == k.getLastIndex(this.l)) {
return 0;
}
return i2 + 1;
}
@Override // java.util.AbstractList, java.util.List
public E get(int i2) {
c.i.checkElementIndex$kotlin_stdlib(i2, size());
return (E) access$getElementData$p(this)[access$positiveMod(this, access$getHead$p(this) + i2)];
}
@Override // d0.t.e
public int getSize() {
return this.m;
}
@Override // java.util.AbstractList, java.util.List
public int indexOf(Object obj) {
int i2;
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + size());
int i3 = this.k;
if (i3 < access$positiveMod) {
while (i3 < access$positiveMod) {
if (m.areEqual(obj, this.l[i3])) {
i2 = this.k;
} else {
i3++;
}
}
return -1;
} else if (i3 < access$positiveMod) {
return -1;
} else {
int length = this.l.length;
while (true) {
if (i3 >= length) {
for (int i4 = 0; i4 < access$positiveMod; i4++) {
if (m.areEqual(obj, this.l[i4])) {
i3 = i4 + this.l.length;
i2 = this.k;
}
}
return -1;
} else if (m.areEqual(obj, this.l[i3])) {
i2 = this.k;
break;
} else {
i3++;
}
}
}
return i3 - i2;
}
@Override // java.util.AbstractCollection, java.util.List, java.util.Collection
public boolean isEmpty() {
return size() == 0;
}
@Override // java.util.AbstractList, java.util.List
public int lastIndexOf(Object obj) {
int lastIndex;
int i2;
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + size());
int i3 = this.k;
if (i3 < access$positiveMod) {
lastIndex = access$positiveMod - 1;
if (lastIndex < i3) {
return -1;
}
while (!m.areEqual(obj, this.l[lastIndex])) {
if (lastIndex == i3) {
return -1;
}
lastIndex--;
}
i2 = this.k;
} else if (i3 <= access$positiveMod) {
return -1;
} else {
int i4 = access$positiveMod - 1;
while (true) {
if (i4 < 0) {
lastIndex = k.getLastIndex(this.l);
int i5 = this.k;
if (lastIndex < i5) {
return -1;
}
while (!m.areEqual(obj, this.l[lastIndex])) {
if (lastIndex == i5) {
return -1;
}
lastIndex--;
}
i2 = this.k;
} else if (m.areEqual(obj, this.l[i4])) {
lastIndex = i4 + this.l.length;
i2 = this.k;
break;
} else {
i4--;
}
}
}
return lastIndex - i2;
}
@Override // java.util.AbstractCollection, java.util.List, java.util.Collection
public boolean remove(Object obj) {
int indexOf = indexOf(obj);
if (indexOf == -1) {
return false;
}
remove(indexOf);
return true;
}
@Override // java.util.AbstractCollection, java.util.List, java.util.Collection
public boolean removeAll(Collection<? extends Object> collection) {
m.checkNotNullParameter(collection, "elements");
boolean z2 = false;
z2 = false;
z2 = false;
if (!isEmpty()) {
if (!(access$getElementData$p(this).length == 0)) {
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + size());
int access$getHead$p = access$getHead$p(this);
if (access$getHead$p(this) < access$positiveMod) {
for (int access$getHead$p2 = access$getHead$p(this); access$getHead$p2 < access$positiveMod; access$getHead$p2++) {
Object obj = access$getElementData$p(this)[access$getHead$p2];
if (!collection.contains(obj)) {
access$getElementData$p(this)[access$getHead$p] = obj;
access$getHead$p++;
} else {
z2 = true;
}
}
j.fill(access$getElementData$p(this), (Object) null, access$getHead$p, access$positiveMod);
} else {
int length = access$getElementData$p(this).length;
boolean z3 = false;
for (int access$getHead$p3 = access$getHead$p(this); access$getHead$p3 < length; access$getHead$p3++) {
Object obj2 = access$getElementData$p(this)[access$getHead$p3];
access$getElementData$p(this)[access$getHead$p3] = null;
if (!collection.contains(obj2)) {
access$getElementData$p(this)[access$getHead$p] = obj2;
access$getHead$p++;
} else {
z3 = true;
}
}
access$getHead$p = access$positiveMod(this, access$getHead$p);
for (int i2 = 0; i2 < access$positiveMod; i2++) {
Object obj3 = access$getElementData$p(this)[i2];
access$getElementData$p(this)[i2] = null;
if (!collection.contains(obj3)) {
access$getElementData$p(this)[access$getHead$p] = obj3;
access$getHead$p = access$incremented(this, access$getHead$p);
} else {
z3 = true;
}
}
z2 = z3;
}
if (z2) {
access$setSize$p(this, access$negativeMod(this, access$getHead$p - access$getHead$p(this)));
}
}
}
return z2;
}
@Override // d0.t.e
public E removeAt(int i2) {
c.i.checkElementIndex$kotlin_stdlib(i2, size());
if (i2 == n.getLastIndex(this)) {
return removeLast();
}
if (i2 == 0) {
return removeFirst();
}
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + i2);
E e = (E) access$getElementData$p(this)[access$positiveMod];
if (i2 < (size() >> 1)) {
int i3 = this.k;
if (access$positiveMod >= i3) {
Object[] objArr = this.l;
j.copyInto(objArr, objArr, i3 + 1, i3, access$positiveMod);
} else {
Object[] objArr2 = this.l;
j.copyInto(objArr2, objArr2, 1, 0, access$positiveMod);
Object[] objArr3 = this.l;
objArr3[0] = objArr3[objArr3.length - 1];
int i4 = this.k;
j.copyInto(objArr3, objArr3, i4 + 1, i4, objArr3.length - 1);
}
Object[] objArr4 = this.l;
int i5 = this.k;
objArr4[i5] = null;
this.k = g(i5);
} else {
int access$positiveMod2 = access$positiveMod(this, access$getHead$p(this) + n.getLastIndex(this));
if (access$positiveMod <= access$positiveMod2) {
Object[] objArr5 = this.l;
j.copyInto(objArr5, objArr5, access$positiveMod, access$positiveMod + 1, access$positiveMod2 + 1);
} else {
Object[] objArr6 = this.l;
j.copyInto(objArr6, objArr6, access$positiveMod, access$positiveMod + 1, objArr6.length);
Object[] objArr7 = this.l;
objArr7[objArr7.length - 1] = objArr7[0];
j.copyInto(objArr7, objArr7, 0, 1, access$positiveMod2 + 1);
}
this.l[access$positiveMod2] = null;
}
this.m = size() - 1;
return e;
}
public final E removeFirst() {
if (!isEmpty()) {
E e = (E) access$getElementData$p(this)[this.k];
Object[] objArr = this.l;
int i2 = this.k;
objArr[i2] = null;
this.k = g(i2);
this.m = size() - 1;
return e;
}
throw new NoSuchElementException("ArrayDeque is empty.");
}
public final E removeFirstOrNull() {
if (isEmpty()) {
return null;
}
return removeFirst();
}
public final E removeLast() {
if (!isEmpty()) {
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + n.getLastIndex(this));
E e = (E) access$getElementData$p(this)[access$positiveMod];
this.l[access$positiveMod] = null;
this.m = size() - 1;
return e;
}
throw new NoSuchElementException("ArrayDeque is empty.");
}
@Override // java.util.AbstractCollection, java.util.List, java.util.Collection
public boolean retainAll(Collection<? extends Object> collection) {
m.checkNotNullParameter(collection, "elements");
boolean z2 = false;
z2 = false;
z2 = false;
if (!isEmpty()) {
if (!(access$getElementData$p(this).length == 0)) {
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + size());
int access$getHead$p = access$getHead$p(this);
if (access$getHead$p(this) < access$positiveMod) {
for (int access$getHead$p2 = access$getHead$p(this); access$getHead$p2 < access$positiveMod; access$getHead$p2++) {
Object obj = access$getElementData$p(this)[access$getHead$p2];
if (collection.contains(obj)) {
access$getElementData$p(this)[access$getHead$p] = obj;
access$getHead$p++;
} else {
z2 = true;
}
}
j.fill(access$getElementData$p(this), (Object) null, access$getHead$p, access$positiveMod);
} else {
int length = access$getElementData$p(this).length;
boolean z3 = false;
for (int access$getHead$p3 = access$getHead$p(this); access$getHead$p3 < length; access$getHead$p3++) {
Object obj2 = access$getElementData$p(this)[access$getHead$p3];
access$getElementData$p(this)[access$getHead$p3] = null;
if (collection.contains(obj2)) {
access$getElementData$p(this)[access$getHead$p] = obj2;
access$getHead$p++;
} else {
z3 = true;
}
}
access$getHead$p = access$positiveMod(this, access$getHead$p);
for (int i2 = 0; i2 < access$positiveMod; i2++) {
Object obj3 = access$getElementData$p(this)[i2];
access$getElementData$p(this)[i2] = null;
if (collection.contains(obj3)) {
access$getElementData$p(this)[access$getHead$p] = obj3;
access$getHead$p = access$incremented(this, access$getHead$p);
} else {
z3 = true;
}
}
z2 = z3;
}
if (z2) {
access$setSize$p(this, access$negativeMod(this, access$getHead$p - access$getHead$p(this)));
}
}
}
return z2;
}
@Override // java.util.AbstractList, java.util.List
public E set(int i2, E e) {
c.i.checkElementIndex$kotlin_stdlib(i2, size());
int access$positiveMod = access$positiveMod(this, access$getHead$p(this) + i2);
E e2 = (E) access$getElementData$p(this)[access$positiveMod];
this.l[access$positiveMod] = e;
return e2;
}
}