public ArrayList getClassesRuns() {
    classesRuns = new ArrayList<String>();

    StringBuffer classRun = new StringBuffer();
    StringBuffer testClassRun;

    for (int run = 1; run < 3; run++) {
      for (RaceRun r : getCompletedRunsByClassTime()) {
        if (r.getRunNumber() == run) {
          testClassRun = new StringBuffer();
          testClassRun.append(r.getBoat().getBoatClass());
          testClassRun.append(":");
          testClassRun.append(run);
          testClassRun.append(":");
          testClassRun.append(r.getStatusString());

          if (testClassRun.toString().compareTo(classRun.toString()) != 0) {
            classRun = testClassRun;
            classesRuns.add(classRun.toString());
          }
        }
      }
    }
    return (classesRuns);
  }
 public void markClassRun(String boatClass, int runNbr, RaceRun.Status status) {
   for (RaceRun r : getCompletedRunsByClassTime()) {
     if (r.getRunNumber() == runNbr) {
       if (r.getBoat().getBoatClass().compareTo(boatClass) == 0) {
         r.setStatus(status);
       }
     }
   }
   updateResults(true);
 }
  public RaceRun getExistingRun(BoatEntry be) { // todo Add Run#
    RaceRun run = null;
    for (RaceRun r : completedRuns) {
      if (r.getRunNumber() == currentRunIteration && r.getBoat() == be) {
        run = r;
        break;
      }
    }

    if (run == null) {
      for (RaceRun r : activeRuns) {
        if (r.getRunNumber() == currentRunIteration && r.getBoat() == be) {
          run = r;
          break;
        }
      }
    }

    return run;
  }
  private Result findRacer(RaceRun run) {
    Result result = null;
    for (Result r : results) {
      if (r.getRacer() == run.getBoat().getRacer()) {
        result = r;
        break;
      }
    }

    return result;
  }
 public boolean isDNF(String bibNumber, int runNumber) {
   boolean dnf = false;
   for (RaceRun rr : completedRuns) {
     if (rr.getBoat().getRacer().getBibNumber().equals(bibNumber)
         && rr.getRunNumber() == runNumber) {
       if (rr.isDnf()) {
         dnf = true;
       }
     }
   }
   return (dnf);
 }
  private boolean sameRun(RaceRun ourRun, RaceRun otherRun) {
    boolean same = false;
    BoatEntry b;
    Racer racer;
    String bib;
    try {
      b = ourRun.getBoat();
      racer = b.getRacer();
      bib = racer.getBibNumber();

      if (bib.compareTo(otherRun.getBoat().getRacer().getBibNumber()) == 0) {
        if (ourRun.getRunNumber() == otherRun.getRunNumber()) {
          same = true;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return (same);
  }
  private boolean sameRun(RaceRun ourRun, PhotoCellRaceRun otherRun) {
    boolean same = false;
    BoatEntry b;
    Racer racer;
    String bib;
    try {
      b = ourRun.getBoat();
      racer = b.getRacer();
      bib = racer.getBibNumber();

      if (bib.compareTo(otherRun.getBibNumber()) == 0) {
        // We only want to store real time Tag Heuer electronic eye times
        // with the current run
        if (ourRun.getRunNumber() == otherRun.getRunNumber()) {
          same = true;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return (same);
  }
  private ArrayList<Result> accumulateResults(ArrayList<RaceRun> runs) {
    Result res;
    results = new ArrayList<Result>();

    for (RaceRun r : runs) {
      res = findRacer(r);
      if (res == null) {
        res = new Result();
        results.add(res);
      }
      res.setRacer(r.getBoat().getRacer());
      res.setBoat(r.getBoat());

      switch (r.getRunNumber()) {
        case 1:
          res.setRun1(r);
          break;
        case 2:
          res.setRun2(r);
          break;
      }
    }

    float run1Time;
    float run2Time;
    for (Result res1 : results) {
      // run1Time = (float)999999.99;
      // run2Time = (float)999999.99;

      try {

        if (res1.getRun1() == null || res1.getRun2() == null) {
          if (res1.getRun1() == null) {
            res1.setBestRun(res1.getRun2());
          }
          if (res1.getRun2() == null) {
            res1.setBestRun(res1.getRun1());
          }
        } else {
          run1Time = res1.getRun1().getElapsed() + res1.getRun1().getTotalPenalties();
          run2Time = res1.getRun2().getElapsed() + res1.getRun2().getTotalPenalties();
          if (run1Time <= run2Time) {
            res1.setBestRun(res1.getRun1());
          } else {
            res1.setBestRun(res1.getRun2());
          }
        }
      } catch (Exception e) {
        log.write(e);
      }
    }

    ArrayList<Result> sorted = Result.getResultsByClassTime(results);
    results = sorted; // A10112013

    String lastBoatClass = "";
    int place = 1;

    for (Result r : sorted) {
      try {
        r.getRun1()
            .setGold(false); // / TODO: if skipping 1st runs fro some reason, this will cause a null
        // pointer reference
        r.getRun1().setSilver(false);
        r.getRun1().setBronze(false);
      } catch (NullPointerException e) {
        // Intentionally empty exception block
      }

      try {
        r.getRun2().setGold(false);
        r.getRun2().setSilver(false);
        r.getRun2().setBronze(false);
      } catch (NullPointerException e) {
        // Intentionally empty exception block
      }

      // todo check this logic   20141122
      try {
        if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) {
          lastBoatClass = r.getBoat().getBoatClass();
          place = 1;
        }
        switch (place) {
          case 1:
            r.getBestRun().setGold(true);
            break;
          case 2:
            r.getBestRun().setSilver(true);
            break;
          case 3:
            r.getBestRun().setBronze(true);
            break;
          default:
            break;
        }
      } catch (NullPointerException e) {
        // Intentionally empty exception block
      }

      r.getBestRun().setPlaceInClass(place++);
    }
    return (sorted);
  }
 public void updateResults(RaceRun run, boolean saveSerialized) {
   updateResults(saveSerialized); // /MUST FIX 2016 Nationals ERROR CONCurrentMpdificationException
   racerResultsHTTP.outputWeb(run.getBoat());
   // M161006    scoreboardResultsHTTP_New.outputWeb("Sorted", getCompletedRunsByClassTime(),
   // true);
 }