public class LazyStringArrayList extends AbstractList<String> implements LazyStringList, RandomAccess
LazyStringList that wraps an ArrayList. Each
element is either a ByteString or a String. 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.
| Modifier and Type | Field and Description |
|---|---|
static LazyStringList |
EMPTY |
modCount| Constructor and Description |
|---|
LazyStringArrayList() |
LazyStringArrayList(LazyStringList from) |
LazyStringArrayList(List<String> from) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(ByteString element)
Appends the specified element to the end of this list (optional
operation).
|
void |
add(int index,
String element) |
boolean |
addAll(Collection<? extends String> c) |
boolean |
addAll(int index,
Collection<? extends String> c) |
void |
clear() |
String |
get(int index) |
ByteString |
getByteString(int index)
Returns the element at the specified position in this list as a ByteString.
|
List<?> |
getUnderlyingElements()
Returns an unmodifiable List of the underlying elements, each of
which is either a
String or its equivalent UTF-8 encoded
ByteString. |
String |
remove(int index) |
String |
set(int index,
String s) |
int |
size() |
add, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListcontains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, subList, toArray, toArraypublic static final LazyStringList EMPTY
public LazyStringArrayList()
public LazyStringArrayList(LazyStringList from)
public String get(int index)
public int size()
size in interface Collection<String>size in interface List<String>size in class AbstractCollection<String>public void add(int index,
String element)
public boolean addAll(Collection<? extends String> c)
addAll in interface Collection<String>addAll in interface List<String>addAll in class AbstractCollection<String>public boolean addAll(int index,
Collection<? extends String> c)
public String remove(int index)
public void clear()
clear in interface Collection<String>clear in interface List<String>clear in class AbstractList<String>public void add(ByteString element)
LazyStringListadd in interface LazyStringListelement - element to be appended to this listpublic ByteString getByteString(int index)
LazyStringListgetByteString in interface LazyStringListindex - index of the element to returnpublic List<?> getUnderlyingElements()
LazyStringListString or its equivalent UTF-8 encoded
ByteString. It is an error for the caller to modify the returned
List, and attempting to do so will result in an
UnsupportedOperationException.getUnderlyingElements in interface LazyStringListCopyright © 2008-2013 Google. All Rights Reserved.