//Marcus Deniels Dec. 7, 1999 swarm-support


import swarm.defobj.Zone;
import swarm.collections.List;
import swarm.collections.Map;
import swarm.collections.MapImpl;
import swarm.collections.MapIndex;
import swarm.collections.ListImpl;
import swarm.collections.ListIndex;
import swarm.Globals;

public class TestIndex {
  List list;
  Map map;

  class Agent {
    int value;

    Agent (int value) {
      super ();

      this.value = value;
    }
    
    int getValue () {
      return value;
    }
  }
  
  TestIndex () {
    super ();
  }

  void checkListIndex (Zone aZone) {
    list = new ListImpl (aZone);

    list.addLast (new Agent (1));
    list.addLast (new Agent (2));
    
    ListIndex index = list.listBegin (aZone);
    Object obj;

    while ((obj = index.next ()) != null) {
      System.out.println (((Agent) obj).getValue ());
    }
  }

  void checkMapIndex (Zone aZone) {
    map = new MapImpl (aZone);
    
    map.at$insert (new Integer (4), new Agent (5));
    map.at$insert (new Integer (6), new Agent (7));

    MapIndex index = map.mapBegin (aZone);
    Object obj;

    while ((obj = index.next ()) != null) {
      System.out.println (((Agent) obj).getValue ());
    }
  }
  
  public static void main (String[] args) {
    Zone aZone = Globals.env.globalZone;
    Globals.env.initSwarm ("testIndex",
                           "2.0.1", "bug-swarm@santafe.edu",
                           args);
    TestIndex testIndex = new TestIndex ();
    testIndex.checkListIndex (aZone);
    testIndex.checkMapIndex (aZone);
  }
}
