Package net.sf.eBus.messages
Class EMessageList<E extends EMessage>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<E>
-
- net.sf.eBus.messages.EAbstractList<E>
-
- net.sf.eBus.messages.EMessageList<E>
-
- Type Parameters:
E
- specifies the homogenous, concreteEMessage
type stored in this list.
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.List<E>
,java.util.RandomAccess
public final class EMessageList<E extends EMessage> extends EAbstractList<E> implements java.io.Serializable
Thismessage field type
allows multiple messages to be transported within anothereBus message
. A message list is message key homogenous. That is, a message list takes an eBus message key parameter and uses that key to verify that all messages placed in this list have the same key as the parameter. That also means thatnull
messages may not be added to a message list.The difference between
EMessageList
andEMessage[]
is thatEMessageList
serializes the definingEMessageKey
once and then each message instance in turn. This works becauseEMessageList
items all use the same message key.EMessage[]
allows messages with different message keys, so the message key is serialized for each message item. This greatly increases the serialization/de-serialization time and serialized buffer size.This class extends
ArrayList
, providing all the features available in that class.There is no limit as to the number of elements which may be placed into this list. But care must be taken not to overflow the eBus
ByteBuffer
when serializing for transport.- Author:
- Charles W. Rapp
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class net.sf.eBus.messages.EAbstractList
mReadOnlyFlag, READ_ONLY_LIST
-
-
Constructor Summary
Constructors Constructor Description EMessageList(int initialCapacity, EMessageKey key)
Creates an empty message list instance with the specified initial capacity.EMessageList(java.util.Collection<E> c, EMessageKey key)
Creates a message list instance containing the same elements asc
and in the order returned by the collection's iterator.EMessageList(EMessageKey key)
Creates an empty message list instance with an initial capacity of ten.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E e)
Inserts the specified element at the specified position in this list.boolean
add(E e)
Appends the specified element to the end of this list.boolean
addAll(int index, java.util.Collection<? extends E> c)
Inserts all of the elements in the specified collection into this list, starting at the specified position.boolean
addAll(java.util.Collection<? extends E> c)
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.EMessageKey
key()
Returns the list element message key.E
set(int index, E e)
Replaces the element at the specified position in this list with the specified element.-
Methods inherited from class net.sf.eBus.messages.EAbstractList
clear, equals, hashCode, isReadOnly, iterator, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, setReadOnly, sort, subList
-
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, lastIndexOf, size, spliterator, toArray, toArray, trimToSize
-
-
-
-
Constructor Detail
-
EMessageList
public EMessageList(EMessageKey key)
Creates an empty message list instance with an initial capacity of ten.- Parameters:
key
- list elements must beeBus messages
containing this message key.- Throws:
java.lang.NullPointerException
- ifkey
isnull
.
-
EMessageList
public EMessageList(int initialCapacity, EMessageKey key)
Creates an empty message list instance with the specified initial capacity.- Parameters:
initialCapacity
- the list initial capacity.key
- list elements must beeBus messages
containing this message key.- Throws:
java.lang.NullPointerException
- ifkey
isnull
.
-
EMessageList
public EMessageList(java.util.Collection<E> c, EMessageKey key)
Creates a message list instance containing the same elements asc
and in the order returned by the collection's iterator.- Parameters:
c
- place this collection's elements into this message list.key
- list elements must beeBus messages
containing this message key.- Throws:
java.lang.NullPointerException
- if eitherc
orkey
isnull
.java.lang.IllegalArgumentException
- ifc
contains a message with a key that does not equalkey
.
-
-
Method Detail
-
add
public boolean add(E e)
Appends the specified element to the end of this list.- Specified by:
add
in interfacejava.util.Collection<E extends EMessage>
- Specified by:
add
in interfacejava.util.List<E extends EMessage>
- Overrides:
add
in classEAbstractList<E extends EMessage>
- Parameters:
e
- append this element to list.- Returns:
true
(as specified byCollection.add(E)
).- Throws:
java.lang.NullPointerException
- ife
isnull
.java.lang.IllegalArgumentException
- ife
does not have a correct message key which matches this list's key.java.lang.UnsupportedOperationException
- if this list is marked as read-only.
-
add
public void add(int index, E e)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).- Specified by:
add
in interfacejava.util.List<E extends EMessage>
- Overrides:
add
in classEAbstractList<E extends EMessage>
- Parameters:
index
- inserte
into list at this index.e
- insert this element into list.- Throws:
java.lang.NullPointerException
- ife
isnull
.java.lang.IllegalArgumentException
- ife
does not have a correct message key which matches this list's key.java.lang.IndexOutOfBoundsException
- ifindex
is out of range (index < 0 || index > this.size()
).java.lang.UnsupportedOperationException
- if this list is marked as read-only.
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
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. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this list, and this list is nonempty.)- Specified by:
addAll
in interfacejava.util.Collection<E extends EMessage>
- Specified by:
addAll
in interfacejava.util.List<E extends EMessage>
- Overrides:
addAll
in classEAbstractList<E extends EMessage>
- Parameters:
c
- append the elements ofc
to this list.- Returns:
true
if this list changed as a result of the call.- Throws:
java.lang.NullPointerException
- ifc
isnull
.java.lang.IllegalArgumentException
- ifc
contains elements that are eithernull
or messages that have message keys that do not match this list's message key.java.lang.UnsupportedOperationException
- if this list is marked as read-only.
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)
Inserts all of the elements in the specified collection into this list, starting at the specified position. 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 the list in the order that they are returned by the specified collection's iterator.- Specified by:
addAll
in interfacejava.util.List<E extends EMessage>
- Overrides:
addAll
in classEAbstractList<E extends EMessage>
- Parameters:
index
- insertc
's elements into this list at this index.c
- collection containing insertion elements.- Returns:
true
if this list changed as a result of the call.- Throws:
java.lang.NullPointerException
- ifc
isnull
.java.lang.IllegalArgumentException
- ifc
contains elements that are eithernull
or messages that have message keys that do not match this list's message key.java.lang.IndexOutOfBoundsException
- ifindex
is out of range (index < 0 || index > this.size()
).java.lang.UnsupportedOperationException
- if this list is marked as read-only.
-
set
public E set(int index, E e)
Replaces the element at the specified position in this list with the specified element.- Specified by:
set
in interfacejava.util.List<E extends EMessage>
- Overrides:
set
in classEAbstractList<E extends EMessage>
- Parameters:
index
- replace element at this index.e
- put this element at specified index.- Returns:
- the element previously at the specified position.
- Throws:
java.lang.NullPointerException
- ife
isnull
.java.lang.IllegalArgumentException
- ife
does not have a correct message key which matches this list's key.java.lang.IndexOutOfBoundsException
- ifindex
is out of range (index < 0 || index > this.size()
).java.lang.UnsupportedOperationException
- if this list is marked as read-only.
-
key
public EMessageKey key()
Returns the list element message key.- Returns:
- message key.
-
-