java.lang.Object
edu.ntnu.idatt1002.k1g4.Division
This class keeps track of a division in the tournament.
- Version:
- 0.7
- Author:
- Brage H. Kvamme, Nicolai H. Brand, Runar Indahl, Carl Gützkow, Callum Gran
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add a match to the list of matches.boolean
Add a team to the list of competing teams.boolean
override equals methodboolean
genRandomMatches
(LocalDateTime startTime, int duration, String[] fields, int divisionId) Create random matches.Creates and return a deep copy of competing teams list.int
getCupId()
Gets cup id.Returns the division category.int
Gets division id.getEqualMatch
(Match match) Helper method to get the match that is equal to the object that is provided This is to solve the problems with compositionReturn the list of matches.int
Gets the projected amount of matches generated.int
hashCode()
gets hashcodeboolean
removeMatch
(Match match) Remove a match from the list of matches.boolean
removeTeam
(Team team) Remove a team.void
setCompetingTeams
(HashMap<Integer, Team> competingTeams) Sets competing teams in a division.void
setCupId
(int cupId) Sets cup id of the division.void
setDivisionCategory
(String divisionCategory) Sets division category.void
setDivisionId
(int divisionId) Sets division id.void
setMatches
(ArrayList<Match> matches) Sets matches in a division.toString()
toString method
-
Constructor Details
-
Division
public Division(HashMap<Integer, Team> competingTeams, ArrayList<Match> matches, String divisionCategory, int cupId) throws IllegalArgumentExceptionInstantiates a new Division.- Parameters:
competingTeams
- HashMap: the competing teams in this division.matches
- ArrayList: the matches that have been played in this division.divisionCategory
- String: the division which is competed in.cupId
- int: the cup id of the division.- Throws:
IllegalArgumentException
- if category is empty
-
Division
Instantiates a new division. Simplified Constructor which allows a division to be established without a list of teams and matches.- Parameters:
divisionCategory
- String: the division which is competed in.cupId
- int: the cup id of the division.
-
Division
public Division()Instantiates a new Division. This constructor is for data from the database.
-
-
Method Details
-
addTeam
Add a team to the list of competing teams.- Parameters:
team
- Team: a competing team.- Returns:
- boolean true if team was added, false if not.
-
removeTeam
Remove a team.- Parameters:
team
- Team: a competing team.- Returns:
- boolean : true if team was removed, false if not.
-
addMatch
Add a match to the list of matches.- Parameters:
match
- Match: the match to be added to the division- Returns:
- Boolean : True if match not exist and then adds the match. False if already exists.
- Throws:
IllegalArgumentException
- the illegal argument exception
-
removeMatch
Remove a match from the list of matches.- Parameters:
match
- Match: the match to be removed.- Returns:
- boolean : true when match is removed.
-
getCompetingTeams
Creates and return a deep copy of competing teams list.- Returns:
- HashMap : a list of competing teams.
-
getMatches
Return the list of matches.- Returns:
- matches ArrayList: the list of matches in this division.
-
getDivisionCategory
Returns the division category.- Returns:
- divisionCategory String: the division which is competed in.
-
getProjectedGeneratedMatches
public int getProjectedGeneratedMatches()Gets the projected amount of matches generated. Integer division by two on total teams- Returns:
- int : amount of matches to be generatd
-
getEqualMatch
Helper method to get the match that is equal to the object that is provided This is to solve the problems with composition- Parameters:
match
- Match: Match - a division to find the equal of- Returns:
- match Match: a match that is in the list. Might be null
-
genRandomMatches
public boolean genRandomMatches(LocalDateTime startTime, int duration, String[] fields, int divisionId) Create random matches.- Parameters:
startTime
- the start timeduration
- the durationfields
- the fieldsdivisionId
- the division id- Returns:
- the list
-
setDivisionId
Sets division id.- Parameters:
divisionId
- int: the division id- Throws:
IllegalArgumentException
- the illegal argument exception
-
setCompetingTeams
Sets competing teams in a division.- Parameters:
competingTeams
- ArrayList: The competing teams
-
setMatches
Sets matches in a division.- Parameters:
matches
- ArrayList: The matches
-
setDivisionCategory
Sets division category.- Parameters:
divisionCategory
- String: The division category- Throws:
IllegalArgumentException
- the illegal argument exception
-
getDivisionId
public int getDivisionId()Gets division id.- Returns:
- divisionId int : the division id
-
setCupId
public void setCupId(int cupId) Sets cup id of the division.- Parameters:
cupId
- int: the cup id
-
getCupId
public int getCupId()Gets cup id.- Returns:
- cupId int : the cup id
-
equals
override equals method -
hashCode
public int hashCode()gets hashcode -
toString
toString method
-