anthill.nestor
Class LocalTrail
java.lang.Object
|
+--anthill.nestor.LocalTrail
- All Implemented Interfaces:
- Clearable, Trail
- public class LocalTrail
- extends java.lang.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$
- Author:
- Alberto Montresor
Field Summary |
protected Factory |
factory
Factory used to instantiate objects |
static java.lang.String |
TRAIL_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 java.lang.String |
TRAIL_MAXTIME
The identifier of the configuration parameter containing the
maximum time of permanence of a pair (ant id, nest id) in a
Trail object. |
Constructor Summary |
LocalTrail(Factory factory)
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. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
TRAIL_MAXSIZE
public static final java.lang.String TRAIL_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.
TRAIL_MAXTIME
public static final java.lang.String TRAIL_MAXTIME
- The identifier of the configuration parameter containing the
maximum time of permanence of a pair (ant id, nest id) in a
Trail
object.
factory
protected Factory factory
- Factory used to instantiate objects
LocalTrail
public LocalTrail(Factory factory)
- 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 object used to obtain the configuration
values
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
- Following copied from interface:
anthill.nest.Trail
- Parameters:
id
- the identifier of the antremove
- true if the association (ant id, nest id)
should be removed after retrieval
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object