Index: third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java |
diff --git a/third_party/protobuf/java/src/main/java/com/google/protobuf/ProtobufArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java |
similarity index 52% |
rename from third_party/protobuf/java/src/main/java/com/google/protobuf/ProtobufArrayList.java |
rename to third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java |
index d2f82ac5135b3664770afc8968c6fd5873541f70..cce286e10fb49912911ac997ebf302959a3ac5b0 100644 |
--- a/third_party/protobuf/java/src/main/java/com/google/protobuf/ProtobufArrayList.java |
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java |
@@ -30,70 +30,75 @@ |
package com.google.protobuf; |
-import com.google.protobuf.Internal.ProtobufList; |
- |
-import java.util.ArrayList; |
-import java.util.List; |
+import java.util.Arrays; |
/** |
- * Implements {@link ProtobufList} for non-primitive and {@link String} types. |
+ * A location in the source code. |
+ * |
+ * <p>A location is the starting line number and starting column number. |
*/ |
-class ProtobufArrayList<E> extends AbstractProtobufList<E> { |
+public final class TextFormatParseLocation { |
- private static final ProtobufArrayList<Object> EMPTY_LIST = new ProtobufArrayList<Object>(); |
- static { |
- EMPTY_LIST.makeImmutable(); |
- } |
- |
- @SuppressWarnings("unchecked") // Guaranteed safe by runtime. |
- public static <E> ProtobufArrayList<E> emptyList() { |
- return (ProtobufArrayList<E>) EMPTY_LIST; |
- } |
- |
- private final List<E> list; |
- |
- ProtobufArrayList() { |
- list = new ArrayList<E>(); |
- } |
- |
- ProtobufArrayList(List<E> toCopy) { |
- list = new ArrayList<E>(toCopy); |
+ /** |
+ * The empty location. |
+ */ |
+ public static final TextFormatParseLocation EMPTY = new TextFormatParseLocation(-1, -1); |
+ |
+ /** |
+ * Create a location. |
+ * |
+ * @param line the starting line number |
+ * @param column the starting column number |
+ * @return a {@code ParseLocation} |
+ */ |
+ static TextFormatParseLocation create(int line, int column) { |
+ if (line == -1 && column == -1) { |
+ return EMPTY; |
+ } |
+ if (line < 0 || column < 0) { |
+ throw new IllegalArgumentException( |
+ String.format("line and column values must be >= 0: line %d, column: %d", line, column)); |
+ } |
+ return new TextFormatParseLocation(line, column); |
} |
- |
- ProtobufArrayList(int capacity) { |
- list = new ArrayList<E>(capacity); |
+ |
+ private final int line; |
+ private final int column; |
+ |
+ private TextFormatParseLocation(int line, int column) { |
+ this.line = line; |
+ this.column = column; |
} |
- |
- @Override |
- public void add(int index, E element) { |
- ensureIsMutable(); |
- list.add(index, element); |
- modCount++; |
+ |
+ public int getLine() { |
+ return line; |
} |
- @Override |
- public E get(int index) { |
- return list.get(index); |
+ public int getColumn() { |
+ return column; |
} |
- |
+ |
@Override |
- public E remove(int index) { |
- ensureIsMutable(); |
- E toReturn = list.remove(index); |
- modCount++; |
- return toReturn; |
+ public String toString() { |
+ return String.format("ParseLocation{line=%d, column=%d}", line, column); |
} |
- |
+ |
@Override |
- public E set(int index, E element) { |
- ensureIsMutable(); |
- E toReturn = list.set(index, element); |
- modCount++; |
- return toReturn; |
+ public boolean equals(Object o) { |
+ if (o == this) { |
+ return true; |
+ } |
+ if (!(o instanceof TextFormatParseLocation)) { |
+ return false; |
+ } |
+ TextFormatParseLocation that = (TextFormatParseLocation) o; |
+ return (this.line == that.getLine()) |
+ && (this.column == that.getColumn()); |
} |
@Override |
- public int size() { |
- return list.size(); |
+ public int hashCode() { |
+ int[] values = {line, column}; |
+ return Arrays.hashCode(values); |
} |
} |