Skip to content
Snippets Groups Projects
Commit 9b8a2913 authored by Eilert Werner Hansen's avatar Eilert Werner Hansen :spaghetti:
Browse files

refactor(main...match):fixed field occupied method implemented teams occupied

parent d87d4f74
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ import java.util.stream.Collectors;
/**
* This class keeps track of a division in the tournament.
* @author Brage H. Kvamme, Nicolai H. Brand, Runar Indahl, Carl Gützkow
* @version 0.4
* @version 0.5
*/
public class Division {
private final HashMap<String, Team> competingTeams;
......@@ -80,7 +80,8 @@ public class Division {
* @return True if match not exist and then adds the match. False if already exists..
*/
public boolean addMatch(Match match) throws IllegalArgumentException{
if(matches.stream().filter(m -> m.fieldOccupied(match)).count() > 1) throw new IllegalArgumentException("Field is occupied");
if(matches.stream().filter(m -> m.fieldOccupied(match)).count() > 0) throw new IllegalArgumentException("Field is occupied");
if(matches.stream().filter(m -> m.teamsOccupied(match)).count() > 0) throw new IllegalArgumentException("Teams occupied");
if (!matches.contains(match)) {
return matches.add(new Match(match.getTeams()[0], match.getTeams()[1], match.getReferees(), match.getStartTime(),
ChronoUnit.MINUTES.between(match.getStartTime(), match.getEndTime()), match.getField(), match.isWalkover()));
......
......@@ -13,8 +13,8 @@ import java.time.format.DateTimeFormatter;
/**
* The class Match creates an instance of a match.
*
* @author Callum Gran, Brage H. Kvamme, Carl Gützkow
* @version 0.3
* @author Callum Gran, Brage H. Kvamme, Carl Gützkow, Eilert Werner Hansen
* @version 0.4
*/
public class Match {
......@@ -179,8 +179,14 @@ public class Match {
return field;
}
/**
* checks if field is occupied by a match
* @param match
* @return true if field and time overlap, false if not
*/
public boolean fieldOccupied(Match match){
if (match.getField().equals(this.getField())){
if (this.getField().equals(match.getField())){
if (match.getStartTime().isAfter(this.getStartTime()) && match.getStartTime().isBefore(this.getEndTime())){
return true;
}
......@@ -191,6 +197,29 @@ public class Match {
return false;
}
/**
* checks if team is occupied by match
* @param match
* @return true if teams and time overlap, false if not
*/
public boolean teamsOccupied(Match match){
boolean teamOneEqualsTeamOne = this.getTeams()[0].equals(match.getTeams()[0]);
boolean teamOneEqualsTeamTwo = this.getTeams()[0].equals(match.getTeams()[1]);
boolean teamTwoEqualsTeamOne = this.getTeams()[1].equals(match.getTeams()[0]);
boolean teamTwoEqualsTeamTwo = this.getTeams()[1].equals(match.getTeams()[1]);
if (teamOneEqualsTeamOne || teamOneEqualsTeamTwo || teamTwoEqualsTeamOne || teamTwoEqualsTeamTwo ){
if (match.getStartTime().isAfter(this.getStartTime()) && match.getStartTime().isBefore(this.getEndTime())){
return true;
}
if (match.getEndTime().isAfter(this.getStartTime()) && match.getEndTime().isBefore(this.getEndTime())){
return true;
}
}
return false;
}
/**
* Is the match is a walkover boolean.
*
......
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