java.lang.Object
edu.ntnu.idatt1002.k01g08.fta.objects.tournaments.Match
All Implemented Interfaces:
Iterable<GameEvent>

public class Match extends Object implements Iterable<GameEvent>
Represents a football match.
  • Constructor Details

  • Method Details

    • getHomeTeam

      public Team getHomeTeam()
      Returns the home team for this match
      Returns:
      home team for this match
    • getAwayTeam

      public Team getAwayTeam()
      Returns the away team for this match
      Returns:
      away team for this match
    • getTeam

      public Team getTeam(boolean homeTeam)
      Returns the team correspending to the entered boolean. True returns the home team, and false the away team.
      Parameters:
      homeTeam - whether to return the home team
      Returns:
      the home team if true, the away team if false
    • setHomeTeam

      public void setHomeTeam(Team homeTeam) throws IllegalArgumentException, NullPointerException, IllegalStateException
      Sets the specified team as the home team.
      Parameters:
      homeTeam - the team to set as the home team
      Throws:
      IllegalArgumentException - if the specified team equals the away team
      NullPointerException - if the specified team is null
      IllegalStateException - if the match has started
    • setAwayTeam

      public void setAwayTeam(Team awayTeam) throws IllegalArgumentException, IllegalStateException, NullPointerException
      Sets the specified team as the away team.
      Parameters:
      awayTeam - the team to set as the away team
      Throws:
      IllegalArgumentException - if the specified team equals the home team
      NullPointerException - if the specified team is null
      IllegalStateException - if the match has started
    • getGameEvent

      public GameEvent getGameEvent(int index)
      Returns the game event at the specified position in the match history.
      Parameters:
      index - position of the event in the match history
      Returns:
      game event at the specified position in the match history
    • getLastGameEvent

      public GameEvent getLastGameEvent(int index)
      Returns the game event at the specified position in the match history, counted from the last event.
      Parameters:
      index - position of the event in the match history
      Returns:
      game event at the specified position in the match history, counted from the last event
    • getLastGameEvent

      public GameEvent getLastGameEvent()
      Returns the very last game event from the match history.
      Returns:
      the very last game event in the match history
    • getMatchHistorySize

      public int getMatchHistorySize()
      Returns:
      the amount of match histories
    • getLengthOfHalf

      public int getLengthOfHalf()
      Returns the length of one half match.
      Returns:
      the length of one half match
    • setLengthOfHalf

      public void setLengthOfHalf(int minutes)
      Sets the length of one half match. This does not impact halves that have already been played, but can be used to set the length of one in progress.
      Parameters:
      minutes - number of minutes to set half length to
    • getHomeTeamScore

      public int getHomeTeamScore()
      Returns the score (number of goals) of the home team in this match
      Returns:
      score of the home team in this match
    • getAwayTeamScore

      public int getAwayTeamScore()
      Returns the score (number of goals) of the away team in this match
      Returns:
      score of the away team in this match
    • getWinner

      public Team getWinner()
      Returns the winner of this match, if the match is finished. The home team wins if it has more goals than the away team. The away team wins if it has at least as many goals as the home team. Returns null if the match has not ended.
      Returns:
      winner of the match if the match is finished, or null if not
    • start

      public boolean start()
      Starts the match, and the match clock, if both teams have been registered. If this is the third half, sets length of half to 15. Returns true if this match's state changed because of the call.
      Returns:
      true if this match's state changed because of the call
    • pause

      public boolean pause()
      Pauses the match. Returns true if this match's state changed because of the call.
      Returns:
      true if this match's state changed.
    • end

      public Team end() throws IllegalStateException
      Ends the match and returns the winning team.
      Returns:
      winning team of this match
      Throws:
      IllegalStateException - if the match has not started
    • isFinished

      public boolean isFinished()
      Returns true if the match is finished.
      Returns:
      true if the match is finished
    • isStarted

      public boolean isStarted()
      Returns true if the match has started.
      Returns:
      true if the match has started
    • onPause

      public boolean onPause()
      Returns true if the match is on pause.
      Returns:
      true if the match is on pause
    • isPlaying

      public boolean isPlaying()
      Returns true if the match is playing.
      Returns:
      true if the match is playing
    • currentHalf

      public int currentHalf()
      Returns the number of the match half currently being played. If on pause, returns the previous one.
      Returns:
      the half currently being played
    • currentMatchTime

      public String currentMatchTime()
      Deprecated.
      use currentMinute() instead
      Returns the current match time as a string. If the time is over the maximum length of a half, the time will be returned on the form ("[max length]+[difference]".
      Returns:
      the current match time as a string.
    • currentMinute

      public String currentMinute()
      Returns the current minute of the match as a string. The first minute of the match is "01", the second "02", and so on. Extra minutes get returned on the form "45+1".
      Returns:
      the current minute of the match as a string
    • currentTime

      public String currentTime()
      The current timestamp of the match as a string. The time is always returned on the form "MM:SS". Each half starts counting without regard for extra minutes in the previous half (so the second half in a default match always starts at "45:00").
      Returns:
      the current timestamp of the match as a string
    • addGameEvent

      public void addGameEvent(GameEvent gameEvent) throws IllegalStateException
      Adds a game event to the match history, if the match has started.
      Parameters:
      gameEvent - game event to add to the match history.
      Throws:
      IllegalStateException - if match has not started yet
    • removeGameEvent

      public GameEvent removeGameEvent(int index) throws IndexOutOfBoundsException
      Removes the game event at the specified position in the match history. Returns the event that was removed.
      Parameters:
      index - position of the event to be removed
      Returns:
      the event that was removed
      Throws:
      IndexOutOfBoundsException - if no event exists at the specified position
    • removeLastGameEvent

      public GameEvent removeLastGameEvent(int index) throws IndexOutOfBoundsException
      Removes the game event at the specified position in the match history, counted from the last. Returns the event that was removed.
      Parameters:
      index - position of the event to be removed, counted from the last
      Returns:
      the event that was removed
      Throws:
      IndexOutOfBoundsException - if no event exists at the specified position
    • removeLastGameEvent

      public GameEvent removeLastGameEvent()
      Removes the game event at the specified position in the match history, counted from the last. Returns the event that was removed.
      Returns:
      the event that was removed
    • addGoal

      public void addGoal(Team team, Player scoringPlayer, Player assistingPlayer, String timeStamp) throws IllegalStateException, NullPointerException
      Adds a new goal to the match history. If time stamp is null or blank, uses current match time.
      Parameters:
      team - the scoring team
      scoringPlayer - the scoring player
      assistingPlayer - the assisting player
      timeStamp - the time stamp of the goal
      Throws:
      IllegalStateException - if the match has not started yet
      NullPointerException - if the team or scoring player is null
    • addGoal

      public void addGoal(boolean homeTeam, int scoringPlayerNumber, int assistingPlayerNumber, String timeStamp) throws IllegalStateException, NullPointerException
      Adds a new goal to the match history. If time stamp is null or blank, uses current match time.
      Parameters:
      homeTeam - whether to add the goal to the home team
      scoringPlayerNumber - the squad number of the scoring player on the scoring team
      assistingPlayerNumber - the squad number of the assisting player on the scoring team
      timeStamp - the time stamp of the goal, or null or blank to use current match time
      Throws:
      IllegalStateException - if the match has not started yet
      NullPointerException - if the scoring player does not exist on the team
    • addSelfGoal

      public void addSelfGoal(boolean scoringPlayerIsHomeTeam, int scoringPlayerNumber, String timeStamp) throws IllegalStateException, NullPointerException
      Adds a new goal to the match history. If time stamp is null or blank, uses current match time.
      Parameters:
      scoringPlayerIsHomeTeam - whether to add the goal to the away team
      scoringPlayerNumber - the squad number of the scoring player
      timeStamp - the time stamp of the goal, or null or blank to use current match time
      Throws:
      IllegalStateException - if the match has not started yet
      NullPointerException - if the scoring player does not exist on the team
    • addSubstitution

      public void addSubstitution(Team team, Player playerIn, Player playerOut, String timeStamp) throws IllegalStateException, NullPointerException
      Adds a new substitution to the match history. If time stamp is null or blank, uses current match time.
      Parameters:
      team - the scoring team
      playerIn - the player that is subbed in
      playerOut - the player that is subbed out
      timeStamp - the time stamp of the substitution
      Throws:
      IllegalStateException - if the match has not started yet
      NullPointerException - if the team or one of the players is null
    • addSubstitution

      public void addSubstitution(boolean homeTeam, int playerInNumber, int playerOutNumber, String timeStamp) throws IllegalStateException, NullPointerException
      Adds a new substitution to the match history. If time stamp is null or blank, uses current match time.
      Parameters:
      homeTeam - whether to add the goal to the home team
      playerInNumber - the squad number of the player that is subbed in
      playerOutNumber - the squad number of the player that is subbed out
      timeStamp - the time stamp of the substitution
      Throws:
      IllegalStateException - if the match has not started yet
      NullPointerException - if one of the players is not on the team
    • addFoul

      public void addFoul(Team team, Player player, String foulTag, int giveCard, String timeStamp) throws IllegalStateException, NullPointerException
      Adds a new foul to the match history. If time stamp is null or blank, uses current match time.
      Parameters:
      team - the team of the offending player
      player - the offending player
      foulTag - the tag of the foul
      timeStamp - the time stamp of the substitution
      Throws:
      IllegalStateException - if the match has not started yet
      NullPointerException - if the team or the player is null
    • addFoul

      public void addFoul(boolean homeTeam, int playerNumber, String foulTag, int giveCard, String timeStamp) throws IllegalStateException, NullPointerException
      Adds a new foul to the match history. If time stamp is null or blank, uses current match time.
      Parameters:
      homeTeam - whether the offending player is on the home team
      playerNumber - the squad number of the offending player
      foulTag - the tag of the foul
      timeStamp - the time stamp of the substitution
      Throws:
      IllegalStateException - if the match has not started yet
      NullPointerException - if a player with the squad number does not exist on the team
    • iterator

      public Iterator<GameEvent> iterator()
      Returns an iterator over the game events in the match history.
      Specified by:
      iterator in interface Iterable<GameEvent>
      Returns:
      an iterator over the game events in the match history
    • eventStream

      public Stream<GameEvent> eventStream()
      Returns a stream of the game events in this match's match history.
      Returns:
      a stream of the game events in this match's match history.
    • toString

      public String toString()
      Overrides:
      toString in class Object