Class GuestList

java.lang.Object
it.unimi.di.prog2.h14.member.GuestList
All Implemented Interfaces:
Iterable<String>

public class GuestList extends Object implements Iterable<String>
Guest list for a private party of prescribed capacity.

Guests are identified by their names that are represented by strings, which must not be null or empty; no check on duplicates is performed.

  • Field Details

    • guests

      private final List<String> guests
      The list of guests.
    • capacity

      private final int capacity
      The maximum capacity of the guest list.
  • Constructor Details

    • GuestList

      public GuestList(int capacity)
      Builds an empty guest list with the given maximum capacity.
      Parameters:
      capacity - the maximum size of the guest list.
      Throws:
      IllegalArgumentException - if capacity is not positive.
    • GuestList

      public GuestList(List<String> guests, int capacity)
      Builds a guest list with the given maximum capacity, populated with an initial list of guests.
      Parameters:
      guests - the initial list of guests.
      capacity - the maximum size of the guest list.
      Throws:
      IllegalArgumentException - if capacity is not positive.
      IllegalArgumentException - if guests.size() is greater than capacity.
      NullPointerException - if guests is null or contains null.
  • Method Details

    • invite

      public void invite(String guest)
      Adds a guest to this guest list.
      Parameters:
      guest - the guest name.
      Throws:
      IllegalStateException - if the list has reached its maximum capacity.
      NullPointerException - if guest is null.
    • iterator

      public Iterator<String> iterator()
      Specified by:
      iterator in interface Iterable<String>
    • firstGuests

      public Iterator<String> firstGuests(int many)
      Returns an iterator for the first many guests.
      Parameters:
      many - the number of guests to return.
      Returns:
      the iterator.
    • toString

      public String toString()
      Overrides:
      toString in class Object