Program: 33758
Project: 33758
Buggy source:
/** 
 * Determines the past/current status of a team at an event.
 * @param e       the event the team is competing at
 * @param teamMatches team's match list
 * @param teamKey key associated with team
 * @return team's past/current event status
 */
public static EventStatus evaluateStatusOfTeam(Event e,ArrayList<Match> teamMatches,String teamKey) throws BasicModel.FieldNotDefinedException {
  JsonArray alliances=e.getAlliances();
  boolean inAlliance=false;
  if (alliances.size() == 0) {
    inAlliance=MatchHelper.getAllianceForTeam(teamMatches,teamKey) != -1;
  }
 else {
    for (int i=0; i < alliances.size(); i++) {
      JsonArray teams=alliances.get(i).getAsJsonObject().get("String_Node_Str").getAsJsonArray();
      for (int j=0; j < teams.size(); j++) {
        if (teams.get(j).getAsString().equals(teamKey)) {
          inAlliance=true;
        }
      }
    }
  }
  ArrayList<Match> qualMatches=new ArrayList<>();
  ArrayList<Match> quarterMatches=new ArrayList<>();
  ArrayList<Match> semiMatches=new ArrayList<>();
  ArrayList<Match> finalMatches=new ArrayList<>();
  ArrayList<Match> currentGroup=qualMatches;
  TYPE lastType=null;
  boolean teamIsHere=false;
  for (  Match match : teamMatches) {
    match.setSelectedTeam(teamKey);
    JsonObject matchAlliances=match.getAlliances();
    JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
    if (redTeams.toString().contains(teamKey) || blueTeams.toString().contains(teamKey)) {
      teamIsHere=true;
    }
    if (lastType != match.getType()) {
switch (match.getType()) {
case QUAL:
        currentGroup=qualMatches;
      break;
case QUARTER:
    currentGroup=quarterMatches;
  break;
case SEMI:
currentGroup=semiMatches;
break;
case FINAL:
currentGroup=finalMatches;
break;
}
}
currentGroup.add(match);
}
Log.d(Constants.LOG_TAG,"String_Node_Str" + qualMatches.size());
Log.d(Constants.LOG_TAG,"String_Node_Str" + quarterMatches.size());
Log.d(Constants.LOG_TAG,"String_Node_Str" + semiMatches.size());
Log.d(Constants.LOG_TAG,"String_Node_Str" + finalMatches.size());
if (e.isHappeningNow() && quarterMatches.size() == 0) {
return EventStatus.PLAYING_IN_QUALS;
}
boolean allQualMatchesPlayed=true;
for (Match match : qualMatches) {
if (!match.hasBeenPlayed()) {
Log.d(Constants.LOG_TAG,"String_Node_Str" + match.getKey() + "String_Node_Str");
allQualMatchesPlayed=false;
break;
}
}
Log.d(Constants.LOG_TAG,"String_Node_Str" + inAlliance);
Log.d(Constants.LOG_TAG,"String_Node_Str" + allQualMatchesPlayed);
if (qualMatches.isEmpty() || (allQualMatchesPlayed && !teamIsHere)) {
return EventStatus.NOT_AVAILABLE;
}
 else if ((allQualMatchesPlayed && !inAlliance) || (!e.isHappeningNow() && (quarterMatches.isEmpty() && semiMatches.isEmpty() && finalMatches.isEmpty()))) {
return EventStatus.NOT_PICKED;
}
if (!quarterMatches.isEmpty()) {
int countPlayed=0, countWon=0;
for (Match match : quarterMatches) {
if (match.hasBeenPlayed()) {
JsonObject matchAlliances=match.getAlliances();
JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
if (!redTeams.toString().contains(teamKey + "String_Node_Str") && !blueTeams.toString().contains(teamKey + "String_Node_Str")) {
continue;
}
countPlayed++;
if (match.didSelectedTeamWin()) {
countWon++;
}
}
}
if (countPlayed > 1 && countWon > 1) {
}
 else if ((countPlayed > 1 && countWon == 0) || (countPlayed > 2 && countWon == 1)) {
return EventStatus.ELIMINATED_IN_QUARTERS;
}
 else if (!e.isHappeningNow() && semiMatches.isEmpty()) {
return EventStatus.ELIMINATED_IN_QUARTERS;
}
 else {
return EventStatus.PLAYING_IN_QUARTERS;
}
}
if (!semiMatches.isEmpty()) {
int countPlayed=0, countWon=0;
for (Match match : semiMatches) {
if (match.hasBeenPlayed()) {
JsonObject matchAlliances=match.getAlliances();
JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
if (!redTeams.toString().contains(teamKey + "String_Node_Str") && !blueTeams.toString().contains(teamKey + "String_Node_Str")) {
continue;
}
countPlayed++;
if (match.didSelectedTeamWin()) {
countWon++;
}
}
}
if (countPlayed > 1 && countWon > 1) {
}
 else if ((countPlayed > 1 && countWon == 0) || (countPlayed > 2 && countWon == 1)) {
return EventStatus.ELIMINATED_IN_SEMIS;
}
 else if (!e.isHappeningNow() && finalMatches.isEmpty()) {
return EventStatus.ELIMINATED_IN_SEMIS;
}
 else {
return EventStatus.PLAYING_IN_SEMIS;
}
}
if (!finalMatches.isEmpty()) {
int countPlayed=0, countWon=0;
for (Match match : finalMatches) {
if (match.hasBeenPlayed()) {
JsonObject matchAlliances=match.getAlliances();
JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
if (!redTeams.toString().contains(teamKey + "String_Node_Str") && !blueTeams.toString().contains(teamKey + "String_Node_Str")) {
continue;
}
countPlayed++;
if (match.didSelectedTeamWin()) {
countWon++;
}
}
}
if (countPlayed > 1 && countWon > 1) {
return EventStatus.WON_EVENT;
}
 else if ((countPlayed > 1 && countWon == 0) || (countPlayed > 2 && countWon == 1)) {
return EventStatus.ELIMINATED_IN_FINALS;
}
 else if (!e.isHappeningNow()) {
return EventStatus.ELIMINATED_IN_FINALS;
}
 else {
return EventStatus.PLAYING_IN_FINALS;
}
}
 else {
return EventStatus.PLAYING_IN_FINALS;
}
}

Fixed version (ground truth):
/** 
 * Determines the past/current status of a team at an event.
 * @param e       the event the team is competing at
 * @param teamMatches team's match list
 * @param teamKey key associated with team
 * @return team's past/current event status
 */
public static EventStatus evaluateStatusOfTeam(Event e,ArrayList<Match> teamMatches,String teamKey) throws BasicModel.FieldNotDefinedException {
  JsonArray alliances=e.getAlliances();
  boolean inAlliance=false;
  if (alliances.size() == 0) {
    inAlliance=MatchHelper.getAllianceForTeam(teamMatches,teamKey) != -1;
  }
 else {
    for (int i=0; i < alliances.size(); i++) {
      JsonArray teams=alliances.get(i).getAsJsonObject().get("String_Node_Str").getAsJsonArray();
      for (int j=0; j < teams.size(); j++) {
        if (teams.get(j).getAsString().equals(teamKey)) {
          inAlliance=true;
        }
      }
    }
  }
  ArrayList<Match> qualMatches=new ArrayList<>();
  ArrayList<Match> quarterMatches=new ArrayList<>();
  ArrayList<Match> semiMatches=new ArrayList<>();
  ArrayList<Match> finalMatches=new ArrayList<>();
  ArrayList<Match> currentGroup=qualMatches;
  TYPE lastType=null;
  boolean teamIsHere=false;
  for (  Match match : teamMatches) {
    match.setSelectedTeam(teamKey);
    JsonObject matchAlliances=match.getAlliances();
    JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
    if (redTeams.toString().contains(teamKey) || blueTeams.toString().contains(teamKey)) {
      teamIsHere=true;
    }
    if (lastType != match.getType()) {
switch (match.getType()) {
case QUAL:
        currentGroup=qualMatches;
      break;
case QUARTER:
    currentGroup=quarterMatches;
  break;
case SEMI:
currentGroup=semiMatches;
break;
case FINAL:
currentGroup=finalMatches;
break;
}
}
currentGroup.add(match);
}
Log.d(Constants.LOG_TAG,"String_Node_Str" + qualMatches.size());
Log.d(Constants.LOG_TAG,"String_Node_Str" + quarterMatches.size());
Log.d(Constants.LOG_TAG,"String_Node_Str" + semiMatches.size());
Log.d(Constants.LOG_TAG,"String_Node_Str" + finalMatches.size());
if (e.isHappeningNow() && quarterMatches.size() == 0) {
return EventStatus.PLAYING_IN_QUALS;
}
boolean allQualMatchesPlayed=true;
for (Match match : qualMatches) {
if (!match.hasBeenPlayed()) {
Log.d(Constants.LOG_TAG,"String_Node_Str" + match.getKey() + "String_Node_Str");
allQualMatchesPlayed=false;
break;
}
}
Log.d(Constants.LOG_TAG,"String_Node_Str" + inAlliance);
Log.d(Constants.LOG_TAG,"String_Node_Str" + allQualMatchesPlayed);
if (qualMatches.isEmpty() || (allQualMatchesPlayed && !teamIsHere)) {
return EventStatus.NOT_AVAILABLE;
}
 else if ((allQualMatchesPlayed && !inAlliance) || (!e.isHappeningNow() && (quarterMatches.isEmpty() && semiMatches.isEmpty() && finalMatches.isEmpty()))) {
return EventStatus.NOT_PICKED;
}
if (!quarterMatches.isEmpty()) {
int countPlayed=0, countWon=0;
for (Match match : quarterMatches) {
if (match.hasBeenPlayed()) {
JsonObject matchAlliances=match.getAlliances();
JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
if (!redTeams.toString().contains(teamKey + "String_Node_Str") && !blueTeams.toString().contains(teamKey + "String_Node_Str")) {
continue;
}
countPlayed++;
if (match.didSelectedTeamWin()) {
countWon++;
}
}
}
if (countPlayed > 1 && countWon > 1) {
}
 else if ((countPlayed > 1 && countWon == 0) || (countPlayed > 2 && countWon == 1)) {
return EventStatus.ELIMINATED_IN_QUARTERS;
}
 else if (!e.isHappeningNow() && semiMatches.isEmpty()) {
return EventStatus.ELIMINATED_IN_QUARTERS;
}
 else {
return EventStatus.PLAYING_IN_QUARTERS;
}
}
 else {
return EventStatus.PLAYING_IN_QUARTERS;
}
if (!semiMatches.isEmpty()) {
int countPlayed=0, countWon=0;
for (Match match : semiMatches) {
if (match.hasBeenPlayed()) {
JsonObject matchAlliances=match.getAlliances();
JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
if (!redTeams.toString().contains(teamKey + "String_Node_Str") && !blueTeams.toString().contains(teamKey + "String_Node_Str")) {
continue;
}
countPlayed++;
if (match.didSelectedTeamWin()) {
countWon++;
}
}
}
if (countPlayed > 1 && countWon > 1) {
}
 else if ((countPlayed > 1 && countWon == 0) || (countPlayed > 2 && countWon == 1)) {
return EventStatus.ELIMINATED_IN_SEMIS;
}
 else if (!e.isHappeningNow() && finalMatches.isEmpty()) {
return EventStatus.ELIMINATED_IN_SEMIS;
}
 else {
return EventStatus.PLAYING_IN_SEMIS;
}
}
 else {
return EventStatus.PLAYING_IN_SEMIS;
}
if (!finalMatches.isEmpty()) {
int countPlayed=0, countWon=0;
for (Match match : finalMatches) {
if (match.hasBeenPlayed()) {
JsonObject matchAlliances=match.getAlliances();
JsonArray redTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray(), blueTeams=matchAlliances.get("String_Node_Str").getAsJsonObject().get("String_Node_Str").getAsJsonArray();
if (!redTeams.toString().contains(teamKey + "String_Node_Str") && !blueTeams.toString().contains(teamKey + "String_Node_Str")) {
continue;
}
countPlayed++;
if (match.didSelectedTeamWin()) {
countWon++;
}
}
}
if (countPlayed > 1 && countWon > 1) {
return EventStatus.WON_EVENT;
}
 else if ((countPlayed > 1 && countWon == 0) || (countPlayed > 2 && countWon == 1)) {
return EventStatus.ELIMINATED_IN_FINALS;
}
 else if (!e.isHappeningNow()) {
return EventStatus.ELIMINATED_IN_FINALS;
}
 else {
return EventStatus.PLAYING_IN_FINALS;
}
}
 else {
return EventStatus.PLAYING_IN_FINALS;
}
}