Class LazyStringArrayList

  • All Implemented Interfaces:
    Internal.ProtobufList<String>, LazyStringList, ProtocolStringList, Iterable<String>, Collection<String>, List<String>, RandomAccess

    public class LazyStringArrayList
    extends AbstractList<E>
    implements LazyStringList, RandomAccess
    An implementation of LazyStringList that wraps an ArrayList. Each element is one of String, ByteString, or byte[]. It caches the last one requested which is most likely the one needed next. This minimizes memory usage while satisfying the most common use cases.

    Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list.

    If the implementation is accessed via concurrent reads, this is thread safe. Conversions are done in a thread safe manner. It's possible that the conversion may happen more than once if two threads attempt to access the same element and the modifications were not visible to each other, but this will not result in any corruption of the list or change in behavior other than performance.

    Author:
    [email protected] (Jon Perlow)