E
- list element type.public abstract class EncodableList<E> extends Object implements List<E>, Encodable
List
interface through to the underlying list implementation, while handling the
serialisation and deserialisation of the list's state via the contract provided by
the Encodable
interface.
In order to use this list, a subclass must be implemented that:
Encodable
interface.
newInstance
, writeValue
, and readValue
methods defined in this class.
This implementation provides the ability to specify what type of list structure to use as a backing store from a set of predefined types. A subclass may use an alternative list implementation by:
one-arg class constructor
passing null
as the backingStore
parameter; and
newListInstance(BackingStore)
method to create the
required list structure, disregarding the method argument.
Modifier and Type | Class and Description |
---|---|
static class |
EncodableList.BackingStore
Pre-defined backing stores for the
EncodableList . |
Modifier | Constructor and Description |
---|---|
|
EncodableList()
Create an
EncodableList using EncodableList.BackingStore.ARRAY as the default backing store. |
protected |
EncodableList(DataInput in,
ClassLoader cl,
DecoderUtils utils)
Creates an
EncodableList with state restored from the specified input stream. |
|
EncodableList(EncodableList.BackingStore backingStore)
Create an
EncodableList using the specified backing store. |
protected |
EncodableList(EncodableList.BackingStore backingStore,
List<E> list)
Create an
EncodableList using the specified backing store and list. |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
void |
add(int index,
E element) |
boolean |
addAll(Collection<? extends E> c) |
boolean |
addAll(int index,
Collection<? extends E> c) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
void |
encode(DataOutput out,
EncoderUtils utils)
Encode the state of this object to the given data output stream.
|
boolean |
equals(Object o) |
protected void |
fromStream(DataInput in,
ClassLoader cl,
DecoderUtils utils)
Populate list elements with state restored from the specified input stream.
|
E |
get(int index) |
int |
hashCode() |
int |
indexOf(Object o) |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator<E> |
listIterator() |
ListIterator<E> |
listIterator(int index) |
protected boolean |
manageNullElements()
Determine if this
EncodableList type should manage null elements within the
serialisation logic. |
protected abstract EncodableList<E> |
newInstance(EncodableList.BackingStore backingStore,
List<E> list)
Create a new instance of this
EncodableList wrapping the specified list. |
protected List<E> |
newListInstance(EncodableList.BackingStore backingStore)
Create a new list instance for the backing store.
|
protected abstract E |
readElement(DataInput in,
ClassLoader cl,
DecoderUtils utils)
Deserialise a list element from the input stream.
|
E |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
E |
set(int index,
E element) |
int |
size() |
List<E> |
subList(int fromIndex,
int toIndex) |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
protected void |
toStream(DataOutput out,
EncoderUtils utils)
Serialise the state of the list to the given output stream.
|
String |
toString() |
protected abstract void |
writeElement(E element,
DataOutput out,
EncoderUtils utils)
Serialise the specified list element to the output stream.
|
public EncodableList()
EncodableList
using EncodableList.BackingStore.ARRAY
as the default backing store.public EncodableList(EncodableList.BackingStore backingStore)
EncodableList
using the specified backing store.backingStore
- the backing store to use.protected EncodableList(EncodableList.BackingStore backingStore, List<E> list)
EncodableList
using the specified backing store and list.
This constructor exists primarily to facilitate the implementation of subList(int, int)
,
but may also be used to create an EncodableList
that wraps a pre-existing list.backingStore
- the backing store to use.list
- the initial list state.protected EncodableList(DataInput in, ClassLoader cl, DecoderUtils utils) throws IOException
EncodableList
with state restored from the specified input stream.in
- the input stream to read list state from.cl
- classloader that can be used to resolve class dependencies.utils
- additional utility decoding functions.IOException
- if an I/O error occurs.protected void fromStream(DataInput in, ClassLoader cl, DecoderUtils utils) throws IOException
Warning: This method can only be used to deserialise a list serialised using the
toStream(DataOutput, EncoderUtils)
method. It will not work with a list serialised
using the encode(DataOutput, EncoderUtils)
method.
in
- the input stream to read list state from.cl
- classloader that can be used to resolve class dependencies.utils
- additional utility decoding functions.IOException
- if an I/O error occurs.public void encode(DataOutput out, EncoderUtils utils) throws IOException
Encodable
encode
in interface Encodable
out
- the data output stream to encode the value to.utils
- additional utility encoding functions that may be useful to the encoder.IOException
- if an I/O error occurs.protected void toStream(DataOutput out, EncoderUtils utils) throws IOException
Warning: the serialisation data created by this method can only be restored using the
fromStream(DataInput, ClassLoader, DecoderUtils)
method. For a more general result
that follows the Encodable
contract, use the encode(DataOutput, EncoderUtils)
method.
out
- the output stream to write list state to.utils
- additional utility encoding functions.IOException
- if an I/O error occurs.public int size()
public boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(E e)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<E>
containsAll
in interface List<E>
public boolean addAll(Collection<? extends E> c)
public boolean addAll(int index, Collection<? extends E> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public boolean equals(Object o)
public int hashCode()
public int lastIndexOf(Object o)
lastIndexOf
in interface List<E>
public ListIterator<E> listIterator()
listIterator
in interface List<E>
public ListIterator<E> listIterator(int index)
listIterator
in interface List<E>
protected boolean manageNullElements()
EncodableList
type should manage null elements within the
serialisation logic.
The result of this method determines whether or not null checks are included in the output
stream when the list is serialised. If null elements are never expected, not supported by
the underlying backing store, or the implementation of writeElement(E, java.io.DataOutput, com.opencloud.rhino.cmp.codecs.EncoderUtils)
and readElement(java.io.DataInput, java.lang.ClassLoader, com.opencloud.rhino.cmp.codecs.DecoderUtils)
will handle null elements, then this method may safely return false
.
The default implementation of this method always returns false
.
true
if null elements should be managed, false
otherwise.protected List<E> newListInstance(EncodableList.BackingStore backingStore)
backingStore.createList()
.backingStore
- the backing store originally passed in to the class constructor when the
EncodableList
was first created.protected abstract EncodableList<E> newInstance(EncodableList.BackingStore backingStore, List<E> list)
EncodableList
wrapping the specified list.backingStore
- the backing store originally passed in to the class constructor when this
EncodableList
was first created.list
- the list that the new EncodableList
instance should wrap.EncodableList
instance wrapping the listprotected abstract void writeElement(E element, DataOutput out, EncoderUtils utils) throws IOException
element
- the list element, may be null
if the underlying list supports null keys and
manageNullElements() return false.out
- the output stream to write the element state to.utils
- additional utility encoding functions that may be useful when serialising the element.IOException
- if an I/O error occurs.protected abstract E readElement(DataInput in, ClassLoader cl, DecoderUtils utils) throws IOException
in
- the input stream to read the element state from.cl
- classloader that can be used to resolve class dependencies.utils
- additional utility decoding functions that may be useful when deserialising the element.IOException
- if an I/O error occurs.