public class LazyStringArrayList extends java.util.AbstractList<java.lang.String> implements LazyStringList, java.util.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 |
Constructor and Description |
---|
LazyStringArrayList() |
LazyStringArrayList(LazyStringList from) |
LazyStringArrayList(java.util.List<java.lang.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,
java.lang.String element) |
boolean |
addAll(java.util.Collection<? extends java.lang.String> c) |
boolean |
addAll(int index,
java.util.Collection<? extends java.lang.String> c) |
void |
clear() |
java.lang.String |
get(int index) |
ByteString |
getByteString(int index)
Returns the element at the specified position in this list as a ByteString.
|
java.util.List<?> |
getUnderlyingElements()
Returns an unmodifiable List of the underlying elements, each of
which is either a
String or its equivalent UTF-8 encoded
ByteString . |
java.lang.String |
remove(int index) |
java.lang.String |
set(int index,
java.lang.String s) |
int |
size() |
add, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
public static final LazyStringList EMPTY
public LazyStringArrayList()
public LazyStringArrayList(LazyStringList from)
public LazyStringArrayList(java.util.List<java.lang.String> from)
public java.lang.String get(int index)
get
in interface java.util.List<java.lang.String>
get
in class java.util.AbstractList<java.lang.String>
public int size()
size
in interface java.util.Collection<java.lang.String>
size
in interface java.util.List<java.lang.String>
size
in class java.util.AbstractCollection<java.lang.String>
public java.lang.String set(int index, java.lang.String s)
set
in interface java.util.List<java.lang.String>
set
in class java.util.AbstractList<java.lang.String>
public void add(int index, java.lang.String element)
add
in interface java.util.List<java.lang.String>
add
in class java.util.AbstractList<java.lang.String>
public boolean addAll(java.util.Collection<? extends java.lang.String> c)
addAll
in interface java.util.Collection<java.lang.String>
addAll
in interface java.util.List<java.lang.String>
addAll
in class java.util.AbstractCollection<java.lang.String>
public boolean addAll(int index, java.util.Collection<? extends java.lang.String> c)
addAll
in interface java.util.List<java.lang.String>
addAll
in class java.util.AbstractList<java.lang.String>
public java.lang.String remove(int index)
remove
in interface java.util.List<java.lang.String>
remove
in class java.util.AbstractList<java.lang.String>
public void clear()
clear
in interface java.util.Collection<java.lang.String>
clear
in interface java.util.List<java.lang.String>
clear
in class java.util.AbstractList<java.lang.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 returnpublic java.util.List<?> getUnderlyingElements()
LazyStringList
String
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 LazyStringList