aboutsummaryrefslogtreecommitdiff
path: root/java/core/src/main/java/com/google/protobuf/LongArrayList.java
diff options
context:
space:
mode:
authorJisi Liu <jisi.liu@gmail.com>2016-04-28 14:34:59 -0700
committerJisi Liu <jisi.liu@gmail.com>2016-04-28 14:34:59 -0700
commitcf14183bcd5485b4a71541599ddce0b35eb71352 (patch)
tree12f6e5eb731d7a70cdac4cdafc8b3131629413e2 /java/core/src/main/java/com/google/protobuf/LongArrayList.java
parentf00300d7f04f1c38a7d70e271f9232b94dd0e326 (diff)
downloadprotobuf-cf14183bcd5485b4a71541599ddce0b35eb71352.tar.gz
protobuf-cf14183bcd5485b4a71541599ddce0b35eb71352.tar.bz2
protobuf-cf14183bcd5485b4a71541599ddce0b35eb71352.zip
Down integrate from Google internal.
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/LongArrayList.java')
-rw-r--r--java/core/src/main/java/com/google/protobuf/LongArrayList.java64
1 files changed, 42 insertions, 22 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/LongArrayList.java b/java/core/src/main/java/com/google/protobuf/LongArrayList.java
index ebe62029..bc4475d1 100644
--- a/java/core/src/main/java/com/google/protobuf/LongArrayList.java
+++ b/java/core/src/main/java/com/google/protobuf/LongArrayList.java
@@ -34,7 +34,6 @@ import com.google.protobuf.Internal.LongList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
import java.util.RandomAccess;
/**
@@ -44,8 +43,6 @@ import java.util.RandomAccess;
*/
final class LongArrayList extends AbstractProtobufList<Long> implements LongList, RandomAccess {
- private static final int DEFAULT_CAPACITY = 10;
-
private static final LongArrayList EMPTY_LIST = new LongArrayList();
static {
EMPTY_LIST.makeImmutable();
@@ -70,32 +67,55 @@ final class LongArrayList extends AbstractProtobufList<Long> implements LongList
* Constructs a new mutable {@code LongArrayList} with default capacity.
*/
LongArrayList() {
- this(DEFAULT_CAPACITY);
- }
-
- /**
- * Constructs a new mutable {@code LongArrayList} with the provided capacity.
- */
- LongArrayList(int capacity) {
- array = new long[capacity];
- size = 0;
+ this(new long[DEFAULT_CAPACITY], 0);
}
/**
* Constructs a new mutable {@code LongArrayList} containing the same elements as {@code other}.
*/
- LongArrayList(List<Long> other) {
- if (other instanceof LongArrayList) {
- LongArrayList list = (LongArrayList) other;
- array = list.array.clone();
- size = list.size;
- } else {
- size = other.size();
- array = new long[size];
- for (int i = 0; i < size; i++) {
- array[i] = other.get(i);
+ private LongArrayList(long[] array, int size) {
+ this.array = array;
+ this.size = size;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof IntArrayList)) {
+ return super.equals(o);
+ }
+ LongArrayList other = (LongArrayList) o;
+ if (size != other.size) {
+ return false;
+ }
+
+ final long[] arr = other.array;
+ for (int i = 0; i < size; i++) {
+ if (array[i] != arr[i]) {
+ return false;
}
}
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ for (int i = 0; i < size; i++) {
+ result = (31 * result) + Internal.hashLong(array[i]);
+ }
+ return result;
+ }
+
+ @Override
+ public LongList mutableCopyWithCapacity(int capacity) {
+ if (capacity < size) {
+ throw new IllegalArgumentException();
+ }
+ return new LongArrayList(Arrays.copyOf(array, capacity), size);
}
@Override