java.lang.Object
edu.ntnu.idatt1002.k01g08.fta.objects.team.Team
All Implemented Interfaces:
Iterable<Player>

public class Team extends Object implements Iterable<Player>
Represents a team of football players
  • Constructor Details

    • Team

      public Team(String name)
      Creates a team instance, with the given name.
      Parameters:
      name - the name of the team
  • Method Details

    • getName

      public String getName()
      Returns the name of this team.
      Returns:
      the name of this team
    • getPlayer

      public Player getPlayer(int number)
      Returns the player with the given squad number. If no player has the number, returns null.
      Parameters:
      number - the squad number of the player
      Returns:
      the player with the given squad number, or null
    • size

      public int size()
      Returns the number of players on this team.
      Returns:
      the number of players on this team
    • addPlayer

      public boolean addPlayer(Player player) throws NullPointerException
      Adds the given player to this team, if its squad number is not shared by any player already present. Returns true if the player was added, and false if not.
      Parameters:
      player - a player to be added to this team
      Returns:
      true if the player was added, false if not
      Throws:
      NullPointerException - if player is null
    • addPlayers

      public boolean addPlayers(Collection<? extends Player> players) throws NullPointerException
      Tries to add all the players in the given collection to the team. Returns true if any of the players were added.
      Parameters:
      players - a player to be added to this team
      Returns:
      true any of the players were added
      Throws:
      NullPointerException - if player is null
    • removePlayer

      public boolean removePlayer(Player player)
      Tries to remove the given player from this team. Returns true if the player was present, and false if not.
      Parameters:
      player - a player to be removed from this team
      Returns:
      true if a player was removed, false if not
    • removePlayer

      public boolean removePlayer(int number)
      Tries to remove the player with the given squad number from this tram. Returns true if a player with that squad number was present, and false if not.
      Parameters:
      number - the squad number of the player to be removed from this team
      Returns:
      true if a player was removed, false if not
    • iterator

      public Iterator<Player> iterator()
      Returns an iterator over the players in this team.
      Specified by:
      iterator in interface Iterable<Player>
      Returns:
      an iterator over the players in this team.
    • toString

      public String toString()
      Overrides:
      toString in class Object