31 package com.google.protobuf;
36 import java.util.Arrays;
37 import java.util.Collection;
38 import java.util.RandomAccess;
45 final class DoubleArrayList
extends AbstractProtobufList<Double>
46 implements DoubleList, RandomAccess, PrimitiveNonBoxingCollection {
48 private static final DoubleArrayList EMPTY_LIST =
new DoubleArrayList(
new double[0], 0);
51 EMPTY_LIST.makeImmutable();
54 public static DoubleArrayList emptyList() {
59 private double[]
array;
69 this(
new double[DEFAULT_CAPACITY], 0);
75 private DoubleArrayList(
double[] other,
int size) {
81 protected void removeRange(
int fromIndex,
int toIndex) {
83 if (toIndex < fromIndex) {
84 throw new IndexOutOfBoundsException(
"toIndex < fromIndex");
87 System.arraycopy(
array, toIndex,
array, fromIndex,
size - toIndex);
88 size -= (toIndex - fromIndex);
93 public boolean equals(Object o) {
97 if (!(o instanceof DoubleArrayList)) {
98 return super.equals(o);
100 DoubleArrayList other = (DoubleArrayList) o;
101 if (
size != other.size) {
105 final double[] arr = other.array;
106 for (
int i = 0;
i <
size;
i++) {
116 public int hashCode() {
118 for (
int i = 0;
i <
size;
i++) {
120 result = (31 * result) + Internal.hashLong(bits);
126 public DoubleList mutableCopyWithCapacity(
int capacity) {
127 if (capacity <
size) {
128 throw new IllegalArgumentException();
130 return new DoubleArrayList(Arrays.copyOf(
array, capacity),
size);
135 return getDouble(
index);
139 public double getDouble(
int index) {
140 ensureIndexInRange(
index);
151 return setDouble(
index, element);
155 public double setDouble(
int index,
double element) {
157 ensureIndexInRange(
index);
160 return previousValue;
165 addDouble(
index, element);
170 public void addDouble(
double element) {
171 addDouble(
size, element);
175 private void addDouble(
int index,
double element) {
178 throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(
index));
187 double[] newArray =
new double[
length];
190 System.arraycopy(
array, 0, newArray, 0,
index);
203 public boolean addAll(Collection<? extends Double> collection) {
206 checkNotNull(collection);
209 if (!(collection instanceof DoubleArrayList)) {
210 return super.addAll(collection);
213 DoubleArrayList list = (DoubleArrayList) collection;
214 if (list.size == 0) {
218 int overflow = Integer.MAX_VALUE -
size;
219 if (overflow < list.size) {
221 throw new OutOfMemoryError();
224 int newSize =
size + list.size;
225 if (newSize >
array.length) {
229 System.arraycopy(list.array, 0,
array,
size, list.size);
236 public boolean remove(Object o) {
238 for (
int i = 0;
i <
size;
i++) {
252 ensureIndexInRange(
index);
268 private void ensureIndexInRange(
int index) {
270 throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(
index));
274 private String makeOutOfBoundsExceptionMessage(
int index) {
275 return "Index:" +
index +
", Size:" +
size;