Class Tournament

java.lang.Object
edu.ntnu.idatt1002.k2g05.models.Tournament
All Implemented Interfaces:
Serializable

public class Tournament extends Object implements Serializable
Class for holding a tournament and all its data.
See Also:
  • Constructor Details

    • Tournament

      public Tournament(String name, League league, LocalDate date, String city, String bowlingAlly)
      Constructor of the Tournament class for creating an instance of the class.
      Parameters:
      name - of the tournament
      league - for the tournament
      date - for the start of the tournament
      city - where the tournament is located.
      bowlingAlly - where the tournament is played.
  • Method Details

    • getName

      public String getName()
    • setName

      public void setName(String name)
      Sets the name of the tournament.
      Parameters:
      name - to be set.
    • getAllRoundCollections

      public List<RoundCollection> getAllRoundCollections()
      Gets all the RoundCollections in the tournament
      Returns:
      the roundCollections
    • getRoundCollections

      public RoundCollection getRoundCollections(int index)
      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

      public Optional<RoundCollection> getRoundCollections(RoundType type)
      Returns an Optional describing the first roundCollection match of the given type, or an empty Optional 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 empty Optional if it does not contain any roundCollection with this type.
      Throws:
      NullPointerException - if the tournament does not contain any roundcollections
    • addRoundCollections

      public boolean addRoundCollections(RoundCollection roundCollection)
      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 by Collection.add(E))
      Throws:
      NullPointerException - if the specified element is null
    • removeRoundCollection

      public boolean removeRoundCollection(RoundCollection roundCollection)
      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. Returns true 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

      public RoundCollection removeRoundCollection(int index)
      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

      public HashSet<Player> getAllPlayers()
      Gets all the players in the tournament.
      Returns:
      all the players
    • getPlayersBySearch

      public List<Player> getPlayersBySearch(String search, int threshold)
      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 by
      threshold - 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

      public void addPlayer(Player player)
      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

      public boolean removePlayer(Player player)
      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

      public League getLeague()
    • setLeague

      public void setLeague(League league)
    • getDate

      public LocalDate getDate()
    • setDate

      public void setDate(LocalDate date)
    • getCity

      public String getCity()
    • setCity

      public void setCity(String city)
    • getBowlingAlley

      public String getBowlingAlley()
    • setBowlingAlley

      public void setBowlingAlley(String bowlingAlley)
    • getAmountOfPlayers

      public int getAmountOfPlayers()
    • getRoundsTemplate

      public RoundsTemplate getRoundsTemplate()
    • setRoundsTemplate

      public void setRoundsTemplate(RoundsTemplate roundsTemplate)
    • save

      public boolean save(String url)
      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

      public String getLastSaveLocation()
    • setLastSaveLocation

      public void setLastSaveLocation(String lastSaveLocation)
    • load

      public static Tournament load(String url) throws ClassNotFoundException
      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

      public String toString()
      Overrides:
      toString in class Object
    • clearRoundCollections

      public void clearRoundCollections()