Skip to content
Snippets Groups Projects
Commit de1103be authored by Brage Halvorsen Kvamme's avatar Brage Halvorsen Kvamme :hammer:
Browse files

feat(update): Added second constructor in Match and Team.

parent d92478ec
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,8 @@ import java.util.Objects;
/**
* The class Match creates an instance of a match.
*
* @author Callum Gran
* @version 0.1
* @author Callum Gran, Brage H. Kvamme
* @version 0.2
*/
public class Match {
......@@ -55,6 +55,34 @@ public class Match {
this.isWalkover = isWalkover;
}
/**
* Instantiates a new Match.
*
* @param team1 Competing team 1.
* @param team2 Competing team 2.
* @param fieldNumber The field that the match is played on.
* @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.
* @throws NullPointerException thrown if either team is null or matchType is null
*/
public Match(Team team1, Team team2, LocalDateTime startTime, LocalDateTime endTime,
int fieldNumber) throws IllegalArgumentException, NullPointerException {
if (fieldNumber < 0) throw new IllegalArgumentException("There should be no negative field numbers");
if (team1 == null || team2 == null) throw new NullPointerException("Team is not defined");
if (team1.equals(team2)) throw new IllegalArgumentException("Teams cannot be the same");
if (!team1.isCompeting() || !team2.isCompeting()) throw new IllegalArgumentException("teams must be competing");
if (endTime.isBefore(startTime)) throw new IllegalArgumentException("End time cannot be before start time");
this.teams = new Team[] { team1, team2 };
this.referees = new HashMap<>();
this.score = new int[] { 0, 0 };
this.startTime = startTime;
this.endTime = endTime;
this.fieldNumber = fieldNumber;
this.isFinished = false;
this.isWalkover = false;
}
/**
* adds score to a team
* @param teamToAddScore team which score will increase
......
......@@ -8,8 +8,8 @@ import java.util.Objects;
/**
* The type Team.
*
* @author Callum Gran, Runar Indahl, Nicolai H. Brand.
* @version 0.2
* @author Callum Gran, Runar Indahl, Nicolai H. Brand, Brage H. Kvame
* @version 0.3
*/
public class Team {
......@@ -36,9 +36,9 @@ public class Team {
/**
* Instantiates a new Team.
*
* @param name the name
* @param isCompeting the is competing
* @throws IllegalArgumentException the illegal argument exception
* @param name the name of the team
* @param isCompeting is this team competing or not?
* @throws IllegalArgumentException the illegal argument exception is thrown when the name is blank.
*/
public Team(String name, boolean isCompeting) throws IllegalArgumentException {
if (name.isBlank()) throw new IllegalArgumentException("Team needs a name");
......@@ -47,6 +47,19 @@ public class Team {
this.isCompeting = isCompeting;
}
/**
* Instantiates a new Team. This team is competing has the isCompeting status set to true by default.
*
* @param name The name of the team
* @throws IllegalArgumentException the illegal argument exception is thrown when the name is blank.
*/
public Team(String name) throws IllegalArgumentException {
if (name.isBlank()) throw new IllegalArgumentException("Team needs a name");
this.name = name;
this.members = new HashMap<>();
this.isCompeting = true;
}
/**
* Gets the team name.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment