anthill.storage.impl
Class LocalTrail

java.lang.Object
  |
  +--anthill.storage.impl.LocalTrail
All Implemented Interfaces:
Clearable, ResourceManager, Trail

public class LocalTrail
extends Object
implements Trail

Class LocalTrail is the implementation of Trail to be used during off-line simulations. Programmers are enabled to specify the maximum number of associations (ant identifier, previous nest identifier) which can be stored in a LocalTrail object, or the maximum duration of such an associations in a LocalTrail object, or both. Assocations which exceed the maximum capacity or are older than the maximum duration are discarded from this LocalTrail.

Version:
$Revision: 1.2 $
Author:
Alberto Montresor

Field Summary
static String PAR_MAXSIZE
          The identifier of the configuration parameter containing the maximum number of pairs (ant id, nest id) that may be stored in a Trail object.
static String PAR_MAXTIME
          The identifier of the configuration parameter containing the maximum time of permanence of a pair (ant id, nest id) in a Trail object.
 
Fields inherited from interface anthill.storage.Trail
NAME
 
Constructor Summary
LocalTrail(Factory factory, String name)
          Instantiate a new empty Trail object.
 
Method Summary
 boolean add(AntId id, NestId source)
          Add a pair (id, source) to the trail object containing the host.
 void clear()
          Restores the object to its initial state.
 NestId lookup(AntId id, boolean remove)
          Lookup this LocalTrail object in order to obtain the identifier of the nest from which the specified ant arrived.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PAR_MAXSIZE

public static final String PAR_MAXSIZE
The identifier of the configuration parameter containing the maximum number of pairs (ant id, nest id) that may be stored in a Trail object.

See Also:
Constant Field Values

PAR_MAXTIME

public static final String PAR_MAXTIME
The identifier of the configuration parameter containing the maximum time of permanence of a pair (ant id, nest id) in a Trail object.

See Also:
Constant Field Values
Constructor Detail

LocalTrail

public LocalTrail(Factory factory,
                  String name)
Instantiate a new empty Trail object. The maximum number of pairs (ant id, source) that may be contained in it, and the maximum duration of pairs are read through the factory object.

Parameters:
factory - the factory to be used to read configuration arguments and to create other configurable objects
name - the name that is associated to this instance in the configuration file
Method Detail

clear

public void clear()
Restores the object to its initial state.

Specified by:
clear in interface Clearable

add

public boolean add(AntId id,
                   NestId source)
Add a pair (id, source) to the trail object containing the host. Returns true if the ant identifier is not already included in this Trail object; return false otherwise. The "false" notification can be used to detect duplicated visit to a nest.

Specified by:
add in interface Trail

lookup

public NestId lookup(AntId id,
                     boolean remove)
Lookup this LocalTrail object in order to obtain the identifier of the nest from which the specified ant arrived. The pair associating the ant identifier to the source nest is removed from both the hash table and the linked list.

Specified by:
lookup in interface Trail
Parameters:
id - the identifier of the ant
remove - true if the association (ant id, nest id) should be removed after retrieval

toString

public String toString()
Overrides:
toString in class Object