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, concreteEMessagetype 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 typeallows 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 thatnullmessages may not be added to a message list.The difference between
EMessageListandEMessage[]is thatEMessageListserializes the definingEMessageKeyonce and then each message instance in turn. This works becauseEMessageListitems 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
ByteBufferwhen 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 ascand 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 voidadd(int index, E e)Inserts the specified element at the specified position in this list.booleanadd(E e)Appends the specified element to the end of this list.booleanaddAll(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.booleanaddAll(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.EMessageKeykey()Returns the list element message key.Eset(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 messagescontaining this message key.- Throws:
java.lang.NullPointerException- ifkeyisnull.
-
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 messagescontaining this message key.- Throws:
java.lang.NullPointerException- ifkeyisnull.
-
EMessageList
public EMessageList(java.util.Collection<E> c, EMessageKey key)
Creates a message list instance containing the same elements ascand 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 messagescontaining this message key.- Throws:
java.lang.NullPointerException- if eithercorkeyisnull.java.lang.IllegalArgumentException- ifccontains 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:
addin interfacejava.util.Collection<E extends EMessage>- Specified by:
addin interfacejava.util.List<E extends EMessage>- Overrides:
addin classEAbstractList<E extends EMessage>- Parameters:
e- append this element to list.- Returns:
true(as specified byCollection.add(E)).- Throws:
java.lang.NullPointerException- ifeisnull.java.lang.IllegalArgumentException- ifedoes 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:
addin interfacejava.util.List<E extends EMessage>- Overrides:
addin classEAbstractList<E extends EMessage>- Parameters:
index- inserteinto list at this index.e- insert this element into list.- Throws:
java.lang.NullPointerException- ifeisnull.java.lang.IllegalArgumentException- ifedoes not have a correct message key which matches this list's key.java.lang.IndexOutOfBoundsException- ifindexis 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:
addAllin interfacejava.util.Collection<E extends EMessage>- Specified by:
addAllin interfacejava.util.List<E extends EMessage>- Overrides:
addAllin classEAbstractList<E extends EMessage>- Parameters:
c- append the elements ofcto this list.- Returns:
trueif this list changed as a result of the call.- Throws:
java.lang.NullPointerException- ifcisnull.java.lang.IllegalArgumentException- ifccontains elements that are eithernullor 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:
addAllin interfacejava.util.List<E extends EMessage>- Overrides:
addAllin classEAbstractList<E extends EMessage>- Parameters:
index- insertc's elements into this list at this index.c- collection containing insertion elements.- Returns:
trueif this list changed as a result of the call.- Throws:
java.lang.NullPointerException- ifcisnull.java.lang.IllegalArgumentException- ifccontains elements that are eithernullor messages that have message keys that do not match this list's message key.java.lang.IndexOutOfBoundsException- ifindexis 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:
setin interfacejava.util.List<E extends EMessage>- Overrides:
setin 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- ifeisnull.java.lang.IllegalArgumentException- ifedoes not have a correct message key which matches this list's key.java.lang.IndexOutOfBoundsException- ifindexis 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.
-
-