anthill.types
Class ArrayReturnPath

java.lang.Object
  |
  +--anthill.types.ArrayReturnPath
All Implemented Interfaces:
ReturnPath

public class ArrayReturnPath
extends Object
implements ReturnPath

Version:
$Revision: 1.3 $
Author:
Alberto Montresor

Constructor Summary
ArrayReturnPath()
          Constructs a new empty return path.
ArrayReturnPath(Factory factory, String name)
          Constructs a new empty return path.
 
Method Summary
 boolean addLast(AntView view, NestId id)
          Adds a new element to the path.
 int capacity()
          Return the current length of the path.
 void init(AntView view)
          Initializes this data structure.
 NestId removeLast(AntView view)
          Removes the last element of the path and returns it to the invoker.
 int size()
          Return the current length of the path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayReturnPath

public ArrayReturnPath(Factory factory,
                       String name)
Constructs a new empty return path. Actual initialization will be postponed to method init, when a view is available. This constructor is used by the factory mechanism.

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

ArrayReturnPath

public ArrayReturnPath()
Constructs a new empty return path. Actual initialization will be postponed to method init, when a view is available.

Method Detail

init

public void init(AntView view)
Initializes this data structure. This method must be invoked at most once, for example in the init method of ants.
The initialization is performed by creating an array capable to contain TTL/2 elements.

Specified by:
init in interface ReturnPath
Parameters:
view - the current view associated to the ant using this data structure

addLast

public boolean addLast(AntView view,
                       NestId id)
Adds a new element to the path. Returns true if this element already belongs to the path, false otherwise. Depending on the implementation, if the element already belongs to the path, the element may be added again or not.
The element is searched by performing a linear search in the array. If found, true is returned. In any case, the element is added to the path.

Specified by:
addLast in interface ReturnPath
Parameters:
view - the current view associated to the ant using this data structure
Throws:
NullPointerException - if id is null

removeLast

public NestId removeLast(AntView view)
Removes the last element of the path and returns it to the invoker. Returns null if there are no more elements in the path.
The element is removed by simply reducing variable size.

Specified by:
removeLast in interface ReturnPath
Parameters:
view - the current view associated to the ant using this data structure

size

public int size()
Return the current length of the path.

Specified by:
size in interface ReturnPath

capacity

public int capacity()
Return the current length of the path.

Specified by:
capacity in interface ReturnPath