31 package com.google.protobuf;
34 import java.util.ArrayList;
35 import java.util.List;
38 final class ProtobufArrayList<E>
extends AbstractProtobufList<E> {
40 private static final ProtobufArrayList<Object> EMPTY_LIST =
41 new ProtobufArrayList<Object>(
new ArrayList<Object>(0));
44 EMPTY_LIST.makeImmutable();
47 @SuppressWarnings(
"unchecked")
48 public static <E> ProtobufArrayList<E> emptyList() {
49 return (ProtobufArrayList<E>) EMPTY_LIST;
52 private final List<E> list;
55 this(
new ArrayList<E>(DEFAULT_CAPACITY));
58 private ProtobufArrayList(List<E> list) {
63 public ProtobufArrayList<E> mutableCopyWithCapacity(
int capacity) {
64 if (capacity <
size()) {
65 throw new IllegalArgumentException();
67 List<E> newList =
new ArrayList<E>(capacity);
69 return new ProtobufArrayList<E>(newList);
73 public void add(
int index, E element) {
75 list.add(
index, element);
80 public E
get(
int index) {
81 return list.get(
index);
85 public E
remove(
int index) {
87 E toReturn = list.remove(
index);
93 public E
set(
int index, E element) {
95 E toReturn = list.set(
index, element);