corny.addressbook.data
Class Contact

java.lang.Object
  extended by corny.addressbook.data.Contact
All Implemented Interfaces:
Record, Searchable, java.lang.Comparable<Contact>

public class Contact
extends java.lang.Object
implements java.lang.Comparable<Contact>, Searchable, Record

Data model class for Contacts vended from the Mac OS X address book. Provides access to most of the data fields of Address Book Contacts. Also implements methods to modify these fields. The modifications will be applied to Apple's Address Book automatically.

Author:
Corny

Constructor Summary
Contact(java.util.Map<java.lang.String,?> rawAttributes)
          Creates a new Contact from the data provided by the native code.
Contact(java.lang.String uid, Group parentGroup, java.lang.String fName, java.lang.String mName, java.lang.String lName, java.lang.String title, java.lang.String org, java.util.List<MultiValue.KeyValuePair<java.lang.String>> email, java.util.List<MultiValue.KeyValuePair<java.lang.String>> phone, java.util.List<MultiValue.KeyValuePair<Address>> address, java.util.List<MultiValue.KeyValuePair<java.lang.String>> chat, java.util.Date birthday, boolean isPerson)
          Creates a new Contact and sets every available field.
 
Method Summary
 void addSearchStringsToList(java.util.List<java.lang.Object> searchObjects, java.lang.String propertyLabel)
          Used by Filter classes to fetch the searchable fields of an object.
 boolean addToGroup(Group g)
          Adds this Contact to a Group
 int compareTo(Contact o)
          Compares this Contact to another by comparing the last names.
 boolean equals(java.lang.Object o)
          Compared the UIDs.
 MultiValue<Address> getAddress()
           
 java.util.Date getBirthday()
           
 MultiValue<java.lang.String> getChat()
           
 java.util.Date getCreationDate()
           
 java.lang.String getDisplayedName()
           
 java.lang.String getDisplayedName(boolean lastNameFirst)
          The Contact's displayed name.
 MultiValue<java.lang.String> getEmail()
           
 java.lang.String getFirstName()
           
static java.util.Comparator<Contact> getFirstNameSorter()
           
 java.lang.String getFullName()
           
 java.lang.String getFullNameLastNameFirst()
           
 java.lang.String getLastName()
           
static java.util.Comparator<Contact> getLastNameSorter()
           
 java.lang.String getMiddleName()
           
 java.util.Date getModificationDate()
           
 java.lang.String getOrganization()
           
 java.util.Set<Group> getParentGroups()
           
 MultiValue<java.lang.String> getPhone()
           
 java.awt.image.BufferedImage getPicture()
           
 java.lang.String getTitle()
           
 java.lang.String getUID()
           
 java.lang.Object getValueForProperty(ContactProperty prop)
          Returns the value for the given ContactProperty of this Contact.
 java.lang.Object getValueForProperty(ContactProperty prop, java.lang.String label)
          Returns the value for the given ContactProperty of this Contact.
 boolean hasPicture()
           
 void initializeWith(Record o)
          Used by NativeAddressBook to re-initialize this Contact if it was modified externally.
 boolean isPerson()
           
 void reInitialize(java.lang.String fName, java.lang.String mName, java.lang.String lName, java.lang.String title, java.lang.String org, java.util.List<MultiValue.KeyValuePair<java.lang.String>> email, java.util.List<MultiValue.KeyValuePair<java.lang.String>> phone, java.util.List<MultiValue.KeyValuePair<Address>> address, java.util.List<MultiValue.KeyValuePair<java.lang.String>> chat, java.util.Date birthday, java.lang.Boolean isPerson)
          Called by NativeAddressBook.modifyContact(...).
 boolean removeFromGroup(Group g)
          Removes this Contact from a Group
 void revealInAddressBook(boolean edit)
          Opens the Address Book and selects this Contact.
 boolean setAddress(MultiValue.KeyValuePair<Address> oldValue, java.lang.String newKey, Address newValue)
          Modifies a given address.
 boolean setAddresses(java.util.List<MultiValue.KeyValuePair<Address>> addresses)
          Replaces the current addresses with the addresses in the given List of KeyValuePairs.
 boolean setAddresses(MultiValue<Address> addresses)
          Replaces the current addresses with the content of the given MultiValue instance.
 boolean setBirthday(java.util.Date birthday)
          Changes the Birthday of this Contact.
 boolean setChat(MultiValue.KeyValuePair<java.lang.String> oldValue, java.lang.String newKey, java.lang.String newValue)
          Modifies a given chat.
 boolean setChats(java.util.List<MultiValue.KeyValuePair<java.lang.String>> chats)
          Replaces the current chats with the chats in the given List of KeyValuePairs.
 boolean setChats(MultiValue<java.lang.String> chats)
          Replaces the current chats with the content of the given MultiValue instance.
 boolean setEmail(MultiValue.KeyValuePair<java.lang.String> oldValue, java.lang.String newKey, java.lang.String newValue)
          Modifies a given Email address.
 boolean setEmails(java.util.List<MultiValue.KeyValuePair<java.lang.String>> emails)
          Replaces the current Emails with the Emails in the given List of KeyValuePairs.
 boolean setEmails(MultiValue<java.lang.String> emails)
          Replaces the current Emails with the content of the given MultiValue instance.
 boolean setFirstName(java.lang.String firstName)
          Changes the first name of this Contact.
 boolean setIsPerson(boolean isPerson)
          Changes the person flag of this Contact.
 boolean setLastName(java.lang.String lastName)
          Changes the last name of this Contact.
 boolean setMiddleName(java.lang.String middleName)
          Changes the middle name of this Contact.
 boolean setOrganitation(java.lang.String organization)
          Changes the organization of this Contact.
 boolean setPhone(MultiValue.KeyValuePair<java.lang.String> oldValue, java.lang.String newKey, java.lang.String newValue)
          Modifies a given phone number.
 boolean setPhones(java.util.List<MultiValue.KeyValuePair<java.lang.String>> phones)
          Replaces the current phone numbers with the phone numbers in the given List of KeyValuePairs.
 boolean setPhones(MultiValue<java.lang.String> phones)
          Replaces the current phone numbers with the content of the given MultiValue instance.
 boolean setTitle(java.lang.String title)
          Changes the title of this Contact.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Contact

public Contact(java.util.Map<java.lang.String,?> rawAttributes)
Creates a new Contact from the data provided by the native code.

Parameters:
rawAttributes - Data provided by the native code

Contact

public Contact(java.lang.String uid,
               Group parentGroup,
               java.lang.String fName,
               java.lang.String mName,
               java.lang.String lName,
               java.lang.String title,
               java.lang.String org,
               java.util.List<MultiValue.KeyValuePair<java.lang.String>> email,
               java.util.List<MultiValue.KeyValuePair<java.lang.String>> phone,
               java.util.List<MultiValue.KeyValuePair<Address>> address,
               java.util.List<MultiValue.KeyValuePair<java.lang.String>> chat,
               java.util.Date birthday,
               boolean isPerson)
Creates a new Contact and sets every available field. Called when adding a new Contact by NativeAddressBook.addContact(...).

Parameters:
uid - UID of the Contact
parentGroup - Parent Group
fName - First name
mName - Middle name
lName - Last name
title - Title
org - Organization
email - Email
phone - Phone
address - Address
chat - Chat
birthday - Birthday
isPerson - true: Person, false: Organization
Method Detail

getLastNameSorter

public static java.util.Comparator<Contact> getLastNameSorter()
Returns:
Comparator comparing the last names first

getFirstNameSorter

public static java.util.Comparator<Contact> getFirstNameSorter()
Returns:
Comparator comparing the first names first

getValueForProperty

public java.lang.Object getValueForProperty(ContactProperty prop,
                                            java.lang.String label)
Returns the value for the given ContactProperty of this Contact.

Parameters:
prop - ContactProperty
label - Specific label for a multi value property
Returns:
Value for the property

getValueForProperty

public java.lang.Object getValueForProperty(ContactProperty prop)
Returns the value for the given ContactProperty of this Contact.

Parameters:
prop - ContactProperty
Returns:
Value for the property

getFirstName

public java.lang.String getFirstName()
Returns:
First name

getMiddleName

public java.lang.String getMiddleName()
Returns:
Middle name

getLastName

public java.lang.String getLastName()
Returns:
Last name

getTitle

public java.lang.String getTitle()
Returns:
Title

getOrganization

public java.lang.String getOrganization()
Returns:
Organization

getEmail

public MultiValue<java.lang.String> getEmail()
Returns:
Emails

getPhone

public MultiValue<java.lang.String> getPhone()
Returns:
Phones

getAddress

public MultiValue<Address> getAddress()
Returns:
Addresses

getChat

public MultiValue<java.lang.String> getChat()
Returns:
Chat accounts

getBirthday

public java.util.Date getBirthday()
Returns:
Birthday

getParentGroups

public java.util.Set<Group> getParentGroups()
Specified by:
getParentGroups in interface Record
Returns:
Parent groups of this Contact

getCreationDate

public java.util.Date getCreationDate()
Returns:
Creation date

getModificationDate

public java.util.Date getModificationDate()
Returns:
Modification date

getUID

public java.lang.String getUID()
Specified by:
getUID in interface Record
Returns:
The Record's unique ID

isPerson

public boolean isPerson()
Returns:
true, if the Contact represents a Person or false, if the Contact represents an Organization

hasPicture

public boolean hasPicture()
Returns:
True, if the Contact has an attached picture

getPicture

public java.awt.image.BufferedImage getPicture()
Returns:
The contact's attached image or null if none exists

getFullName

public java.lang.String getFullName()
Returns:
The Contact's full name (First, middle and last name)

getFullNameLastNameFirst

public java.lang.String getFullNameLastNameFirst()
Returns:
The Contact's full name in the form Last, first middle

getDisplayedName

public java.lang.String getDisplayedName(boolean lastNameFirst)
The Contact's displayed name. If the Contact is a person, its full name is returned. If the Contact is an Organization, the Organization is returned.

Parameters:
lastNameFirst - If and the Contact is a Person, the full name will be return with the last name first.
Returns:
Displayed name

getDisplayedName

public java.lang.String getDisplayedName()
Returns:
The Contact's displayed name. If the Contact is a person, its full name is returned. If the Contact is an Organization, the Organization is returned. Same as getDisplayedName(false);

setFirstName

public boolean setFirstName(java.lang.String firstName)
Changes the first name of this Contact. This method automatically changes the value in Apple's Address Book, too.

Parameters:
firstName - New first name
Returns:
true if the value is now equal to the given value.

setMiddleName

public boolean setMiddleName(java.lang.String middleName)
Changes the middle name of this Contact. This method automatically changes the value in Apple's Address Book, too.

Parameters:
middleName - New first name
Returns:
true if the value is now equal to the given value.

setLastName

public boolean setLastName(java.lang.String lastName)
Changes the last name of this Contact. This method automatically changes the value in Apple's Address Book, too.

Parameters:
lastName - New first name
Returns:
true if the value is now equal to the given value.

setTitle

public boolean setTitle(java.lang.String title)
Changes the title of this Contact. This method automatically changes the value in Apple's Address Book, too.

Parameters:
title - New first name
Returns:
true if the value is now equal to the given value.

setIsPerson

public boolean setIsPerson(boolean isPerson)
Changes the person flag of this Contact. This method automatically changes the value in Apple's Address Book, too.

Parameters:
isPerson - true: Contact is a Person, false: Contact is a Company
Returns:
true if the value is now equal to the given value.

setBirthday

public boolean setBirthday(java.util.Date birthday)
Changes the Birthday of this Contact. This method automatically changes the value in Apple's Address Book, too.

Parameters:
birthday - New birthday
Returns:
true if the value is now equal to the given value.

setOrganitation

public boolean setOrganitation(java.lang.String organization)
Changes the organization of this Contact. This method automatically changes the value in Apple's Address Book, too.

Parameters:
organization - New first name
Returns:
true if the value is now equal to the given value.

setEmails

public boolean setEmails(MultiValue<java.lang.String> emails)
Replaces the current Emails with the content of the given MultiValue instance. This method automatically changes the values in Apple's Address Book, too.

Parameters:
emails - New Emails
Returns:
true if the value is now equal to the given value.

setEmails

public boolean setEmails(java.util.List<MultiValue.KeyValuePair<java.lang.String>> emails)
Replaces the current Emails with the Emails in the given List of KeyValuePairs. This method automatically changes the values in Apple's Address Book, too.

Parameters:
emails - New Emails
Returns:
true if the value is now equal to the given value.

setEmail

public boolean setEmail(MultiValue.KeyValuePair<java.lang.String> oldValue,
                        java.lang.String newKey,
                        java.lang.String newValue)
Modifies a given Email address. This method automatically changes the value in Apple's Address Book, too.

Parameters:
oldValue - Old Email address to modify
newKey - New key or null to leave the old key
newValue - New value or null to leave the old value
Returns:
true if the value is now equal to the given value.

setPhones

public boolean setPhones(MultiValue<java.lang.String> phones)
Replaces the current phone numbers with the content of the given MultiValue instance. This method automatically changes the values in Apple's Address Book, too.

Parameters:
phones - New phone numbers
Returns:
true if the value is now equal to the given value.

setPhones

public boolean setPhones(java.util.List<MultiValue.KeyValuePair<java.lang.String>> phones)
Replaces the current phone numbers with the phone numbers in the given List of KeyValuePairs. This method automatically changes the values in Apple's Address Book, too.

Parameters:
phones - New phone numbers
Returns:
true if the value is now equal to the given value.

setPhone

public boolean setPhone(MultiValue.KeyValuePair<java.lang.String> oldValue,
                        java.lang.String newKey,
                        java.lang.String newValue)
Modifies a given phone number. This method automatically changes the value in Apple's Address Book, too.

Parameters:
oldValue - Old phone number to modify
newKey - New key or null to leave the old key
newValue - New value or null to leave the old value
Returns:
true if the value is now equal to the given value.

setAddresses

public boolean setAddresses(MultiValue<Address> addresses)
Replaces the current addresses with the content of the given MultiValue instance. This method automatically changes the values in Apple's Address Book, too.

Parameters:
addresses - New addresses
Returns:
true if the value is now equal to the given value.

setAddresses

public boolean setAddresses(java.util.List<MultiValue.KeyValuePair<Address>> addresses)
Replaces the current addresses with the addresses in the given List of KeyValuePairs. This method automatically changes the values in Apple's Address Book, too.

Parameters:
addresses - New addresses
Returns:
true if the value is now equal to the given value.

setAddress

public boolean setAddress(MultiValue.KeyValuePair<Address> oldValue,
                          java.lang.String newKey,
                          Address newValue)
Modifies a given address. This method automatically changes the value in Apple's Address Book, too.

Parameters:
oldValue - Old address to modify
newKey - New key or null to leave the old key
newValue - New value or null to leave the old value
Returns:
true if the value is now equal to the given value.

setChats

public boolean setChats(MultiValue<java.lang.String> chats)
Replaces the current chats with the content of the given MultiValue instance. This method automatically changes the values in Apple's Address Book, too.

Parameters:
chats - New chats
Returns:
true if the value is now equal to the given value.

setChats

public boolean setChats(java.util.List<MultiValue.KeyValuePair<java.lang.String>> chats)
Replaces the current chats with the chats in the given List of KeyValuePairs. This method automatically changes the values in Apple's Address Book, too.

Parameters:
chats - New chats
Returns:
true if the value is now equal to the given value.

setChat

public boolean setChat(MultiValue.KeyValuePair<java.lang.String> oldValue,
                       java.lang.String newKey,
                       java.lang.String newValue)
Modifies a given chat. This method automatically changes the value in Apple's Address Book, too.

Parameters:
oldValue - Old chat to modify
newKey - New key or null to leave the old key
newValue - New value or null to leave the old value
Returns:
true if the value is now equal to the given value.

addToGroup

public boolean addToGroup(Group g)
Adds this Contact to a Group

Parameters:
g - Group to add this Contact to
Returns:
true, if this Contact was successfully added to the Group or if it already was part of the Group

removeFromGroup

public boolean removeFromGroup(Group g)
Removes this Contact from a Group

Parameters:
g - Group to remove this Contact from
Returns:
True, if this Contact is no member of the Group any more

revealInAddressBook

public void revealInAddressBook(boolean edit)
Opens the Address Book and selects this Contact. If edit is set to true, Address Book will open in editing mode.

Parameters:
edit - If true, Address Book will open in editing mode

reInitialize

public void reInitialize(java.lang.String fName,
                         java.lang.String mName,
                         java.lang.String lName,
                         java.lang.String title,
                         java.lang.String org,
                         java.util.List<MultiValue.KeyValuePair<java.lang.String>> email,
                         java.util.List<MultiValue.KeyValuePair<java.lang.String>> phone,
                         java.util.List<MultiValue.KeyValuePair<Address>> address,
                         java.util.List<MultiValue.KeyValuePair<java.lang.String>> chat,
                         java.util.Date birthday,
                         java.lang.Boolean isPerson)
Called by NativeAddressBook.modifyContact(...). Do not call this method, call NativeAddressBook.modifyContact(...) instead if you want to modify every attribute of this Contact.

Parameters:
fName - New first name
mName - New middle name
lName - New last name
title - New title
org - New organization
email - New E-Mails
phone - New Phones
address - New Addresses
chat - New Chats
birthday - Birthday
isPerson - New Person flag
See Also:
NativeAddressBook.modifyContact(Contact, String, String, String, String, String, List, List, List, List, Date, Boolean)

compareTo

public int compareTo(Contact o)
Compares this Contact to another by comparing the last names.

Specified by:
compareTo in interface java.lang.Comparable<Contact>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addSearchStringsToList

public void addSearchStringsToList(java.util.List<java.lang.Object> searchObjects,
                                   java.lang.String propertyLabel)
Description copied from interface: Searchable
Used by Filter classes to fetch the searchable fields of an object.

Specified by:
addSearchStringsToList in interface Searchable
Parameters:
searchObjects - List to add the searchable fields to
propertyLabel - If this is set, only the properties with a specific label should be added to the list.

equals

public boolean equals(java.lang.Object o)
Compared the UIDs.

Overrides:
equals in class java.lang.Object

initializeWith

public void initializeWith(Record o)
Used by NativeAddressBook to re-initialize this Contact if it was modified externally.

Specified by:
initializeWith in interface Record
Parameters:
o - Record to take data from