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(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(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.
|
String |
remove(int index) |
String |
set(int index,
String s) |
int |
size() |
add, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add, addAll, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, subList, toArray, toArray
public static final LazyStringList EMPTY
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(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)
LazyStringList
add
in interface LazyStringList
element
- element to be appended to this listpublic ByteString getByteString(int index)
LazyStringList
getByteString
in interface LazyStringList
index
- index of the element to returnCopyright © 2008-2013. All Rights Reserved.