Package edu.ntnu.idatt1002.k2g05.models
Class Tournament
java.lang.Object
edu.ntnu.idatt1002.k2g05.models.Tournament
- All Implemented Interfaces:
Serializable
Class for holding a tournament and all its data.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Method for adding players to the tournament.boolean
addRoundCollections
(RoundCollection roundCollection) Appends the specified roundCollection to the end of the tournament's roundCollections list.void
Gets all the players in the tournament.Gets all the RoundCollections in the tournamentint
getCity()
getDate()
getName()
getPlayersBySearch
(String search, int threshold) Method for returning a list over results given a search query by name.getRoundCollections
(int index) Get a specific roundCollection given its insertion order (index) in the tournament.getRoundCollections
(RoundType type) Returns anOptional
describing the first roundCollection match of the given type, or an emptyOptional
if it does not contain any roundCollection with this type.static Tournament
Method for getting an instance of a tournament given a serialized file.boolean
removePlayer
(Player player) Method for removing a given player from the torunamentremoveRoundCollection
(int index) Removes the roundCollection at the specified position in this list (optional operation).boolean
removeRoundCollection
(RoundCollection roundCollection) Removes the first occurrence of a roundCollection from this list, if it is present.boolean
Method for saving the current instance of the tournament to a serialized file.void
setBowlingAlley
(String bowlingAlley) void
void
void
setLastSaveLocation
(String lastSaveLocation) void
void
Sets the name of the tournament.void
setRoundsTemplate
(RoundsTemplate roundsTemplate) toString()
-
Constructor Details
-
Tournament
Constructor of the Tournament class for creating an instance of the class.- Parameters:
name
- of the tournamentleague
- for the tournamentdate
- for the start of the tournamentcity
- where the tournament is located.bowlingAlly
- where the tournament is played.
-
-
Method Details
-
getName
-
setName
Sets the name of the tournament.- Parameters:
name
- to be set.
-
getAllRoundCollections
Gets all the RoundCollections in the tournament- Returns:
- the roundCollections
-
getRoundCollections
Get a specific roundCollection given its insertion order (index) in the tournament.- Parameters:
index
- index of the roundCollection to return- Returns:
- the roundCollection at the specified position in the tournament
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()
)
-
getRoundCollections
Returns anOptional
describing the first roundCollection match of the given type, or an emptyOptional
if it does not contain any roundCollection with this type.- Parameters:
type
- of the collection to get.- Returns:
- an
Optional
describing the first roundCollection match of the given type, or an emptyOptional
if it does not contain any roundCollection with this type. - Throws:
NullPointerException
- if the tournament does not contain any roundcollections
-
addRoundCollections
Appends the specified roundCollection to the end of the tournament's roundCollections list.null
is prohibited.- Parameters:
roundCollection
- element to be appended to this list- Returns:
true
(as specified byCollection.add(E)
)- Throws:
NullPointerException
- if the specified element is null
-
removeRoundCollection
Removes the first occurrence of a roundCollection from this list, if it is present. If this tournament does not contain the roundCollection, it is unchanged. Returnstrue
if this list contained the specified element (or equivalently, if this list changed as a result of the call).- Parameters:
roundCollection
- roundCollection to be removed from this tournament, if present- Returns:
true
if this list contained the specified round.
-
removeRoundCollection
Removes the roundCollection at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.- Parameters:
index
- the index of the roundCollection to be removed- Returns:
- the element previously at the specified position
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()
)
-
getAllPlayers
Gets all the players in the tournament.- Returns:
- all the players
-
getPlayersBySearch
Method for returning a list over results given a search query by name. A fuzzy search algorithm is used so the user does not have to write the exact player name.- Parameters:
search
- to be filtered bythreshold
- of the fuzzy search, the higher the value the more specific a search has to be. Threshold must be between 0 and 100- Returns:
-
addPlayer
Method for adding players to the tournament.- Parameters:
player
- to be added ot the list- Throws:
IllegalArgumentException
- if the player is already added to the tournament.
-
removePlayer
Method for removing a given player from the torunament- Parameters:
player
- to be removed.- Returns:
true
if the tournament contained the specified element- Throws:
NullPointerException
- if the given player is null
-
getLeague
-
setLeague
-
getDate
-
setDate
-
getCity
-
setCity
-
getBowlingAlley
-
setBowlingAlley
-
getAmountOfPlayers
public int getAmountOfPlayers() -
getRoundsTemplate
-
setRoundsTemplate
-
save
Method for saving the current instance of the tournament to a serialized file.- Parameters:
url
- to save to- Returns:
true
if the save was successful- Throws:
UncheckedIOException
IllegalArgumentException
- if url is blank or it doesn't end in .trnm
-
getLastSaveLocation
-
setLastSaveLocation
-
load
Method for getting an instance of a tournament given a serialized file.- Parameters:
url
- of the file- Returns:
- the tournament
- Throws:
ClassNotFoundException
- Class of a serialized object cannot be found.
-
toString
-
clearRoundCollections
public void clearRoundCollections()
-