protected void checkIntegrity(){
  PrintStream errors=System.err;
  Hashtable otherIntersections=new Hashtable();
  Object bothIntersections=new Object();
  Object inRoadsVector=new Object();
  for (Enumeration e=intersections.elements(); e.hasMoreElements(); ) {
    Intersection intersection=(Intersection)e.nextElement();
    int nRoads=intersection.getRoadCount();
    if (nRoads == 0) {
      errors.println("Dangling intersection");
      errors.println("  Intersection = " + intersection);
      continue;
    }
    for (int i=0; i < nRoads; i++) {
      Road road=intersection.getRoad(i);
      Object other=otherIntersections.get(road);
      if (other == null) {
        otherIntersections.put(road,road.getOtherIntersection(intersection));
      }
 else       if (other == intersection) {
        otherIntersections.put(road,bothIntersections);
      }
 else {
        errors.println("Misconnected");
        errors.println("          Road = " + road);
        errors.println("    Road.Other = " + other);
        errors.println("  Intersection = " + intersection);
      }
    }
  }
  for (Enumeration e=roads.elements(); e.hasMoreElements(); ) {
    Road road=(Road)e.nextElement();
    Object other=otherIntersections.get(road);
    if (other == null) {
      errors.println("Road not found in intersections");
      errors.println("          Road = " + road);
    }
 else     if (other != bothIntersections) {
      errors.println("Road incompletely connected");
      errors.println("          Road = " + road);
      errors.println("    Road.Other = " + other);
    }
 else     if (other == inRoadsVector) {
      errors.println("Road doubly listed");
      errors.println("          Road = " + road);
    }
    otherIntersections.put(road,inRoadsVector);
  }
  for (Enumeration e=otherIntersections.keys(); e.hasMoreElements(); ) {
    Road road=(Road)e.nextElement();
    Object other=otherIntersections.get(road);
    if (other != inRoadsVector) {
      errors.println("Road not listed");
      errors.println("          Road = " + road);
    }
  }
}

protected void checkIntegrity ( ) { PrintStream errors = System . err ; Hashtable otherIntersections = new Hashtable ( ) ; Object bothIntersections = new Object ( ) ; Object inRoadsVector = new Object ( ) ; for ( Enumeration e = intersections . elements ( ) ; e . hasMoreElements ( ) ; ) { Intersection intersection = ( Intersection ) e . nextElement ( ) ; int nRoads = intersection . getRoadCount ( ) ; if ( nRoads == 0 ) { errors . println ( "Dangling intersection" ) ; errors . println ( "  Intersection = " + intersection ) ; continue ; } for ( int i = 0 ; i < nRoads ; i ++ ) { Road road = intersection . getRoad ( i ) ; Object other = otherIntersections . get ( road ) ; if ( other == null ) { otherIntersections . put ( road , road . getOtherIntersection ( intersection ) ) ; } else if ( other == intersection ) { otherIntersections . put ( road , bothIntersections ) ; } else { errors . println ( "Misconnected" ) ; errors . println ( "          Road = " + road ) ; errors . println ( "    Road.Other = " + other ) ; errors . println ( "  Intersection = " + intersection ) ; } } } for ( Enumeration e = roads . elements ( ) ; e . hasMoreElements ( ) ; ) { Road road = ( Road ) e . nextElement ( ) ; Object other = otherIntersections . get ( road ) ; if ( other == null ) { errors . println ( "Road not found in intersections" ) ; errors . println ( "          Road = " + road ) ; } else if ( other != bothIntersections ) { errors . println ( "Road incompletely connected" ) ; errors . println ( "          Road = " + road ) ; errors . println ( "    Road.Other = " + other ) ; } else if ( other == inRoadsVector ) { errors . println ( "Road doubly listed" ) ; errors . println ( "          Road = " + road ) ; } otherIntersections . put ( road , inRoadsVector ) ; } for ( Enumeration e = otherIntersections . keys ( ) ; e . hasMoreElements ( ) ; ) { Road road = ( Road ) e . nextElement ( ) ; Object other = otherIntersections . get ( road ) ; if ( other != inRoadsVector ) { errors . println ( "Road not listed" ) ; errors . println ( "          Road = " + road ) ; } } }
check the integrity of our data structures . scan the known intersections . note intersections with no roads . scan the roads of the intersection : each road has two intersections . if the road has already been encountered , then we recorded its " other " intersection and that must match this intersection . if it doesn ' t match , record an error . if it does match reset its recorded other intersection to be a special marker indicating that both ends of the road have been accounted for . if the road has not already been encountered , then record its " other " intersection . scan the known roads . every road should accounted for in the " other " intersection table and should be marked as having both intersections accounted for . note the roads which were not found in the first scan and the roads which were found , but for which both intersections were not found . remark every road . finally scan the other intersection table for entries which were not marked as being in the roads vector .
