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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final LazyStringList | |
| private static final LazyStringArrayList | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(int
index at which the specified element is to be inserted index, String element to be inserted element)Overrides com. Implements java. |
| private void | add(int
index at which the specified element is to be inserted index, ByteString element to be inserted element)Overrides com. Implements java. |
| private void | add(int
index at which the specified element is to be inserted index, byte[] element to be inserted element)Overrides com. Implements java. |
| public void | add(ByteString
element to be appended to this list element)Overrides com. Implements com. |
| public void | add(byte[]
element to be appended to this list element)Overrides com. Implements com. |
| public boolean | addAll(Collection<? extends String>
collection containing elements to be added to this list c)Overrides com. Implements java. |
| public boolean | addAll(int
index at which to insert the first element from the
specified collection index, Collection<? extends String> collection containing elements to be added to this list c)Overrides com. Implements java. |
| public boolean | addAllByteArray(Collection<byte[]>
collection whose elements are to be added to this list c)Implements com. |
| public boolean | addAllByteString(Collection<? extends ByteString>
collection whose elements are to be added to this list values)Implements com. |
| private static byte[] | |
| public List | asByteArrayList()
Implements com. |
| private static ByteString | |
| public List | asByteStringList()
Implements com. |
| private static String | |
| public void | clear()
Overrides com. Implements java. |
| pack-priv static LazyStringArrayList | |
| public String | get(int
index of the element to return index)Implements abstract java. Implements java. |
| public byte[] | getByteArray(int
index of the element to return index)Implements com. |
| public ByteString | getByteString(int
index of the element to return index)Implements com. |
| public Object | getRaw(int
index of the element to return index)Implements com. |
| public List | getUnderlyingElements()
Implements com. String or its equivalent UTF-8 encoded ByteString or byte[].
|
| public LazyStringList | getUnmodifiableView()
Implements com. |
| public void | mergeFrom(LazyStringList other)
Implements com. |
| public LazyStringArrayList | mutableCopyWithCapacity(int capacity)
Implements com. |
| public String | remove(int
the index of the element to be removed index)Overrides com. Implements java. |
| public String | set(int
index of the element to replace index, String element to be stored at the specified position s)Overrides com. Implements java. |
| public void | set(int
index of the element to replace index, ByteString the element to be stored at the specified position s)Overrides com. Implements com. |
| public void | set(int
index of the element to replace index, byte[] the element to be stored at the specified position s)Overrides com. Implements com. |
| private Object | |
| private Object | |
| public int | size()
Implements abstract java. Implements java. |
| EMPTY | back to summary |
|---|---|
| public static final LazyStringList EMPTY | |
| EMPTY_LIST | back to summary |
|---|---|
| private static final LazyStringArrayList EMPTY_LIST | |
| list | back to summary |
|---|---|
| private final List<Object> list | |
| LazyStringArrayList | back to summary |
|---|---|
| public LazyStringArrayList() | |
| LazyStringArrayList | back to summary |
|---|---|
| public LazyStringArrayList(int initialCapacity) | |
| LazyStringArrayList | back to summary |
|---|---|
| public LazyStringArrayList(LazyStringList from) | |
| LazyStringArrayList | back to summary |
|---|---|
| public LazyStringArrayList(List<String> from) | |
| LazyStringArrayList | back to summary |
|---|---|
| private LazyStringArrayList(ArrayList<Object> list) | |
| add | back to summary |
|---|---|
| public void add(int index, String element) Overrides com. Implements java. Doc from java. Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). | |
| add | back to summary |
|---|---|
| private void add(int index, ByteString element) Overrides com. Implements java. Doc from java. Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
| |
| add | back to summary |
|---|---|
| private void add(int index, byte[] element) Overrides com. Implements java. Doc from java. Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
| |
| add | back to summary |
|---|---|
| public void add(ByteString element) Overrides com. Implements com. Doc from com. Appends the specified element to the end of this list (optional operation).
| |
| add | back to summary |
|---|---|
| public void add(byte[] element) Overrides com. Implements com. Doc from com. Appends the specified element to the end of this list (optional operation).
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(Collection<? extends String> c) Overrides com. Implements java. Doc from java. Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(int index, Collection<? extends String> c) Overrides com. Implements java. Doc from java. Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
| |
| addAllByteArray | back to summary |
|---|---|
| public boolean addAllByteArray(Collection<byte[]> c) Implements com. Doc from com. Appends all elements in the specified byte[] collection to the end of this list.
| |
| addAllByteString | back to summary |
|---|---|
| public boolean addAllByteString(Collection<? extends ByteString> values) Implements com. Doc from com. Appends all elements in the specified ByteString collection to the end of this list.
| |
| asByteArray | back to summary |
|---|---|
| private static byte[] asByteArray(Object o) | |
| asByteArrayList | back to summary |
|---|---|
| public List Implements com. Doc from com. Returns a mutable view of this list. Changes to the view will be made into the original list. This method is used in mutable API only.
| |
| asByteString | back to summary |
|---|---|
| private static ByteString asByteString(Object o) | |
| asByteStringList | back to summary |
|---|---|
| public List Implements com. Doc from com. Returns a view of the data as a list of ByteStrings.
| |
| asString | back to summary |
|---|---|
| private static String asString(Object o) | |
| clear | back to summary |
|---|---|
| public void clear() Overrides com. Implements java. Doc from java. Removes all of the elements from this list (optional operation). The list will be empty after this call returns.
| |
| emptyList | back to summary |
|---|---|
| pack-priv static LazyStringArrayList emptyList() | |
| get | back to summary |
|---|---|
| public String get(int index) Implements abstract java. Implements java. Doc from java. Returns the element at the specified position in this list. | |
| getByteArray | back to summary |
|---|---|
| public byte[] getByteArray(int index) Implements com. Doc from com. Returns the element at the specified position in this list as byte[].
| |
| getByteString | back to summary |
|---|---|
| public ByteString getByteString(int index) Implements com. Doc from com. Returns the element at the specified position in this list as a ByteString.
| |
| getRaw | back to summary |
|---|---|
| public Object getRaw(int index) Implements com. Doc from com. Returns the element at the specified position in this list as an Object that will either be a String or a ByteString. | |
| getUnderlyingElements | back to summary |
|---|---|
| public List Implements com. Doc from com. Returns an unmodifiable List of the underlying elements, each of which is either a
| |
| getUnmodifiableView | back to summary |
|---|---|
| public LazyStringList getUnmodifiableView() Implements com. Doc from com. Returns an unmodifiable view of the list.
| |
| mergeFrom | back to summary |
|---|---|
| public void mergeFrom(LazyStringList other) Implements com. Doc from com. Merges all elements from another LazyStringList into this one. This method differs from
| |
| mutableCopyWithCapacity | back to summary |
|---|---|
| public LazyStringArrayList mutableCopyWithCapacity(int capacity) Implements com. Doc from com. Returns a mutable clone of this list with the specified capacity.
| |
| remove | back to summary |
|---|---|
| public String remove(int index) Overrides com. Implements java. Doc from java. Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list. | |
| set | back to summary |
|---|---|
| public String set(int index, String s) Overrides com. Implements java. Doc from java. Replaces the element at the specified position in this list with the specified element (optional operation). | |
| set | back to summary |
|---|---|
| public void set(int index, ByteString s) Overrides com. Implements com. Doc from com. Replaces the element at the specified position in this list with the specified element (optional operation).
| |
| set | back to summary |
|---|---|
| public void set(int index, byte[] s) Overrides com. Implements com. Doc from com. Replaces the element at the specified position in this list with the specified element (optional operation).
| |
| setAndReturn | back to summary |
|---|---|
| private Object setAndReturn(int index, ByteString s) | |
| setAndReturn | back to summary |
|---|---|
| private Object setAndReturn(int index, byte[] s) | |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this list. If this list contains
more than
| |
| Modifier and Type | Field and Description |
|---|---|
| private final LazyStringArrayList |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(int
index at which the specified element is to be inserted index, byte[] element to be inserted s)Overrides java. Implements java. |
| public byte[] | get(int
index of the element to return index)Implements abstract java. Implements java. |
| public byte[] | remove(int
the index of the element to be removed index)Overrides java. Implements java. |
| public byte[] | set(int
index of the element to replace index, byte[] element to be stored at the specified position s)Overrides java. Implements java. |
| public int | size()
Implements abstract java. Implements java. |
| list | back to summary |
|---|---|
| private final LazyStringArrayList list | |
| ByteArrayListView | back to summary |
|---|---|
| pack-priv ByteArrayListView(LazyStringArrayList list) | |
| add | back to summary |
|---|---|
| public void add(int index, byte[] s) Overrides java. Implements java. Doc from java. Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
| |
| get | back to summary |
|---|---|
| public byte[] get(int index) Implements abstract java. Implements java. Doc from java. Returns the element at the specified position in this list.
| |
| remove | back to summary |
|---|---|
| public byte[] remove(int index) Overrides java. Implements java. Doc from java. Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
| |
| set | back to summary |
|---|---|
| public byte[] set(int index, byte[] s) Overrides java. Implements java. Doc from java. Replaces the element at the specified position in this list with the specified element (optional operation).
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this list. If this list contains
more than
| |
| Modifier and Type | Field and Description |
|---|---|
| private final LazyStringArrayList |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(int
index at which the specified element is to be inserted index, ByteString element to be inserted s)Overrides java. Implements java. |
| public ByteString | get(int
index of the element to return index)Implements abstract java. Implements java. |
| public ByteString | remove(int
the index of the element to be removed index)Overrides java. Implements java. |
| public ByteString | set(int
index of the element to replace index, ByteString element to be stored at the specified position s)Overrides java. Implements java. |
| public int | size()
Implements abstract java. Implements java. |
| list | back to summary |
|---|---|
| private final LazyStringArrayList list | |
| ByteStringListView | back to summary |
|---|---|
| pack-priv ByteStringListView(LazyStringArrayList list) | |
| add | back to summary |
|---|---|
| public void add(int index, ByteString s) Overrides java. Implements java. Doc from java. Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
| |
| get | back to summary |
|---|---|
| public ByteString get(int index) Implements abstract java. Implements java. Doc from java. Returns the element at the specified position in this list.
| |
| remove | back to summary |
|---|---|
| public ByteString remove(int index) Overrides java. Implements java. Doc from java. Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
| |
| set | back to summary |
|---|---|
| public ByteString set(int index, ByteString s) Overrides java. Implements java. Doc from java. Replaces the element at the specified position in this list with the specified element (optional operation).
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this list. If this list contains
more than
| |