FileDocCategorySizeDatePackage
ContactList.javaAPI DocAndroid 1.5 API5773Wed May 06 22:42:46 BST 2009com.android.im.engine

ContactList

public class ContactList extends ImEntity

Fields Summary
protected Address
mAddress
protected String
mName
protected boolean
mDefault
protected ContactListManager
mManager
private HashMap
mContactsCache
Constructors Summary
public ContactList(Address address, String name, boolean isDefault, Collection contacts, ContactListManager manager)

        mAddress = address;
        mDefault = isDefault;
        mName = name;
        mManager = manager;

        mContactsCache = new HashMap<String, Contact>();
        if (contacts != null) {
            for (Contact c : contacts) {
                mContactsCache.put(manager.normalizeAddress(c.getAddress().getFullName()), c);
            }
        }
    
Methods Summary
public voidaddContact(java.lang.String address)
Add a contact to the list. The contact is specified by its address string.

param
address the address string specifies the contact.
throws
IllegalArgumentException if the address is invalid.
throws
NullPointerException if the address string is null
throws
ImException if the contact is not allowed to be added

        address = mManager.normalizeAddress(address);

        if (null == address) {
            throw new NullPointerException();
        }

        if (mManager.isBlocked(address)) {
            throw new ImException(ImErrorInfo.CANT_ADD_BLOCKED_CONTACT,
                    "Contact has been blocked");
        }

        if(containsContact(address)){
            throw new ImException(ImErrorInfo.CONTACT_EXISTS_IN_LIST,
                    "Contact already exists in the list");
        }

        mManager.addContactToListAsync(address, this);
    
public synchronized booleancontainsContact(java.lang.String address)

        return mContactsCache.containsKey(mManager.normalizeAddress(address));
    
public synchronized booleancontainsContact(Address address)

        return address == null ? false
                : mContactsCache.containsKey(mManager.normalizeAddress(address.getFullName()));
    
public synchronized booleancontainsContact(Contact c)

        return c == null ? false
                : mContactsCache.containsKey(mManager.normalizeAddress(c.getAddress().getFullName()));
    
public AddressgetAddress()

        return mAddress;
    
public synchronized ContactgetContact(Address address)

        return mContactsCache.get(mManager.normalizeAddress(address.getFullName()));
    
public synchronized ContactgetContact(java.lang.String address)

        return mContactsCache.get(mManager.normalizeAddress(address));
    
public synchronized java.util.CollectiongetContacts()

        return new ArrayList<Contact>(mContactsCache.values());
    
public synchronized intgetContactsCount()

        return mContactsCache.size();
    
public java.lang.StringgetName()

        return mName;
    
protected voidinsertToCache(Contact contact)

        mContactsCache.put(mManager.normalizeAddress(contact.getAddress().getFullName()), contact);
    
public booleanisDefault()

        return mDefault;
    
public voidremoveContact(Address address)
Remove a contact from the list. If the contact is not in the list, nothing will happen. Otherwise, the contact will be removed from the list on the server asynchronously.

param
address the address of the contact to be removed from the list
throws
NullPointerException If the address is null

        if(address == null) {
            throw new NullPointerException();
        }
        Contact c = getContact(address);
        if(c != null) {
            removeContact(c);
        }
    
public voidremoveContact(Contact contact)
Remove a contact from the list. If the contact is not in the list, nothing will happen. Otherwise, the contact will be removed from the list on the server asynchronously.

param
contact the contact to be removed from the list
throws
NullPointerException If the contact is null

        if(contact == null) {
            throw new NullPointerException();
        }

        if(containsContact(contact)) {
            mManager.removeContactFromListAsync(contact, this);
        }
    
protected voidremoveFromCache(Contact contact)

        mContactsCache.remove(mManager.normalizeAddress(contact.getAddress().getFullName()));
    
public voidsetDefault(boolean isDefault)

        this.mDefault = isDefault;
    
public voidsetName(java.lang.String name)

        if (null == name) {
            throw new NullPointerException();
        }

        mManager.setListNameAsync(name, this);