
import EDU.neu.ccs.demeter.dj.*;
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    ClassGraph cg = new ClassGraph(); // constructed from *.java
    System.out.println(cg.version() + " = version");
    System.out.println(cg + " Class graph ");        

    // 1 person at second nested bus route
    // but is used twice
    PersonList persons2 = new PersonList();
    persons2.addElement(new Person());
    BusStop aBusStop2 = new BusStop(persons2);
    MyVector busStops2 = new MyVector();
    busStops2.addElement(aBusStop2);
    BusRoute aBusRoute2 = new BusRoute(null, busStops2);

    // 5 people
    PersonList persons = new PersonList();
    persons.addElement(new Person());
    persons.addElement(new Person());
    persons.addElement(new Person());
    persons.addElement(new Person());
    persons.addElement(new Person());
    BusStop aBusStop = new BusStop(persons,aBusRoute2);

    MyVector busStops = new MyVector();
    // 10 people
    busStops.addElement(aBusStop);
    busStops.addElement(aBusStop);

    PersonList personsArray = new PersonList();
    personsArray.addElement(new Person());
// was not intended but should work
    MyVector buses = new MyVector();
    buses.addElement(persons);
    buses.addElement(persons);
    buses.addElement(personsArray);

    BusRoute aBusRoute = new BusRoute(buses, busStops);
    
    String wysiwyg = " bypassing {BusRoute,BusStop,Person} ";
    // Strategy sg = new Strategy("from BusRoute through BusStop to Person");
    Strategy sg = new Strategy(
    "from BusRoute" + wysiwyg +
      "through BusStop" + wysiwyg + 
    "to Person");
    // Strategy sg = new Strategy(
    // "{BusRoute -> BusStop bypassing {BusRoute,BusStop,Person} BusStop -> Person bypassing {BusRoute,BusStop,Person}}");

/*
    Strategy sg = new Strategy(
     "{" +
       "BusRoute -> BusStop" + wysiwyg +
       "BusStop -> Person" + wysiwyg + 
       "BusStop -> BusRoute" + wysiwyg +
     "}");
*/
    System.out.println(sg + " Strategy graph ");        

    TraversalGraph tg = TraversalGraph.compute(cg, sg);
    System.out.println
      ("Traversal Graph for from BusRoute through BusStop to Person");
    System.out.println(tg);        
    System.out.println
      ("Summarized Traversal Graph for from BusRoute through BusStop to Person");
    System.out.println(tg.toClassGraph());        

    Integer result = (Integer) tg.traverse(aBusRoute, new MyVisitor());
    int r = result.intValue();
    if (r==10) {System.out.println("SUCCESS");}
    else {System.out.println("FAILURE");};
    System.out.println(" number of waiting persons = " + result);

    InputIterator beginDs = tg.start(aBusRoute);
    InputIterator endDs = tg.finish(aBusRoute);
    Printing.println(beginDs, endDs);

    Enumeration e = tg.elements(aBusRoute);
    while (e.hasMoreElements())
      System.out.println(e.nextElement());


  }
}

