edu.umich.eecs.tac.props
Class AbstractTransportableEntryListBacking<S extends se.sics.isl.transport.Transportable>

java.lang.Object
  extended by edu.umich.eecs.tac.props.AbstractTransportable
      extended by edu.umich.eecs.tac.props.AbstractTransportableEntryListBacking<S>
Type Parameters:
S - the transportable class this object is backing.
All Implemented Interfaces:
java.io.Serializable, se.sics.isl.transport.Transportable
Direct Known Subclasses:
AbstractKeyedEntryList

public abstract class AbstractTransportableEntryListBacking<S extends se.sics.isl.transport.Transportable>
extends AbstractTransportable

This class provides a skeletal implementation of a list of transportables. The class if backed by an ArrayList.

Author:
Patrick Jordan
See Also:
Serialized Form

Constructor Summary
protected AbstractTransportableEntryListBacking()
          Sole constructor.
 
Method Summary
protected  int addEntry(S entry)
          Appends the specified entry to the end of this list.
protected  void afterAddEntry(S entry)
          Callback that is invoked before the entry is added to the backing list in the removeEntry(int) call.
protected  void afterRemoveEntry(int index)
          Callback that is invoked after the entry is removed from the backing list in the removeEntry(int) call.
protected  void beforeAddEntry(S entry)
          Callback that is invoked before the entry is added to the backing list in the removeEntry(int) call.
protected  void beforeRemoveEntry(int index)
          Callback that is invoked before the entry is removed from the backing list in the removeEntry(int) call.
protected abstract  java.lang.Class entryClass()
          Returns class of the entries.
protected  java.util.List<S> getEntries()
          Returns the backing entry list.
protected  S getEntry(int index)
          Returns the entry at the specified index in this list.
protected  void readAfterEntries(se.sics.isl.transport.TransportReader reader)
          Reads from the reader after the entry nodes have been read.
protected  void readBeforeEntries(se.sics.isl.transport.TransportReader reader)
          Reads from the reader before the entry nodes have been read.
protected  void readWithLock(se.sics.isl.transport.TransportReader reader)
          Reads a list of entry transportables from the reader.
protected  void removeEntry(int index)
          Removes the entry at the specified index in this list.
 int size()
          Return the number of entries in the list.
 java.lang.String toString()
          Returns a string that lists in the form (SimpleName [before] (entry1) ...
protected  void toStringAfterEntries(java.lang.StringBuilder builder)
          Appends the builder after the entries are written to the builder.
protected  void toStringBeforeEntries(java.lang.StringBuilder builder)
          Appends the builder before the entries are written to the builder.
protected  void writeAfterEntries(se.sics.isl.transport.TransportWriter writer)
          Writes to the writer after the entry nodes have been written.
protected  void writeBeforeEntries(se.sics.isl.transport.TransportWriter writer)
          Writes to the writer before the entry nodes have been written.
protected  void writeWithLock(se.sics.isl.transport.TransportWriter writer)
          Writes a list of entry transportables to the writer.
 
Methods inherited from class edu.umich.eecs.tac.props.AbstractTransportable
getTransportName, isLocked, lock, lockCheck, read, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractTransportableEntryListBacking

protected AbstractTransportableEntryListBacking()
Sole constructor. (For invocation by subclass constructors, typically implicit.)

Constructs an empty backing list with an initial capacity of ten.

Method Detail

getEntries

protected final java.util.List<S> getEntries()
Returns the backing entry list.

Returns:
the backing entry list.

size

public final int size()
Return the number of entries in the list.

Returns:
the number of entries in the list.

toStringBeforeEntries

protected void toStringBeforeEntries(java.lang.StringBuilder builder)
Appends the builder before the entries are written to the builder.

Parameters:
builder - the builder to append for the toString()

toString

public final java.lang.String toString()
Returns a string that lists in the form (SimpleName [before] (entry1) ... (entryN) [after]), where (entry1) is the contents of the toString method for the entry.

Overrides:
toString in class java.lang.Object
Returns:
a string created from appending the toString method in the entries.

toStringAfterEntries

protected void toStringAfterEntries(java.lang.StringBuilder builder)
Appends the builder after the entries are written to the builder.

Parameters:
builder - the builder to append for the toString()

readBeforeEntries

protected void readBeforeEntries(se.sics.isl.transport.TransportReader reader)
                          throws java.text.ParseException
Reads from the reader before the entry nodes have been read.

Parameters:
reader - the reader that is read from.
Throws:
java.text.ParseException - if a parse exception occurs before reading in the entries.

readAfterEntries

protected void readAfterEntries(se.sics.isl.transport.TransportReader reader)
                         throws java.text.ParseException
Reads from the reader after the entry nodes have been read.

Parameters:
reader - the reader that is read from.
Throws:
java.text.ParseException - if a parse exception occurs after reading in the entries.

readWithLock

protected final void readWithLock(se.sics.isl.transport.TransportReader reader)
                           throws java.text.ParseException
Reads a list of entry transportables from the reader.

Specified by:
readWithLock in class AbstractTransportable
Parameters:
reader - the reader to read the data in.
Throws:
java.text.ParseException - if a parse exception occurs when reading in the entries.

writeWithLock

protected final void writeWithLock(se.sics.isl.transport.TransportWriter writer)
Writes a list of entry transportables to the writer.

Specified by:
writeWithLock in class AbstractTransportable
Parameters:
writer - the writer to write the data out to.

writeAfterEntries

protected void writeAfterEntries(se.sics.isl.transport.TransportWriter writer)
Writes to the writer after the entry nodes have been written. Implementing classes should not write attributes without enclosing them in nodes.

Parameters:
writer - the writer that is written to.

writeBeforeEntries

protected void writeBeforeEntries(se.sics.isl.transport.TransportWriter writer)
Writes to the writer before the entry nodes have been written.

Parameters:
writer - the writer that is written to.

getEntry

protected final S getEntry(int index)
                                                                throws java.lang.IndexOutOfBoundsException
Returns the entry at the specified index in this list.

Parameters:
index - the index of entry to return
Returns:
the entry at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).

removeEntry

protected final void removeEntry(int index)
                          throws java.lang.IllegalStateException
Removes the entry at the specified index in this list. Shifts any subsequent entries to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters:
index - the index of the element to removed.
Throws:
java.lang.IllegalStateException - if the object is locked

beforeRemoveEntry

protected void beforeRemoveEntry(int index)
Callback that is invoked before the entry is removed from the backing list in the removeEntry(int) call.

Parameters:
index - the index to remove.

afterRemoveEntry

protected void afterRemoveEntry(int index)
Callback that is invoked after the entry is removed from the backing list in the removeEntry(int) call.

Parameters:
index - the index to remove.

addEntry

protected final int addEntry(S entry)
                      throws java.lang.IllegalStateException
Appends the specified entry to the end of this list.

Parameters:
entry - the entry to be appended to the list
Returns:
the index of the new entry. -1 if the entry was not added.
Throws:
java.lang.IllegalStateException - if the object is locked

beforeAddEntry

protected void beforeAddEntry(S entry)
                       throws java.lang.IllegalStateException
Callback that is invoked before the entry is added to the backing list in the removeEntry(int) call.

Parameters:
entry - the entry to be added.
Throws:
java.lang.IllegalStateException - if the method is modifying state

afterAddEntry

protected void afterAddEntry(S entry)
                      throws java.lang.IllegalStateException
Callback that is invoked before the entry is added to the backing list in the removeEntry(int) call.

Parameters:
entry - the entry to be added.
Throws:
java.lang.IllegalStateException - if the method is modifying state

entryClass

protected abstract java.lang.Class entryClass()
Returns class of the entries. The Class.getSimpleName() simple name} of the class will determine how the entries are read in by the TransportReader. Implementing classes should return the class of the generic parameter T.

Returns:
the class of the entries.


Copyright © 2007-2009 Association for Trading Agent Research. All Rights Reserved.