corny.addressbook.data
Class Group

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

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

Data model class for contact groups vended from the Mac OS X address book. Implements methods to modify the Group content of Apple's Address Book directly.

Author:
Corny

Constructor Summary
Group(java.util.List<?> rawContent, java.util.Map<java.lang.String,Record> persons)
          Creates a new Group from the raw data provided by the native Code.
Group(java.util.List<Contact> members)
          Constructor for the "Everyone"-Group
Group(java.lang.String name, java.lang.String uid)
          Creates a new, empty Group.
 
Method Summary
 boolean addRecord(Record newMember)
          Adds a new Record to this Group.
 int compareTo(Group o)
          Compares the name of this Group to the name of another Group
 boolean equals(java.lang.Object o)
           
 java.util.Set<Contact> getMembers()
          Returns the members of this Group.
 java.lang.String getName()
           
 java.util.Set<Group> getParentGroups()
          Returns the parent Groups of this Group.
 java.util.Set<Group> getSubGroups()
          Returns the subgroups of this Group.
 java.lang.String getUID()
           
 void initializeWith(Record o)
          Re-Initialized a Record with the data of another Record.
 boolean isEveryoneGroup()
           
 boolean isSmartGroup()
           
 java.util.Iterator<Contact> iterator()
           
 boolean removeRecord(Record recordToRemove)
          Removes a Record from this Group.
 boolean setName(java.lang.String name)
          Changes the Name of this Group.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Group

public Group(java.util.List<?> rawContent,
             java.util.Map<java.lang.String,Record> persons)
Creates a new Group from the raw data provided by the native Code.

Parameters:
rawContent - Data provided by the native Code
persons - Map containing all Persons

Group

public Group(java.util.List<Contact> members)
Constructor for the "Everyone"-Group

Parameters:
members - All Contacts

Group

public Group(java.lang.String name,
             java.lang.String uid)
Creates a new, empty Group. Called from NativeAddressBook.addGroup(String, Group).

Parameters:
name - Name of the new Group
uid - UID of the new Group
See Also:
NativeAddressBook.addGroup(String, Group)
Method Detail

getName

public java.lang.String getName()
Returns:
Name of this Group

getUID

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

isSmartGroup

public boolean isSmartGroup()
Returns:
true, if this Group is a SmartGroup

getMembers

public java.util.Set<Contact> getMembers()
Returns the members of this Group. Ensure to not modify the returned Set since it is NOT a copy.

Returns:
Members of this Group

getSubGroups

public java.util.Set<Group> getSubGroups()
Returns the subgroups of this Group. Ensure to not modify the returned Set since it is NOT a copy.

Returns:
Subgroups of this Group

getParentGroups

public java.util.Set<Group> getParentGroups()
Returns the parent Groups of this Group. Ensure to not modify the returned Set since it is NOT a copy.

Specified by:
getParentGroups in interface Record
Returns:
Parent Groups of this Group

isEveryoneGroup

public boolean isEveryoneGroup()
Returns:
true if this Group is the "Everyone" Group.

setName

public boolean setName(java.lang.String name)
Changes the Name of this Group. This method automatically changes the value in Apple's Address Book, too.

Parameters:
name - New name of this Group
Returns:
true, if the name of the Contact is now equal to the given name.

addRecord

public boolean addRecord(Record newMember)
Adds a new Record to this Group. This method automatically adds the Record in Apple's Address Book, too.

Parameters:
newMember - New member of this Group
Returns:
true, if the Record was successfully added or already was part of this Group

removeRecord

public boolean removeRecord(Record recordToRemove)
Removes a Record from this Group. This method automatically removes the Record in Apple's Address Book, too.

Parameters:
recordToRemove - Record to remove
Returns:
true, if the record is no member of this Group any more

compareTo

public int compareTo(Group o)
Compares the name of this Group to the name of another Group

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

iterator

public java.util.Iterator<Contact> iterator()
Specified by:
iterator in interface java.lang.Iterable<Contact>
Returns:
Returns an iterator over the members of this Group.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
Returns:
true, if either both of the Groups are the "Everyone" Group or both of the Groups have the same ID. false otherwise.

initializeWith

public void initializeWith(Record o)
Description copied from interface: Record
Re-Initialized a Record with the data of another Record.

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