public Contact getContactById(Long id) { if (id == null) return null; for (Contact c : contactList) { if (c.getId().equals(id)) { return c; } } return null; }
public ApiContacts getContacts() { ApiContacts apiContacts = new ApiContacts(); List<ApiContact> apiContactList = new ArrayList<ApiContact>(); for (Contact c : contactList) { ApiContact apiContact = new ApiContact(); apiContact.setId("" + c.getId()); apiContact.setName(c.getName()); apiContact.setEmail(c.getEmail()); apiContactList.add(apiContact); } apiContacts.setSize(apiContactList.size()); apiContacts.setContacts(apiContactList); return apiContacts; }
public Long saveContact(Contact contact) { Long id = new Long(contactList.size() + 1); contact.setId(id); contactList.add(contact); return id; }