Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://aoindustries.com/contact
public class PersistentLinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>
Serializes and stores objects in a persistent buffer. Unlike FileList which
is intended for efficient RandomAccess,
this is a linked list implementation and has the expected benefits and costs.
There are no size limits to the stored data.
This class is not thread-safe. It is absolutely critical that external synchronization be applied.
The objects are serialized using the standard Java serialization, unless a
Serializer is provided. If an object that is not Serializable
is to be stored, a Serializer must be provided. Serializers
may also provide a more efficient or more compact representation of an object.
This class is intended for scalability and persistence, not for intra-process or intra-thread shared data.
The first block allocated is a header:
Offset Type Description
0- 3 ASCII "PLL\n"
4- 7 int version
8-15 long block id of the head or END_PTR if empty.
16-23 long block id of the tail or END_PTR if empty.
Each entry consists of:
Offset Name Type Description
0- 7 next long block id of next, END_PTR for last element
8-15 prev long block id of prev, END_PTR for first element
16-23 dataSize long the size of the serialized data, -1 means null element
24+ data data the binary data
TODO: Add corrupt flag, set on exceptions? Cause immediate crash recovery? TODO: Similar thing for the underlying block buffers and byte buffers?
modCount| Constructor and Description |
|---|
PersistentLinkedList(Class<E> type)
Constructs a list backed by a temporary file using standard serialization.
|
PersistentLinkedList(Class<E> type,
Collection<? extends E> c)
Constructs a list with a temporary file using standard serialization containing all of the provided elements.
|
PersistentLinkedList(PersistentBuffer pbuffer,
Class<E> type)
Constructs a list backed by the provided persistent buffer using the most efficient serialization
for the provided type.
|
PersistentLinkedList(PersistentBuffer pbuffer,
Serializer<E> serializer)
Constructs a list backed by the provided persistent buffer.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E element) |
void |
add(int index,
E element) |
boolean |
addAll(Collection<? extends E> c) |
boolean |
addAll(int index,
Collection<? extends E> c) |
void |
addFirst(E element)
Inserts the specified element at the beginning of this list.
|
void |
addLast(E element)
Appends the specified element to the end of this list.
|
protected void |
checkConsistency(boolean autoCorrect)
Performs a check that this linked list is in a consistent state, optionally
correcting problems that may occur during an unclean shutdown.
|
void |
clear()
Clears the list.
|
void |
close()
Closes the random access file backing this list.
|
boolean |
contains(Object o) |
Iterator<E> |
descendingIterator() |
E |
element() |
protected void |
finalize() |
E |
get(int index) |
E |
getFirst()
Returns the first element in this list.
|
E |
getLast()
Returns the last element in this list.
|
int |
indexOf(Object o) |
int |
lastIndexOf(Object o) |
ListIterator<E> |
listIterator(int index) |
boolean |
offer(E e) |
boolean |
offerFirst(E e) |
boolean |
offerLast(E e) |
E |
peek() |
E |
peekFirst() |
E |
peekLast() |
E |
poll() |
E |
pollFirst() |
E |
pollLast() |
E |
pop() |
void |
push(E e) |
E |
remove() |
E |
remove(int index) |
boolean |
remove(Object o) |
E |
removeFirst()
Removes and returns the first element from this list.
|
boolean |
removeFirstOccurrence(Object o) |
E |
removeLast()
Removes and returns the last element from this list.
|
boolean |
removeLastOccurrence(Object o) |
E |
set(int index,
E element) |
int |
size()
Gets the number of elements in this list.
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
iteratorequals, hashCode, listIterator, removeRange, subListcontainsAll, isEmpty, removeAll, retainAll, toStringcontainsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, replaceAll, retainAll, sort, spliterator, subListparallelStream, removeIf, streampublic PersistentLinkedList(Class<E> type) throws IOException
IOExceptionPersistentCollections.getPersistentBuffer(long)public PersistentLinkedList(Class<E> type, Collection<? extends E> c) throws IOException
IOExceptionpublic PersistentLinkedList(PersistentBuffer pbuffer, Class<E> type) throws IOException
IOExceptionPersistentCollections.getSerializer(java.lang.Class)public PersistentLinkedList(PersistentBuffer pbuffer, Serializer<E> serializer) throws IOException
IOExceptionprotected void checkConsistency(boolean autoCorrect)
throws IOException,
IllegalStateException
autoCorrect - Will correct inconsistencies that arise from an unclean shutdown.
Logs any corrections made to logger with level INFO.IOException - if IO error occurs during checkIllegalStateException - when in an inconsistent state and, if autoCorrect, is uncorrectablepublic E getFirst()
getFirst in interface Deque<E>NoSuchElementException - if this list is emptypublic E getLast()
getLast in interface Deque<E>NoSuchElementException - if this list is emptypublic E removeFirst()
removeFirst in interface Deque<E>NoSuchElementException - if this list is emptypublic E removeLast()
removeLast in interface Deque<E>NoSuchElementException - if this list is emptypublic void addFirst(E element)
public void addLast(E element)
This method is equivalent to add(E).
public boolean contains(Object o)
public boolean remove(Object o)
public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in interface List<E>addAll in class AbstractCollection<E>public boolean addAll(int index,
Collection<? extends E> c)
public int size()
public boolean add(E element)
public void clear()
clear in interface Collection<E>clear in interface List<E>clear in class AbstractList<E>public E get(int index)
public void add(int index,
E element)
public E remove(int index)
public int indexOf(Object o)
public int lastIndexOf(Object o)
lastIndexOf in interface List<E>lastIndexOf in class AbstractList<E>public E peek()
public E element()
public E poll()
public E remove()
public boolean offer(E e)
public boolean offerFirst(E e)
offerFirst in interface Deque<E>public boolean removeFirstOccurrence(Object o)
removeFirstOccurrence in interface Deque<E>public boolean removeLastOccurrence(Object o)
removeLastOccurrence in interface Deque<E>public ListIterator<E> listIterator(int index)
listIterator in interface List<E>listIterator in class AbstractSequentialList<E>public Iterator<E> descendingIterator()
descendingIterator in interface Deque<E>public Object[] toArray()
toArray in interface Collection<E>toArray in interface List<E>toArray in class AbstractCollection<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>toArray in interface List<E>toArray in class AbstractCollection<E>protected void finalize()
throws Throwable
public void close()
throws IOException
IOExceptionCopyright © 2000–2019 AO Industries, Inc.. All rights reserved.