edu.umich.eecs.tac.props
Class AbstractKeyedEntryList<T,S extends KeyedEntry<T>>

java.lang.Object
  extended by edu.umich.eecs.tac.props.AbstractTransportable
      extended by edu.umich.eecs.tac.props.AbstractTransportableEntryListBacking<S>
          extended by edu.umich.eecs.tac.props.AbstractKeyedEntryList<T,S>
Type Parameters:
T - key class
S - entry class
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<T>, se.sics.isl.transport.Transportable
Direct Known Subclasses:
AbstractAdvertiserKeyedReportTransportable, AbstractQueryKeyedReportTransportable, RetailCatalog, UserPopulationState

public abstract class AbstractKeyedEntryList<T,S extends KeyedEntry<T>>
extends AbstractTransportableEntryListBacking<S>
implements java.lang.Iterable<T>

This class provides a skeletal implementation of a list containing keyed entries with supporting methods for interacting entries specified by a given key.

Author:
Patrick Jordan
See Also:
Serialized Form

Constructor Summary
AbstractKeyedEntryList()
           
 
Method Summary
protected  int addKey(T key)
          Adds a new key to the list.
 boolean containsKey(T key)
          Returns true if the key is in the list and false otherwise.
protected abstract  S createEntry(T key)
          Creates a new entry with the given key.
protected  S getEntry(T key)
          Returns the entry with the specified key.
protected  T getKey(int index)
          Returns the key for the entry at the index.
 int indexForEntry(T key)
          Returns the index for the entry specified by the key.
 java.util.Iterator<T> iterator()
          Returns an iterator over the keys in the list.
 java.util.Set<T> keys()
          Returns the set of keys for the entries.
 
Methods inherited from class edu.umich.eecs.tac.props.AbstractTransportableEntryListBacking
addEntry, afterAddEntry, afterRemoveEntry, beforeAddEntry, beforeRemoveEntry, entryClass, getEntries, getEntry, readAfterEntries, readBeforeEntries, readWithLock, removeEntry, size, toString, toStringAfterEntries, toStringBeforeEntries, writeAfterEntries, writeBeforeEntries, writeWithLock
 
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

AbstractKeyedEntryList

public AbstractKeyedEntryList()
Method Detail

indexForEntry

public final int indexForEntry(T key)
Returns the index for the entry specified by the key.

Parameters:
key - the key for the entry to be found.
Returns:
the index for the entry specified by the key. -1 if the key is not in the list.

iterator

public final java.util.Iterator<T> iterator()
Returns an iterator over the keys in the list.

Specified by:
iterator in interface java.lang.Iterable<T>
Returns:
an iterator over the keys in the list.

containsKey

public final boolean containsKey(T key)
Returns true if the key is in the list and false otherwise.

Parameters:
key - the key to check for containment.
Returns:
true if the key is in the list and false otherwise.

addKey

protected final int addKey(T key)
                    throws java.lang.NullPointerException
Adds a new key to the list. The createEntry(T) method creates the new entry with the specified key.

Parameters:
key - the key used to add the new entry.
Returns:
the index of the newly generated entry.
Throws:
java.lang.NullPointerException - if the key is null.

createEntry

protected abstract S createEntry(T key)
Creates a new entry with the given key.

Parameters:
key - the key for the created entry.
Returns:
the created entry with the given key.

keys

public final java.util.Set<T> keys()
Returns the set of keys for the entries. A new set is created each time the method is called.

Returns:
the set of keys for the entries.

getKey

protected final T getKey(int index)
                  throws java.lang.IndexOutOfBoundsException
Returns the key for the entry at the index.

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

getEntry

protected final S getEntry(T key)
Returns the entry with the specified key.

Parameters:
key - the key used to identify the entry.
Returns:
the entry with the specified key or null if the key is not found.


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