package implemB;

import java.util.Set;
import java.util.TreeSet;

public class Repertoire {
	private Set<Contact> contacts;
	
	public Repertoire()
	{
		this.contacts = new TreeSet<Contact>();
	}
	
	public void addContact(String firstName, String lastName)
	{
		this.contacts.add(new Contact(firstName, lastName));
	}
	
	public Contact getContact(String firstName, String lastName)
	{
		for(Contact c : this.getContacts())
			if(c.getFirstName().toLowerCase().equals(firstName.toLowerCase()))
				if(c.getLastName().toLowerCase().equals(lastName.toLowerCase()))
					return c;
		
		return null;
	}

	public boolean delContact(String firstName, String lastName)
	{
		Contact c;
		
		c = this.getContact(firstName, lastName);
				
		if(c != null)
			this.contacts.remove(c);
		
		return c != null;
	}
	
	public Contact findFromNumber(String num)
	{
		for(Contact c : this.getContacts())
			if(c.findNumber(num) != null)
				return c;
		
		return null;
	}
	
	public Set<Contact> getContacts() {
		return this.contacts;
	}
}
