1616import java .util .RandomAccess ;
1717
1818/**
19- * An implementation of {@link LazyStringList} that wraps an ArrayList. Each element is one of
20- * String, ByteString, or byte[]. It caches the last one requested which is most likely the one
21- * needed next. This minimizes memory usage while satisfying the most common use cases.
19+ * An implementation of {@link LazyStringList} that wraps an {@link ArrayList}. Each element is one
20+ * of {@link String}, {@link ByteString}, or {@code byte[]}. It caches the last one requested which
21+ * is most likely the one needed next. This minimizes memory usage while satisfying the most common
22+ * use cases.
2223 *
23- * <p><strong >Note that this implementation is not synchronized.</strong > If multiple threads access
24- * an <tt> ArrayList</tt> instance concurrently, and at least one of the threads modifies the list
25- * structurally, it <i>must</i> be synchronized externally. (A structural modification is any
26- * operation that adds or deletes one or more elements, or explicitly resizes the backing array;
27- * merely setting the value of an element is not a structural modification.) This is typically
28- * accomplished by synchronizing on some object that naturally encapsulates the list.
24+ * <p><b >Note that this implementation is not synchronized.</b > If multiple threads access an {@link
25+ * ArrayList} instance concurrently, and at least one of the threads modifies the list structurally,
26+ * it <i>must</i> be synchronized externally. (A structural modification is any operation that adds
27+ * or deletes one or more elements, or explicitly resizes the backing array; merely setting the
28+ * value of an element is not a structural modification.) This is typically accomplished by
29+ * synchronizing on some object that naturally encapsulates the list.
2930 *
3031 * <p>If the implementation is accessed via concurrent reads, this is thread safe. Conversions are
3132 * done in a thread safe manner. It's possible that the conversion may happen more than once if two
@@ -48,11 +49,9 @@ public static LazyStringArrayList emptyList() {
4849 /**
4950 * For compatibility with older runtimes.
5051 *
51- * <p>TODO Remove this in a breaking release.
52- *
53- * @deprecated use {@link emptyList()} instead
52+ * @deprecated use {@link #emptyList()} instead
5453 */
55- @ Deprecated public static final LazyStringList EMPTY = EMPTY_LIST ;
54+ @ Deprecated public static final LazyStringList EMPTY = emptyList () ;
5655
5756 private final List <Object > list ;
5857
@@ -119,13 +118,6 @@ public int size() {
119118 return list .size ();
120119 }
121120
122- @ Override
123- public String set (int index , String s ) {
124- ensureIsMutable ();
125- Object o = list .set (index , s );
126- return asString (o );
127- }
128-
129121 @ Override
130122 public void add (int index , String element ) {
131123 ensureIsMutable ();
@@ -246,20 +238,27 @@ public byte[] getByteArray(int index) {
246238 }
247239
248240 @ Override
249- public void set (int index , ByteString s ) {
250- setAndReturn (index , s );
241+ public String set (int index , String s ) {
242+ ensureIsMutable ();
243+ Object o = list .set (index , s );
244+ return asString (o );
251245 }
252246
253- private Object setAndReturn ( int index , ByteString s ) {
254- ensureIsMutable ();
255- return list . set (index , s );
247+ @ Override
248+ public void set ( int index , ByteString s ) {
249+ setAndReturn (index , s );
256250 }
257251
258252 @ Override
259253 public void set (int index , byte [] s ) {
260254 setAndReturn (index , s );
261255 }
262256
257+ private Object setAndReturn (int index , ByteString s ) {
258+ ensureIsMutable ();
259+ return list .set (index , s );
260+ }
261+
263262 private Object setAndReturn (int index , byte [] s ) {
264263 ensureIsMutable ();
265264 return list .set (index , s );
0 commit comments