Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt1002_2022_K1-G4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carl Gützkow
idatt1002_2022_K1-G4
Commits
9b8a2913
Commit
9b8a2913
authored
3 years ago
by
Eilert Werner Hansen
Browse files
Options
Downloads
Patches
Plain Diff
refactor(main...match):fixed field occupied method implemented teams occupied
parent
d87d4f74
Branches
refactor/change-match-equals
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/edu/ntnu/idatt1002/k1g4/Division.java
+3
-2
3 additions, 2 deletions
src/main/java/edu/ntnu/idatt1002/k1g4/Division.java
src/main/java/edu/ntnu/idatt1002/k1g4/Match.java
+32
-3
32 additions, 3 deletions
src/main/java/edu/ntnu/idatt1002/k1g4/Match.java
with
35 additions
and
5 deletions
src/main/java/edu/ntnu/idatt1002/k1g4/Division.java
+
3
−
2
View file @
9b8a2913
...
...
@@ -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
()));
...
...
This diff is collapsed.
Click to expand it.
src/main/java/edu/ntnu/idatt1002/k1g4/Match.java
+
32
−
3
View file @
9b8a2913
...
...
@@ -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.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment