Class Match

java.lang.Object
edu.ntnu.idatt1002.k1g4.Match

public class Match extends Object
The class Match which holds two teams.
Version:
0.8
Author:
Callum Gran, Brage H. Kvamme, Carl Gützkow, Runar Indahl, Nicolai H. Brand.
  • Constructor Details

    • Match

      public Match(Team teamOne, Team teamTwo, LocalDateTime startTime, long duration, String field, boolean isWalkover) throws IllegalArgumentException, NullPointerException
      First constructor for match.
      Parameters:
      teamOne - Team: Competing team 1.
      teamTwo - Team: Competing team 2.
      startTime - LocalDateTime: Time of when the match starts
      duration - LocalDateTime: The expected duration of the match in minutes
      field - String: The field that the match is played on.
      isWalkover - boolean: Defines if the match is a walkover.
      Throws:
      IllegalArgumentException - thrown if field number is negative, if the teams are the same, if one of the teams is not competing or if endTime is before starTime.
      NullPointerException - thrown if either team is null or matchType is null
    • Match

      public Match(Team teamOne, Team teamTwo, LocalDateTime startTime, long duration, String field)
      Instantiates a new Match.
      Parameters:
      teamOne - Team: Competing team 1.
      teamTwo - Team: Competing team 2.
      startTime - Team: Time of when the match starts
      duration - Team: Time of when then match ends
      field - Team: The field that the match is played on.
    • Match

      public Match(Team teamOne, Team teamTwo)
      Instantiates a new Match.
      Parameters:
      teamOne - Team: Competing team 1.
      teamTwo - Team: Competing team 2.
    • Match

      public Match()
      Instantiates a new Match. This constructor is for data from the database.
  • Method Details

    • incrementScore

      public void incrementScore(Team teamToIncreaseScore)
      Increments score for a team.
      Parameters:
      teamToIncreaseScore - Team: team which score will increase
    • updateScore

      public void updateScore(int teamNr, int newScore)
      Update score.
      Parameters:
      teamNr - int: the team nr
      newScore - int: the new score
    • getScore

      public int getScore(Team team)
      Get score of a team
      Parameters:
      team - Team: the team
      Returns:
      score int: score of a team
    • getScores

      public int[] getScores()
      Gets the score of the match.
      Returns:
      score int[] the scores of both teams.
    • isFinished

      public boolean isFinished()
      checks if match is finished
      Returns:
      isFinished boolean: true if match is finished and false if not
    • setFinished

      public void setFinished()
      Sets the match to finished. finishes match with end time now Uses the other finished method to set end time to now.
    • setFinished

      public void setFinished(LocalDateTime endTime)
      Set finished. finishes match with specified end time
      Parameters:
      endTime - LocalDateTime: the match end time
    • setWinner

      public void setWinner()
      Sets the losing team to not competing. Only called on matches that are of type knockout
    • setWalkover

      public void setWalkover(boolean walkover)
      Sets walkover to true or false.
      Parameters:
      walkover - boolean: true if the match is a walk over match
    • getTeamOne

      public Team getTeamOne()
      Get team one.
      Returns:
      teamOne Team: one of the two teams that are playing.
    • getTeamTwo

      public Team getTeamTwo()
      Get team two.
      Returns:
      teamTwo Team: one of the two teams that are playing.
    • getDuration

      public long getDuration()
      Gets the duration of the match
      Returns:
      duration long: the duration of the match
    • setDuration

      public void setDuration(long duration)
      Sets a new duration for the match Should be possible to edit duration after a match is finished in case someone where to forget to finish a match. Also updates the end time accordingly.
      Parameters:
      duration - long: the duration of the match
    • getStartTime

      public LocalDateTime getStartTime()
      Gets the start time of the match.
      Returns:
      startTime LocalDateTime: the start time of the match.
    • setStartTime

      public void setStartTime(LocalDateTime startTime)
      Set start time to a new one Updates the duration as well
      Parameters:
      startTime - LocalDateTime: the new star time of the match
    • getEndTime

      public LocalDateTime getEndTime()
      Gets the end time of the match.
      Returns:
      endTime LocalDateTime: the end time of the match.
    • getTimeLeft

      public long getTimeLeft()
      Get the amount of time left of the match. Format is a long in minutes
      Returns:
      long : minutes left of the match
    • getField

      public String getField()
      Gets the field of the match.
      Returns:
      field String: the field number.
    • setField

      public void setField(String field)
      Sets a new field to the match
      Parameters:
      field - String: the field for the match
    • fieldOccupied

      public boolean fieldOccupied(Match match)
      Checks if field is occupied by a match
      Parameters:
      match - Match: the match to check
      Returns:
      boolean : true if field and time overlap, false if not
    • teamsOccupied

      public boolean teamsOccupied(Match match)
      checks if team is occupied by match
      Parameters:
      match - Match: the match to check
      Returns:
      boolean : true if teams and time overlap, false if not
    • isWalkover

      public boolean isWalkover()
      Is the match walkover.
      Returns:
      isWalkover boolean: the boolean if the match is a walkover or not.
    • getMatchId

      public int getMatchId()
      Gets match id.
      Returns:
      int : The match id
    • setMatchId

      public void setMatchId(int matchId)
      Sets match id.
      Parameters:
      matchId - int: The match id
    • setTeamOne

      public void setTeamOne(Team teamOne)
      Sets team one.
      Parameters:
      teamOne - Team: Team one
    • setTeamTwo

      public void setTeamTwo(Team teamTwo)
      Sets team two.
      Parameters:
      teamTwo - Team: Team two
    • getScore

      public int[] getScore()
      Get score.
      Returns:
      score int[]: The score of both teams.
    • setScore

      public void setScore(int[] score)
      Sets score.
      Parameters:
      score - int[]: the score of both teams
    • setEndTime

      public void setEndTime(LocalDateTime endTime)
      Sets end time.
      Parameters:
      endTime - LocalDateTime: The end time
    • setFinished

      public void setFinished(boolean finished)
      Sets finished.
      Parameters:
      finished - boolean: true or false if match is finished
    • isKnockout

      public boolean isKnockout()
      Is knockout boolean.
      Returns:
      isKnockout boolean: true or false if is a knockout match
    • getDivisionId

      public int getDivisionId()
      Gets division id.
      Returns:
      divisionId int: the division id
    • setDivisionId

      public void setDivisionId(int divisionId)
      Sets division id.
      Parameters:
      divisionId - the division id
    • setKnockout

      public void setKnockout(boolean isKnockout)
      Sets knockout.
      Parameters:
      isKnockout - the is knockout
    • equals

      public boolean equals(Object o)
      Overrides the equals method from Object
      Overrides:
      equals in class Object
      Parameters:
      o - Object: object to be compared
      Returns:
      boolean: true if they are the same, false if not
    • toString

      public String toString()
      Overrides the toString method in Object Different for finished, ongoing and not started matches
      Overrides:
      toString in class Object
      Returns:
      String: string representation of a match