public interface AppendList<T> extends Iterable<T>
Two states are in this list. State AppendList.State.WRITE when instance created, then element can be appended to tail.
After all elements are appended, switch state to AppendList.State.READ. When state is AppendList.State.READ, data cannot be
appended, only can be iterative.
Only support appending element to tail and iterative reading.
Such code as an example:
AppendList<Data> dataList = new MemoryDiskList<Data>(60L, "c.txt");
dataList.append(new Data(1, 1));
dataList.append(new Data(2, 2));
dataList.append(new Data(3, 3));
dataList.append(new Data(4, 4));
dataList.switchState();
for(Data d: dataList) {
System.out.println(d);
}
| Modifier and Type | Interface and Description |
|---|---|
static class |
AppendList.State
Inner state definition.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
append(T t)
Append object to this list
|
void |
clear()
Clear all elements.
|
int |
size()
Return size of this list.
|
void |
switchState()
After appending, switch state from WRITE to READ to allow iterating.
|
forEach, iterator, spliteratorboolean append(T t)
t - the object to appendIllegalStateException - if not in WRITE state.void switchState()
int size()
void clear()
Copyright © 2019. All Rights Reserved.