gt:         if (isCoachOrAbove(contest, userJid)) {
context: package org.iatoki.judgels.uriel.contest;
  
  import com.google.common.collect.ImmutableList;
  import com.google.common.collect.Lists;
  import org.iatoki.judgels.play.IdentityUtils;
  import org.iatoki.judgels.play.InternalLink;
  import org.iatoki.judgels.play.LazyHtml;
  import org.iatoki.judgels.play.views.html.layouts.alertLayout;
  import org.iatoki.judgels.play.views.html.layouts.headingLayout;
  import org.iatoki.judgels.play.views.html.layouts.headingWithActionLayout;
  import org.iatoki.judgels.play.views.html.layouts.tabLayout;
  import org.iatoki.judgels.uriel.UrielProperties;
  import org.iatoki.judgels.uriel.contest.contestant.ContestContestant;
  import org.iatoki.judgels.uriel.contest.supervisor.ContestPermissions;
  import org.iatoki.judgels.uriel.contest.team.ContestTeam;
  import org.iatoki.judgels.uriel.UrielControllerUtils;
  import org.iatoki.judgels.uriel.UrielUtils;
  import org.iatoki.judgels.uriel.contest.module.ContestModule;
  import org.iatoki.judgels.uriel.contest.module.ContestModuleComparator;
  import org.iatoki.judgels.uriel.contest.module.ContestModules;
  import org.iatoki.judgels.uriel.contest.module.TabbedContestModule;
  import org.iatoki.judgels.uriel.contest.module.registration.ContestRegistrationModule;
  import org.iatoki.judgels.uriel.contest.module.trigger.ContestTrigger;
  import org.iatoki.judgels.uriel.contest.module.trigger.ContestTriggerModule;
  import org.iatoki.judgels.uriel.contest.module.virtual.ContestVirtualModule;
  import org.iatoki.judgels.uriel.contest.contestant.password.ContestContestantPasswordService;
  import org.iatoki.judgels.uriel.contest.contestant.ContestContestantService;
  import org.iatoki.judgels.uriel.contest.manager.ContestManagerService;
  import org.iatoki.judgels.uriel.contest.supervisor.ContestSupervisorService;
  import org.iatoki.judgels.uriel.contest.team.ContestTeamService;
  import org.iatoki.judgels.uriel.contest.html.contestTimeLayout;
  import org.iatoki.judgels.uriel.contest.html.javaSpecificationLayout;
  
  import play.i18n.Messages;
  import play.mvc.Controller;
  import play.mvc.Result;
  import play.mvc.Results;
  
  import java.util.Collections;
  import java.util.Date;
  import java.util.List;
  import java.util.concurrent.TimeUnit;
  
  public final class ContestControllerUtils {
  
      private static ContestControllerUtils instance;
  
      private final ContestContestantService contestContestantService;
      private final ContestSupervisorService contestSupervisorService;
      private final ContestManagerService contestManagerService;
      private final ContestTeamService contestTeamService;
      private final ContestContestantPasswordService contestContestantPasswordService;
  
      public ContestControllerUtils(ContestContestantService contestContestantService, ContestSupervisorService contestSupervisorService, ContestManagerService contestManagerService, ContestTeamService contestTeamService, ContestContestantPasswordService contestContestantPasswordService) {
          this.contestContestantService = contestContestantService;
          this.contestSupervisorService = contestSupervisorService;
          this.contestManagerService = contestManagerService;
          this.contestTeamService = contestTeamService;
          this.contestContestantPasswordService = contestContestantPasswordService;
      }
  
      public static synchronized void buildInstance(ContestContestantService contestContestantService, ContestSupervisorService contestSupervisorService, ContestManagerService contestManagerService, ContestTeamService contestTeamService, ContestContestantPasswordService contestPasswordService) {
          if (instance != null) {
              throw new UnsupportedOperationException("ContestControllerUtils instance has already been built");
          }
          instance = new ContestControllerUtils(contestContestantService, contestSupervisorService, contestManagerService, contestTeamService, contestPasswordService);
      }
  
      public static ContestControllerUtils getInstance() {
          if (instance == null) {
              throw new UnsupportedOperationException("ContestControllerUtils instance has not been built");
          }
          return instance;
      }
  
      public void setCurrentStatementLanguage(String languageCode) {
          Controller.session("currentStatementLanguage", languageCode);
      }
  
      public String getCurrentStatementLanguage() {
          String lang = Controller.session("currentStatementLanguage");
          if (lang == null) {
              return "en-US";
          }
  
          return lang;
      }
  
      public boolean isAdmin() {
          return UrielControllerUtils.getInstance().isAdmin();
      }
  
      public boolean isManager(Contest contest, String userJid) {
          return contestManagerService.isManagerInContest(contest.getJid(), userJid);
      }
  
      public boolean isSupervisor(Contest contest, String userJid) {
          return contest.containsModule(ContestModules.SUPERVISOR) && contestSupervisorService.isContestSupervisorInContest(contest.getJid(), userJid);
      }
  
      public boolean isCoach(Contest contest, String userJid) {
          return contest.containsModule(ContestModules.TEAM) && contestTeamService.isUserACoachOfAnyTeamInContest(contest.getJid(), userJid);
      }
  
      public boolean isContestant(Contest contest, String userJid) {
          return contestContestantService.isContestantInContest(contest.getJid(), userJid);
      }
  
      public boolean isManagerOrAbove(Contest contest, String userJid) {
          return isAdmin() || isManager(contest, userJid);
      }
  
      public boolean isSupervisorOrAbove(Contest contest, String userJid) {
          return isManagerOrAbove(contest, userJid) || isSupervisor(contest, userJid);
      }
  
      public boolean isCoachOrAbove(Contest contest, String userJid) {
          return isSupervisorOrAbove(contest, userJid) || isCoach(contest, userJid);
      }
  
      public boolean isPermittedToSupervise(Contest contest, ContestPermissions contestPermissions, String userJid) {
          return isManagerOrAbove(contest, userJid) || (isSupervisor(contest, userJid) && contestSupervisorService.findContestSupervisorInContestByUserJid(contest.getJid(), userJid).getContestPermission().isAllowed(contestPermissions));
      }
  
      public boolean hasContestBegun(Contest contest) {
          return new Date().after(contest.getBeginTime());
      }
  
      public boolean hasContestEnded(Contest contest) {
          return !new Date().before(contest.getEndTime());
      }
  
      public boolean hasRegisteredToContest(Contest contest, String userJid) {
          if (!contest.containsModule(ContestModules.REGISTRATION)) {
              return false;
          }
  
          return contestContestantService.hasRegisteredToContest(contest.getJid(), userJid);
      }
  
      public boolean hasContestStarted(Contest contest, String userJid) {
          if (contest.containsModule(ContestModules.VIRTUAL)) {
              if (!contestContestantService.isContestantInContest(contest.getJid(), userJid)) {
                  return false;
              }
  
              ContestContestant contestContestant = contestContestantService.findContestantInContestAndJid(contest.getJid(), userJid);
              return contestContestant.getContestStartTime() != 0;
          }
  
          return hasContestBegun(contest);
      }
  
      public boolean hasContestFinished(Contest contest, String userJid) {
          if (hasContestEnded(contest)) {
              return true;
          }
  
          if (contest.containsModule(ContestModules.VIRTUAL) && isContestant(contest, userJid)) {
              ContestContestant contestContestant = contestContestantService.findContestantInContestAndJid(contest.getJid(), userJid);
              ContestVirtualModule contestVirtualModule = (ContestVirtualModule) contest.getModule(ContestModules.VIRTUAL);
  
              return contestContestant.getContestStartTime() != 0 && (System.currentTimeMillis() > (contestContestant.getContestStartTime() + contestVirtualModule.getVirtualDuration()));
          }
  
          return hasContestEnded(contest);
      }
  
      public boolean isAllowedToViewContest(Contest contest, String userJid) {
          return !contest.containsModule(ContestModules.LIMITED) || isCoachOrAbove(contest, userJid) || isContestant(contest, userJid);
      }
  
      public boolean isAllowedToManageContest(Contest contest, String userJid) {
          return isManagerOrAbove(contest, userJid);
      }
  
      public boolean isAllowedToRegisterContest(Contest contest, String userJid) {
          if (!contest.containsModule(ContestModules.REGISTRATION)) {
              return false;
          }
  
          if (isSupervisorOrAbove(contest, userJid)) {
              return false;
          }
  
          ContestRegistrationModule contestRegistrationModule = (ContestRegistrationModule) contest.getModule(ContestModules.REGISTRATION);
          return (contestRegistrationModule.getRegisterStartTime() < System.currentTimeMillis()) && (contestRegistrationModule.getRegisterStartTime() + contestRegistrationModule.getRegisterDuration() > System.currentTimeMillis()) && ((contestRegistrationModule.getMaxRegistrants() == 0) || (contestContestantService.countContestantsInContest(contest.getJid()) < contestRegistrationModule.getMaxRegistrants())) && !hasContestEnded(contest) && !hasRegisteredToContest(contest, userJid);
      }
  
      public boolean isAllowedToUnregisterContest(Contest contest, String userJid) {
          if (!contest.containsModule(ContestModules.REGISTRATION)) {
              return false;
          }
  
          return !hasContestStarted(contest, userJid) && isContestant(contest, userJid);
      }
  
      public boolean isAllowedToViewEnterContestButton(Contest contest, String userJid) {
          if (isCoachOrAbove(contest, userJid)) {
              return true;
          }
          if (contest.containsModule(ContestModules.REGISTRATION) || contest.containsModule(ContestModules.LIMITED)) {
              if (!hasContestStarted(contest, userJid) || !isContestant(contest, userJid)) {
                  return false;
              }
          }
          if (requiresPasswordToEnterContest(contest, userJid)) {
              return false;
          }
  
          return hasContestStarted(contest, userJid);
      }
  
      public boolean isAllowedToEnterContest(Contest contest, String userJid) {
          if (UrielProperties.getInstance().isLegacyContestDisallowed(contest.getJid()) && !isSupervisorOrAbove(contest, userJid)) {
              return false;
          }
          if (!isAllowedToViewEnterContestButton(contest, userJid)) {
              return false;
          }
  