class Zonation {

  private final Map<Unit, Zone> unitToZone;
  private int zoneCount;

  public Zonation(StmtBody body) {
    final Chain<Unit> units = body.getUnits();
    this.zoneCount = 0;
    this.unitToZone = new HashMap<Unit, Zone>(units.size() * 2 + 1, 0.7f);

    // Build trap boundaries
    Map<Unit, List<Trap>> unitToTrapBoundaries = new HashMap<Unit, List<Trap>>();
    for (Trap t : body.getTraps()) {
      addTrapBoundary(t.getBeginUnit(), t, unitToTrapBoundaries);
      addTrapBoundary(t.getEndUnit(), t, unitToTrapBoundaries);
    }

    // Traverse units, assigning each to a zone
    Map<List<Trap>, Zone> trapListToZone = new HashMap<List<Trap>, Zone>(10, 0.7f);
    List<Trap> currentTraps = new ArrayList<Trap>();

    // Initialize first empty zone
    Zone currentZone = new Zone("0");
    trapListToZone.put(new ArrayList<Trap>(), currentZone);

    for (Unit u : units) {
      // Process trap boundaries
      {
        List<Trap> trapBoundaries = unitToTrapBoundaries.get(u);
        if (trapBoundaries != null && !trapBoundaries.isEmpty()) {
          for (Trap trap : trapBoundaries) {
            if (currentTraps.contains(trap)) {
              currentTraps.remove(trap);
            } else {
              currentTraps.add(trap);
            }
          }

          if (trapListToZone.containsKey(currentTraps)) {
            currentZone = trapListToZone.get(currentTraps);
          } else {
            // Create a new zone
            zoneCount++;
            currentZone = new Zone(Integer.toString(zoneCount));
            trapListToZone.put(currentTraps, currentZone);
          }
        }
      }

      unitToZone.put(u, currentZone);
    }
  }

  private void addTrapBoundary(Unit unit, Trap t, Map<Unit, List<Trap>> unitToTrapBoundaries) {
    List<Trap> boundary = unitToTrapBoundaries.get(unit);
    if (boundary == null) {
      boundary = new ArrayList<Trap>();
      unitToTrapBoundaries.put(unit, boundary);
    }
    boundary.add(t);
  }

  public Zone getZoneOf(Unit u) {<FILL_FUNCTION_BODY>}

  public int getZoneCount() {
    return zoneCount;
  }
}

    Zone z = unitToZone.get(u);
    if (z == null) {
      throw new RuntimeException("null zone!");
    } else {
      return z;
    }
  
<no_super_class>