diff options
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java')
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java index d2f82ac5..81255ec2 100644 --- a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java @@ -38,7 +38,7 @@ import java.util.List; /** * Implements {@link ProtobufList} for non-primitive and {@link String} types. */ -class ProtobufArrayList<E> extends AbstractProtobufList<E> { +final class ProtobufArrayList<E> extends AbstractProtobufList<E> { private static final ProtobufArrayList<Object> EMPTY_LIST = new ProtobufArrayList<Object>(); static { @@ -51,17 +51,23 @@ class ProtobufArrayList<E> extends AbstractProtobufList<E> { } private final List<E> list; - + ProtobufArrayList() { - list = new ArrayList<E>(); + this(new ArrayList<E>(DEFAULT_CAPACITY)); } - ProtobufArrayList(List<E> toCopy) { - list = new ArrayList<E>(toCopy); + private ProtobufArrayList(List<E> list) { + this.list = list; } - - ProtobufArrayList(int capacity) { - list = new ArrayList<E>(capacity); + + @Override + public ProtobufArrayList<E> mutableCopyWithCapacity(int capacity) { + if (capacity < size()) { + throw new IllegalArgumentException(); + } + List<E> newList = new ArrayList<E>(capacity); + newList.addAll(list); + return new ProtobufArrayList<E>(newList); } @Override |