31 package com.google.protobuf;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
41 abstract class ListFieldSchema {
43 private ListFieldSchema() {}
45 private static final ListFieldSchema FULL_INSTANCE =
new ListFieldSchemaFull();
46 private static final ListFieldSchema LITE_INSTANCE =
new ListFieldSchemaLite();
48 abstract <L> List<L> mutableListAt(Object msg,
long offset);
50 abstract void makeImmutableListAt(Object msg,
long offset);
52 abstract <L>
void mergeListsAt(Object msg, Object otherMsg,
long offset);
54 static ListFieldSchema full() {
58 static ListFieldSchema lite() {
66 Collections.unmodifiableList(Collections.emptyList()).getClass();
70 return mutableListAt(
message,
offset, AbstractProtobufList.DEFAULT_CAPACITY);
75 List<?> list = (List<?>) UnsafeUtil.getObject(
message,
offset);
76 Object immutable =
null;
82 }
else if (list instanceof PrimitiveNonBoxingCollection && list instanceof ProtobufList) {
83 if (((ProtobufList<?>) list).isModifiable()) {
84 ((ProtobufList<?>) list).makeImmutable();
88 immutable = Collections.unmodifiableList((List<?>) list);
93 @SuppressWarnings(
"unchecked")
94 private static <L> List<L> mutableListAt(Object
message,
long offset,
int additionalCapacity) {
99 }
else if (list instanceof PrimitiveNonBoxingCollection && list instanceof
ProtobufList) {
102 list =
new ArrayList<L>(additionalCapacity);
106 ArrayList<L> newList =
new ArrayList<L>(list.size() + additionalCapacity);
107 newList.addAll(list);
113 list = (List<L>) newList;
115 }
else if (list instanceof PrimitiveNonBoxingCollection
125 <E>
void mergeListsAt(Object msg, Object otherMsg,
long offset) {
126 List<E> other = getList(otherMsg,
offset);
127 List<E> mine = mutableListAt(msg,
offset, other.size());
129 int size = mine.size();
130 int otherSize = other.size();
131 if (
size > 0 && otherSize > 0) {
139 @SuppressWarnings(
"unchecked")
152 int size = list.size();
155 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY :
size * 2);
168 <E>
void mergeListsAt(Object msg, Object otherMsg,
long offset) {
172 int size = mine.size();
173 int otherSize = other.size();
174 if (
size > 0 && otherSize > 0) {
185 @SuppressWarnings(
"unchecked")