public class ContactSet extends Object
Constructor and Description |
---|
ContactSet()
Initializes this contact set to have a name.
|
ContactSet(ContactSet other)
Initialize this contact set by copying the name and contacts
from another contact set.
|
ContactSet(String setName)
Initialize this contact set so that it has the given name
and zero contacts.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Contact c)
Add a new contact to this contact set.
|
Contact |
getByName(String name)
Returns a new copy of the contact having the given name.
|
List<Contact> |
getContacts()
Returns a list containing new copies of all of the contacts
in this contact list.
|
String |
getName()
Return the name of this contact set.
|
void |
setName(String name)
Set the name of this contact set.
|
void |
update(Contact c,
String name,
PhoneNumber number)
Update the information for an existing contact in this contact set.
|
public ContactSet()
public ContactSet(String setName)
setName
- the non-null name of this contact setpublic ContactSet(ContactSet other)
other
- a non-null contact set to copypublic String getName()
public void setName(String name)
name
- a non-null name for this contact setpublic List<Contact> getContacts()
public Contact getByName(String name)
null
is returned if
no contact with the given name is in this contact set.name
- the non-null name of the contactpublic void update(Contact c, String name, PhoneNumber number)
ContactDoesNotExistException
is thrown and this set
remains unchanged. If a contact with the same name and phone number
as the updated contact information is already in this contact set
then a DuplicateContactException
is thrown and this
set remains unchanged.
NOTE TO STUDENTS: To correctly update the set, you must remove the contact from the set and add the updated contact back to the set.
c
- the non-null contact to updatename
- the non-null updated contact namenumber
- the non-null updated contact numberContactDoesNotExistException
- if the contact c is not in
this contact setDuplicateContactException
- if a contact having the
same name and number as the updated contact information is already in this
contact setpublic void add(Contact c)
c
- the non-null contact to addDuplicateContactException
- if c is already in this contact set