package com.google.protobuf; import com.google.protobuf.Internal; import java.util.AbstractList; import java.util.Arrays; import java.util.Collection; import java.util.RandomAccess; /* loaded from: classes3.dex */ public final class LongArrayList extends AbstractProtobufList implements Internal.LongList, RandomAccess, PrimitiveNonBoxingCollection { private static final LongArrayList EMPTY_LIST; private long[] array; private int size; public static LongArrayList emptyList() { return EMPTY_LIST; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.size; } static { LongArrayList longArrayList = new LongArrayList(new long[0], 0); EMPTY_LIST = longArrayList; longArrayList.makeImmutable(); } public LongArrayList() { this(new long[10], 0); } private LongArrayList(long[] jArr, int i) { this.array = jArr; this.size = i; } @Override // java.util.AbstractList public void removeRange(int i, int i2) { ensureIsMutable(); if (i2 < i) { throw new IndexOutOfBoundsException("toIndex < fromIndex"); } long[] jArr = this.array; System.arraycopy(jArr, i2, jArr, i, this.size - i2); this.size -= i2 - i; ((AbstractList) this).modCount++; } @Override // com.google.protobuf.AbstractProtobufList, java.util.AbstractList, java.util.Collection, java.util.List public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof LongArrayList)) { return super.equals(obj); } LongArrayList longArrayList = (LongArrayList) obj; if (this.size != longArrayList.size) { return false; } long[] jArr = longArrayList.array; for (int i = 0; i < this.size; i++) { if (this.array[i] != jArr[i]) { return false; } } return true; } @Override // com.google.protobuf.AbstractProtobufList, java.util.AbstractList, java.util.Collection, java.util.List public int hashCode() { int i = 1; for (int i2 = 0; i2 < this.size; i2++) { i = (i * 31) + Internal.hashLong(this.array[i2]); } return i; } @Override // com.google.protobuf.Internal.ProtobufList, com.google.protobuf.Internal.BooleanList /* renamed from: mutableCopyWithCapacity */ public Internal.ProtobufList mutableCopyWithCapacity2(int i) { if (i < this.size) { throw new IllegalArgumentException(); } return new LongArrayList(Arrays.copyOf(this.array, i), this.size); } @Override // java.util.AbstractList, java.util.List public Long get(int i) { return Long.valueOf(getLong(i)); } @Override // com.google.protobuf.Internal.LongList public long getLong(int i) { ensureIndexInRange(i); return this.array[i]; } @Override // java.util.AbstractList, java.util.List public int indexOf(Object obj) { if (!(obj instanceof Long)) { return -1; } long longValue = ((Long) obj).longValue(); int size = size(); for (int i = 0; i < size; i++) { if (this.array[i] == longValue) { return i; } } return -1; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public boolean contains(Object obj) { return indexOf(obj) != -1; } @Override // com.google.protobuf.AbstractProtobufList, java.util.AbstractList, java.util.List public Long set(int i, Long l) { return Long.valueOf(setLong(i, l.longValue())); } @Override // com.google.protobuf.Internal.LongList public long setLong(int i, long j) { ensureIsMutable(); ensureIndexInRange(i); long[] jArr = this.array; long j2 = jArr[i]; jArr[i] = j; return j2; } @Override // com.google.protobuf.AbstractProtobufList, java.util.AbstractList, java.util.AbstractCollection, java.util.Collection, java.util.List public boolean add(Long l) { addLong(l.longValue()); return true; } @Override // com.google.protobuf.AbstractProtobufList, java.util.AbstractList, java.util.List public void add(int i, Long l) { addLong(i, l.longValue()); } @Override // com.google.protobuf.Internal.LongList public void addLong(long j) { ensureIsMutable(); int i = this.size; long[] jArr = this.array; if (i == jArr.length) { long[] jArr2 = new long[((i * 3) / 2) + 1]; System.arraycopy(jArr, 0, jArr2, 0, i); this.array = jArr2; } long[] jArr3 = this.array; int i2 = this.size; this.size = i2 + 1; jArr3[i2] = j; } private void addLong(int i, long j) { int i2; ensureIsMutable(); if (i < 0 || i > (i2 = this.size)) { throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(i)); } long[] jArr = this.array; if (i2 < jArr.length) { System.arraycopy(jArr, i, jArr, i + 1, i2 - i); } else { long[] jArr2 = new long[((i2 * 3) / 2) + 1]; System.arraycopy(jArr, 0, jArr2, 0, i); System.arraycopy(this.array, i, jArr2, i + 1, this.size - i); this.array = jArr2; } this.array[i] = j; this.size++; ((AbstractList) this).modCount++; } @Override // com.google.protobuf.AbstractProtobufList, java.util.AbstractCollection, java.util.Collection, java.util.List public boolean addAll(Collection collection) { ensureIsMutable(); Internal.checkNotNull(collection); if (!(collection instanceof LongArrayList)) { return super.addAll(collection); } LongArrayList longArrayList = (LongArrayList) collection; int i = longArrayList.size; if (i == 0) { return false; } int i2 = this.size; if (Integer.MAX_VALUE - i2 < i) { throw new OutOfMemoryError(); } int i3 = i2 + i; long[] jArr = this.array; if (i3 > jArr.length) { this.array = Arrays.copyOf(jArr, i3); } System.arraycopy(longArrayList.array, 0, this.array, this.size, longArrayList.size); this.size = i3; ((AbstractList) this).modCount++; return true; } @Override // com.google.protobuf.AbstractProtobufList, java.util.AbstractList, java.util.List public Long remove(int i) { ensureIsMutable(); ensureIndexInRange(i); long[] jArr = this.array; long j = jArr[i]; if (i < this.size - 1) { System.arraycopy(jArr, i + 1, jArr, i, (r3 - i) - 1); } this.size--; ((AbstractList) this).modCount++; return Long.valueOf(j); } private void ensureIndexInRange(int i) { if (i < 0 || i >= this.size) { throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(i)); } } private String makeOutOfBoundsExceptionMessage(int i) { return "Index:" + i + ", Size:" + this.size; } }