Class Match
java.lang.Object
edu.ntnu.idatt1002.k01g08.fta.objects.tournaments.Match
Represents a football match.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new foul to the match history.void
Adds a new foul to the match history.void
addGameEvent
(GameEvent gameEvent) Adds a game event to the match history, if the match has started.void
Adds a new goal to the match history.void
Adds a new goal to the match history.void
addSelfGoal
(boolean scoringPlayerIsHomeTeam, int scoringPlayerNumber, String timeStamp) Adds a new goal to the match history.void
addSubstitution
(boolean homeTeam, int playerInNumber, int playerOutNumber, String timeStamp) Adds a new substitution to the match history.void
addSubstitution
(Team team, Player playerIn, Player playerOut, String timeStamp) Adds a new substitution to the match history.int
Returns the number of the match half currently being played.Deprecated.use currentMinute() insteadReturns the current minute of the match as a string.The current timestamp of the match as a string.end()
Ends the match and returns the winning team.Returns a stream of the game events in this match's match history.Returns the away team for this matchint
Returns the score (number of goals) of the away team in this matchgetGameEvent
(int index) Returns the game event at the specified position in the match history.Returns the home team for this matchint
Returns the score (number of goals) of the home team in this matchReturns the very last game event from the match history.getLastGameEvent
(int index) Returns the game event at the specified position in the match history, counted from the last event.int
Returns the length of one half match.int
getTeam
(boolean homeTeam) Returns the team correspending to the entered boolean.Returns the winner of this match, if the match is finished.boolean
Returns true if the match is finished.boolean
Returns true if the match is playing.boolean
Returns true if the match has started.iterator()
Returns an iterator over the game events in the match history.boolean
onPause()
Returns true if the match is on pause.boolean
pause()
Pauses the match.removeGameEvent
(int index) Removes the game event at the specified position in the match history.Removes the game event at the specified position in the match history, counted from the last.removeLastGameEvent
(int index) Removes the game event at the specified position in the match history, counted from the last.void
setAwayTeam
(Team awayTeam) Sets the specified team as the away team.void
setHomeTeam
(Team homeTeam) Sets the specified team as the home team.void
setLengthOfHalf
(int minutes) Sets the length of one half match.boolean
start()
Starts the match, and the match clock, if both teams have been registered.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Match
public Match()Creates a new match -
Match
Creates a new match with the specified home and away team.- Parameters:
homeTeam
- home team for this matchawayTeam
- away team for this match- Throws:
IllegalArgumentException
- if the teams are equalNullPointerException
- if one of the specified teams is null
-
-
Method Details
-
getHomeTeam
Returns the home team for this match- Returns:
- home team for this match
-
getAwayTeam
Returns the away team for this match- Returns:
- away team for this match
-
getTeam
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 teamNullPointerException
- if the specified team is nullIllegalStateException
- 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 teamNullPointerException
- if the specified team is nullIllegalStateException
- if the match has started
-
getGameEvent
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
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
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
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
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
Deprecated.use currentMinute() insteadReturns 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
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
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
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
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
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
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 teamscoringPlayer
- the scoring playerassistingPlayer
- the assisting playertimeStamp
- the time stamp of the goal- Throws:
IllegalStateException
- if the match has not started yetNullPointerException
- 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 teamscoringPlayerNumber
- the squad number of the scoring player on the scoring teamassistingPlayerNumber
- the squad number of the assisting player on the scoring teamtimeStamp
- the time stamp of the goal, or null or blank to use current match time- Throws:
IllegalStateException
- if the match has not started yetNullPointerException
- 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 teamscoringPlayerNumber
- the squad number of the scoring playertimeStamp
- the time stamp of the goal, or null or blank to use current match time- Throws:
IllegalStateException
- if the match has not started yetNullPointerException
- 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 teamplayerIn
- the player that is subbed inplayerOut
- the player that is subbed outtimeStamp
- the time stamp of the substitution- Throws:
IllegalStateException
- if the match has not started yetNullPointerException
- 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 teamplayerInNumber
- the squad number of the player that is subbed inplayerOutNumber
- the squad number of the player that is subbed outtimeStamp
- the time stamp of the substitution- Throws:
IllegalStateException
- if the match has not started yetNullPointerException
- 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 playerplayer
- the offending playerfoulTag
- the tag of the foultimeStamp
- the time stamp of the substitution- Throws:
IllegalStateException
- if the match has not started yetNullPointerException
- 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 teamplayerNumber
- the squad number of the offending playerfoulTag
- the tag of the foultimeStamp
- the time stamp of the substitution- Throws:
IllegalStateException
- if the match has not started yetNullPointerException
- if a player with the squad number does not exist on the team
-
iterator
Returns an iterator over the game events in the match history. -
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
-