java.lang.Object
edu.ntnu.idatt1002.k1g4.Match
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 Summary
ConstructorDescriptionMatch()
Instantiates a new Match.Instantiates a new Match.Match
(Team teamOne, Team teamTwo, LocalDateTime startTime, long duration, String field) Instantiates a new Match.Match
(Team teamOne, Team teamTwo, LocalDateTime startTime, long duration, String field, boolean isWalkover) First constructor for match. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Overrides the equals method from Objectboolean
fieldOccupied
(Match match) Checks if field is occupied by a matchint
Gets division id.long
Gets the duration of the matchGets the end time of the match.getField()
Gets the field of the match.int
Gets match id.int[]
getScore()
Get score.int
Get score of a teamint[]
Gets the score of the match.Gets the start time of the match.Get team one.Get team two.long
Get the amount of time left of the match.void
incrementScore
(Team teamToIncreaseScore) Increments score for a team.boolean
checks if match is finishedboolean
Is knockout boolean.boolean
Is the match walkover.void
setDivisionId
(int divisionId) Sets division id.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.void
setEndTime
(LocalDateTime endTime) Sets end time.void
Sets a new field to the matchvoid
Sets the match to finished.void
setFinished
(boolean finished) Sets finished.void
setFinished
(LocalDateTime endTime) Set finished.void
setKnockout
(boolean isKnockout) Sets knockout.void
setMatchId
(int matchId) Sets match id.void
setScore
(int[] score) Sets score.void
setStartTime
(LocalDateTime startTime) Set start time to a new one Updates the duration as wellvoid
setTeamOne
(Team teamOne) Sets team one.void
setTeamTwo
(Team teamTwo) Sets team two.void
setWalkover
(boolean walkover) Sets walkover to true or false.void
Sets the losing team to not competing.boolean
teamsOccupied
(Match match) checks if team is occupied by matchtoString()
Overrides the toString method in Object Different for finished, ongoing and not started matchesvoid
updateScore
(int teamNr, int newScore) Update score.
-
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 startsduration
- LocalDateTime: The expected duration of the match in minutesfield
- 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
Instantiates a new Match.- Parameters:
teamOne
- Team: Competing team 1.teamTwo
- Team: Competing team 2.startTime
- Team: Time of when the match startsduration
- Team: Time of when then match endsfield
- Team: The field that the match is played on.
-
Match
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
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 nrnewScore
- int: the new score
-
getScore
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
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
Get team one.- Returns:
- teamOne Team: one of the two teams that are playing.
-
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
Gets the start time of the match.- Returns:
- startTime LocalDateTime: the start time of the match.
-
setStartTime
Set start time to a new one Updates the duration as well- Parameters:
startTime
- LocalDateTime: the new star time of the match
-
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
Gets the field of the match.- Returns:
- field String: the field number.
-
setField
Sets a new field to the match- Parameters:
field
- String: the field for the match
-
fieldOccupied
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
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
Sets team one.- Parameters:
teamOne
- Team: Team one
-
setTeamTwo
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
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
Overrides the equals method from Object -
toString
Overrides the toString method in Object Different for finished, ongoing and not started matches
-