Working on the MetaContactList implementation

cusax-fix
Emil Ivov 20 years ago
parent 78a73349c1
commit ef90beec99

@ -5,8 +5,11 @@
import net.java.sip.communicator.service.contactlist.*;
/**
* A Default implementation of a MetaContactGroup.
*
* A Default implementation of a MetaContactGroup. Note that this implementation
* is only meant to be used for non-root contact groups and can only contain
* contacts. All subgroup retrieving methods would returns null/0 values.
* Root contact groups are to be represented by the RootMetaContactGroupImpl.
* <p>
* @author Emil Ivov
*/
public class MetaContactGroupImpl
@ -17,10 +20,17 @@ public class MetaContactGroupImpl
*/
private Vector childContacts = new Vector();
/**
* An empty list that we'll be using in order to return an empty iterator
* of the (non-existing) sub groups.
*/
private final List dummySubgroupsList = new LinkedList();
protected MetaContactGroupImpl()
private String groupName = null;
protected MetaContactGroupImpl(String groupName)
{
this.groupName = groupName;
}
/**
@ -107,6 +117,15 @@ public MetaContactGroup getMetaContactSubgroup(int index) throws
return null;
}
/**
* Returns the name of this group.
* @return a String containing the name of this group.
*/
public String getGroupName()
{
return groupName;
}
/**
* Returns the <tt>MetaContactGroup</tt> with the specified name.
*
@ -139,7 +158,7 @@ public int countSubgroups()
*/
public Iterator getSubgroups()
{
return childContacts.iterator();
return dummySubgroupsList.iterator();
}
/**
@ -161,4 +180,6 @@ void removeMetaContact(MetaContact metaContact)
{
this.childContacts.remove( metaContact );
}
}

@ -0,0 +1,159 @@
package net.java.sip.communicator.impl.contactlist;
import java.util.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
/**
* A default implementation of a meta contact.
* @author Emil Ivov
*/
public class MetaContactImpl
implements MetaContact
{
/**
* A vector containing all protocol specific contacts merged in this
* MetaContact.
*
*/
private Vector protoContacts = new Vector();
/**
* An id uniquely identifying the meta contact in this contact list.
*/
private String uid = null;
/**
* Returns a human readable string used by the UI to display the contact.
*/
private String displayName = "";
MetaContactImpl()
{
//create the uid
this.uid = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the number of protocol speciic <tt>Contact</tt>s that this
* <tt>MetaContact</tt> contains.
*
* @return an int indicating the number of protocol specific contacts
* merged in this <tt>MetaContact</tt>
*/
public int getContactCount()
{
return protoContacts.size();
}
/**
* Returns a Contact, encapsulated by this MetaContact and coming from
* the specified ProtocolProviderService.
*
* @param provider a reference to the <tt>ProtocolProviderService</tt>
* that we'd like to get a <tt>Contact</tt> for.
* @return a <tt>Contact</tt> encapsulated in this <tt>MetaContact</tt>
* and originating from the specified provider.
*/
public Contact getContactForProvider(ProtocolProviderService provider)
{
Iterator contactsIter = protoContacts.iterator();
while (contactsIter.hasNext())
{
Contact contact = (Contact)contactsIter.next();
if(contact.getProtocolProvider() == provider)
return contact;
}
return null;
}
/**
* Returns a <tt>java.util.Iterator</tt> over all protocol specific
* <tt>Contacts</tt> encapsulated by this <tt>MetaContact</tt>.
*
* @return a <tt>java.util.Ierator</tt> over all protocol specific
* <tt>Contact</tt>s that were registered as subcontacts for this
* <tt>MetaContact</tt>
*/
public Iterator getContacts()
{
return protoContacts.iterator();
}
/**
* Currently simply returns the first contact in the list of proto spec.
* contacts. We should do this more inteligently though and have it
* chose according to preconfigured preferences.
*
* @return the default <tt>Contact</tt> to use when communicating with
* this <tt>MetaContact</tt>
*/
public Contact getDefaultContact()
{
return (Contact)this.protoContacts.get(0);
}
/**
* Returns a String identifier (the actual contents is left to
* implementations) that uniquely represents this <tt>MetaContact</tt> in
* the containing <tt>MetaContactList</tt>
*
* @return a String uniquely identifying this meta contact.
*/
public String getMetaContactID()
{
return uid;
}
/**
* Returns a characteristic display name that can be used when including
* this <tt>MetaContact</tt> in user interface.
* @return a human readable String that represents this meta contact.
*/
public String getDisplayName()
{
return displayName;
}
/**
* Sets a name that can be used when displaying this contact in user
* interface components.
* @param displayName a human readable String representing this
* <tt>MetaContact</tt>
*/
void setDisplayName(String displayName)
{
this.displayName = displayName;
}
/**
* Adds the specified protocol specific contact to the list of contacts
* merged in this meta contact.
* @param contact the protocol specific Contact to add.
*/
void addProtoContact(Contact contact)
{
this.protoContacts.add(contact);
}
/**
* Removes the specified protocol specific contact from the contacts
* encapsulated in this <code>MetaContact</code>
*
* @param contact the contact to remove
*
* @return true if this <tt>MetaContact</tt> contained the specified
* contact and false otherwise.
*/
boolean removeProtoContact(Contact contact)
{
return this.protoContacts.remove(contact);
}
}

@ -0,0 +1,191 @@
package net.java.sip.communicator.impl.contactlist;
import java.util.*;
import net.java.sip.communicator.service.contactlist.*;
/**
* An implementation of the meta contact group that would only be used for the
* root meta contact group.
* @author Emil Ivov
*/
public class RootMetaContactGroupImpl
implements MetaContactGroup
{
/**
* All the subgroups that this group contains.
*/
private Vector subgroups = new Vector();
/**
* An empty list that we'll use to return an iterator over the
* (non-exising) contats in this group.
*/
private List dummyContacts = new LinkedList();
private static final String groupName = "RootMetaContactGroup";
/**
* Creates an instance of the root meta contact group.
*/
RootMetaContactGroupImpl()
{
}
/**
* Determines whether or not this group can contain subgroups.
*
* @return always <tt>true</tt> since this is the root contact group
* and in our imple it can only contain groups.
*/
public boolean canContainSubgroups()
{
return false;
}
/**
* Returns the number of <tt>MetaContact</tt>s that this group contains.
* <p>
* @return always 0 since this is the root contact group and in our impl it
* can only contain groups.
*/
public int countChildContacts()
{
return 0;
}
/**
* Returns the number of subgroups that this <tt>MetaContactGroup</tt>
* contains.
*
* @return an int indicating the number of subgroups in this group.
*/
public int countSubgroups()
{
return subgroups.size();
}
/**
* Returns a <tt>java.util.Iterator</tt> over the <tt>MetaContact</tt>s
* contained in this <tt>MetaContactGroup</tt>.
*
* @return a <tt>java.util.Iterator</tt> over an empty contacts list.
*/
public Iterator getChildContacts()
{
return dummyContacts.iterator();
}
/**
* Returns the contact with the specified identifier
*
* @param metaContactID a String identifier obtained through the
* <tt>MetaContact.getMetaContactID()</tt> method. <p>
* @return always null since this is the root contact group and in our impl
* it can only contain groups.
*/
public MetaContact getMetaContact(String metaContactID)
{
return null;
}
/**
* Returns the meta contact on the specified index.
*
* @param index the index of the meta contact to return.
* @return always null since this is the root contact group and in our impl
* it can only contain groups. <p>
*/
public MetaContact getMetaContact(int index)
{
return null;
}
/**
* Returns the <tt>MetaContactGroup</tt> with the specified index.
* <p>
* @param index the index of the group to return.
* @return the <tt>MetaContactGroup</tt> with the specified index. <p>
* @throws IndexOutOfBoundsException if <tt>index</tt> is not a valid
* index.
*/
public MetaContactGroup getMetaContactSubgroup(int index) throws
IndexOutOfBoundsException
{
return (MetaContactGroup)subgroups.get(index);
}
/**
* Returns the <tt>MetaContactGroup</tt> with the specified name.
*
* @param groupName the name of the group to return.
* @return the <tt>MetaContactGroup</tt> with the specified name or null
* if no such group exists.
*/
public MetaContactGroup getMetaContactSubgroup(String groupName)
{
Iterator groupsIter = getSubgroups();
while(groupsIter.hasNext())
{
MetaContactGroup mcGroup = (MetaContactGroup)groupsIter.next();
if(mcGroup.getGroupName().equals(groupName))
return mcGroup;
}
return null;
}
/**
* Returns an <tt>java.util.Iterator</tt> over the sub groups that this
* <tt>MetaContactGroup</tt> contains.
* <p>
* @return a <tt>java.util.Iterator</tt> containing all subgroups.
*/
public Iterator getSubgroups()
{
return subgroups.iterator();
}
/**
* Returns the name of this group.
* @return a String containing the name of this group.
*/
public String getGroupName()
{
return groupName;
}
/**
* Adds the specified meta group to the subgroups of this one.
* @param subgroup the MetaContactGroup to register as a subgroup to this
* root meta contact group.
*/
void addSubgroup(MetaContactGroup subgroup)
{
this.subgroups.add(subgroup);
}
/**
* Removes the meta contact group with the specified index.
* @param the <tt>index</tt> index of the group to remove.
* @return the <tt>MetaContactGroup</tt> that has just been removed.
*/
MetaContactGroupImpl removeSubgroup(int index)
{
return (MetaContactGroupImpl)subgroups.remove(index);
}
/**
* Removes the specified group from the list of groups in this list.
* @param group the <tt>MetaContactGroup</tt> to remove.
* @return true if the group has been successfully removed and false
* otherwise.
*/
boolean removeSubgroup(MetaContactGroup group)
{
return subgroups.remove(group);
}
}

@ -8,7 +8,7 @@
import net.java.sip.communicator.service.protocol.*;
import java.util.List;
import java.util.Iterator;
/**
* A MetaContact is an abstraction used for merging mutltiple Contacts (most
@ -30,13 +30,13 @@ public interface MetaContact
public Contact getDefaultContact();
/**
* Returns a <tt>java.util.List</tt> with all protocol specific
* Returns a <tt>java.util.Iterator</tt> with all protocol specific
* <tt>Contacts</tt> encapsulated by this <tt>MetaContact</tt>.
* @return a <tt>java.util.List</tt> containing all protocol specific
* @return a <tt>java.util.Iterator</tt> containing all protocol specific
* <tt>Contact</tt>s that were registered as subcontacts for this
* <tt>MetaContact</tt>
*/
public List getContacts();
public Iterator getContacts();
/**
* Returns the number of protocol speciic <tt>Contact</tt>s that this
@ -66,4 +66,11 @@ public interface MetaContact
* @return String
*/
public String getMetaContactID();
/**
* Returns a characteristic display name that can be used when including
* this <tt>MetaContact</tt> in user interface.
* @return a human readable String that represents this meta contact.
*/
public String getDisplayName();
}

@ -86,6 +86,12 @@ public interface MetaContactGroup
public MetaContact getMetaContact(int index)
throws IndexOutOfBoundsException;
/**
* Returns the name of this group.
* @return a String containing the name of this group.
*/
public String getGroupName();
/**
* Returns the <tt>MetaContactGroup</tt> with the specified name.
* @param groupName the name of the group to return.

Loading…
Cancel
Save