31 package com.google.protobuf;
36 import java.util.Arrays;
37 import java.util.Collection;
38 import java.util.RandomAccess;
45 final class FloatArrayList
extends AbstractProtobufList<Float>
46 implements FloatList, RandomAccess, PrimitiveNonBoxingCollection {
48 private static final FloatArrayList EMPTY_LIST =
new FloatArrayList(
new float[0], 0);
51 EMPTY_LIST.makeImmutable();
54 public static FloatArrayList emptyList() {
59 private float[]
array;
69 this(
new float[DEFAULT_CAPACITY], 0);
75 private FloatArrayList(
float[] 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 FloatArrayList)) {
98 return super.equals(o);
100 FloatArrayList other = (FloatArrayList) o;
101 if (
size != other.size) {
105 final float[] arr = other.array;
106 for (
int i = 0;
i <
size;
i++) {
116 public int hashCode() {
118 for (
int i = 0;
i <
size;
i++) {
119 result = (31 * result) +
Float.floatToIntBits(
array[
i]);
125 public FloatList mutableCopyWithCapacity(
int capacity) {
126 if (capacity <
size) {
127 throw new IllegalArgumentException();
129 return new FloatArrayList(Arrays.copyOf(
array, capacity),
size);
134 return getFloat(
index);
138 public float getFloat(
int index) {
139 ensureIndexInRange(
index);
150 return setFloat(
index, element);
154 public float setFloat(
int index,
float element) {
156 ensureIndexInRange(
index);
159 return previousValue;
164 addFloat(
index, element);
169 public void addFloat(
float element) {
170 addFloat(
size, element);
174 private void addFloat(
int index,
float element) {
177 throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(
index));
186 float[] newArray =
new float[
length];
189 System.arraycopy(
array, 0, newArray, 0,
index);
202 public boolean addAll(Collection<? extends Float> collection) {
205 checkNotNull(collection);
208 if (!(collection instanceof FloatArrayList)) {
209 return super.addAll(collection);
212 FloatArrayList list = (FloatArrayList) collection;
213 if (list.size == 0) {
217 int overflow = Integer.MAX_VALUE -
size;
218 if (overflow < list.size) {
220 throw new OutOfMemoryError();
223 int newSize =
size + list.size;
224 if (newSize >
array.length) {
228 System.arraycopy(list.array, 0,
array,
size, list.size);
235 public boolean remove(Object o) {
237 for (
int i = 0;
i <
size;
i++) {
251 ensureIndexInRange(
index);
267 private void ensureIndexInRange(
int index) {
269 throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(
index));
273 private String makeOutOfBoundsExceptionMessage(
int index) {
274 return "Index:" +
index +
", Size:" +
size;