Class GuestList

java.lang.Object
it.unimi.di.prog2.h12.GuestList

public class GuestList extends Object
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

    • guests

      public List<String> guests()
      Returns the list of guests.

      The returned List is unmodifiable.

      As we'll see this method is an horrible idea!

      Returns:
      an unmodifiable view of the guests list.
    • 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object