Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.jabber
Class ContactGroupJabberImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.jabber.AbstractContactGroupJabberImpl
      extended by net.java.sip.communicator.impl.protocol.jabber.ContactGroupJabberImpl
All Implemented Interfaces:
ContactGroup
Direct Known Subclasses:
VolatileContactGroupJabberImpl

public class ContactGroupJabberImpl
extends AbstractContactGroupJabberImpl

The Jabber implementation of the ContactGroup interface. Instances of this class (contrary to RootContactGroupJabberImpl) may only contain buddies and cannot have sub groups. Note that instances of this class only use the corresponding smack source group for reading their names and only initially fill their buddies java.util.List with the ContactJabberImpl objects corresponding to those contained in the source group at the moment it is being created. They would, however, never try to sync or update their contents ulteriorly. This would have to be done through the addContact()/removeContact() methods. The content of buddies is created on creating of the group and when the smack source group is changed.

Author:
Damian Minkov, Emil Ivov

Constructor Summary
ContactGroupJabberImpl(org.jivesoftware.smack.RosterGroup rosterGroup, Iterator<org.jivesoftware.smack.RosterEntry> groupMembers, ServerStoredContactListJabberImpl ssclCallback, boolean isResolved)
          Creates an Jabber group using the specified RosterGroup as a source.
ContactGroupJabberImpl(String id, ServerStoredContactListJabberImpl ssclCallback)
          Used when creating unresolved groups.
 
Method Summary
(package private)  void addContact(ContactJabberImpl contact)
          Adds the specified contact to the end of this group.
 boolean canContainSubgroups()
          Determines whether the group may contain subgroups or not.
 Iterator<Contact> contacts()
          Returns an Iterator over all contacts, member of this ContactGroup.
 int countContacts()
          Returns the number of Contact members of this ContactGroup
 int countSubgroups()
          Returns the number of subgroups contained by this group, which is always 0 since sub groups in the protocol may only be contained by the root group - RootContactGroupImpl.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this group.
(package private)  ContactJabberImpl findContact(String id)
          Returns the contact encapsulating with the spcieified name or null if no such contact was found.
 Contact getContact(String id)
          Returns the Contact with the specified address or identifier.
 ContactGroup getGroup(int index)
          Returns the subgroup with the specified index (i.e.
 ContactGroup getGroup(String groupName)
          Returns the subgroup with the specified name.
 String getGroupName()
          Returns the name of this group.
(package private)  String getNameCopy()
          Returns the name of the group as it was at the last call of initNameCopy.
 ContactGroup getParentContactGroup()
          Returns a reference to the root group which in Jabber is the parent of any other group since the protocol does not support subgroups.
 String getPersistentData()
          Returns null as no persistent data is required and the contact address is sufficient for restoring the contact.
 ProtocolProviderService getProtocolProvider()
          Returns the protocol provider that this group belongs to.
(package private)  org.jivesoftware.smack.RosterGroup getSourceGroup()
          The source group we are encapsulating
 String getUID()
          Returns a String that uniquely represents the group.
 int hashCode()
          Returns a hash code value for the object, which is actually the hashcode value of the groupname.
 boolean isPersistent()
          Determines whether or not this contact group is being stored by the server.
 boolean isResolved()
          Determines whether or not this contact group has been resolved against the server.
(package private)  void removeContact(ContactJabberImpl contact)
          Removes the specified contact from this contact group
(package private)  void setNameCopy(String newName)
          Sets the name copy field that we use as a means of detecting changes in the group name.
(package private)  void setResolved(org.jivesoftware.smack.RosterGroup source)
          Resolve this contact group against the specified group
(package private)  void setSourceGroup(org.jivesoftware.smack.RosterGroup newGroup)
          Change the source group, used when renaming groups.
 Iterator<ContactGroup> subgroups()
          Returns an empty iterator.
 String toString()
          Returns a string representation of this group, in the form JabberGroup.GroupName[size]{ buddy1.toString(), buddy2.toString(), ...}.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ContactGroupJabberImpl

ContactGroupJabberImpl(org.jivesoftware.smack.RosterGroup rosterGroup,
                       Iterator<org.jivesoftware.smack.RosterEntry> groupMembers,
                       ServerStoredContactListJabberImpl ssclCallback,
                       boolean isResolved)
Creates an Jabber group using the specified RosterGroup as a source. The newly created group will always return the name of the underlying RosterGroup and would thus automatically adapt to changes. It would, however, not receive or try to poll for modifications of the buddies it contains and would therefore have to be updated manually by ServerStoredContactListImpl update will only be done if source group is changed.

Parameters:
rosterGroup - the Jabber Group corresponding to the group
groupMembers - the group members that we should add to the group.
ssclCallback - a callback to the server stored contact list we're creating.
isResolved - a boolean indicating whether or not the group has been resolved against the server.

ContactGroupJabberImpl

ContactGroupJabberImpl(String id,
                       ServerStoredContactListJabberImpl ssclCallback)
Used when creating unresolved groups.

Parameters:
id - the id of the group.
ssclCallback - the contact list handler that created us.
Method Detail

countContacts

public int countContacts()
Returns the number of Contact members of this ContactGroup

Returns:
an int indicating the number of Contacts, members of this ContactGroup.

getParentContactGroup

public ContactGroup getParentContactGroup()
Returns a reference to the root group which in Jabber is the parent of any other group since the protocol does not support subgroups.

Returns:
a reference to the root group.

addContact

void addContact(ContactJabberImpl contact)
Adds the specified contact to the end of this group.

Parameters:
contact - the new contact to add to this group

removeContact

void removeContact(ContactJabberImpl contact)
Removes the specified contact from this contact group

Parameters:
contact - the contact to remove.

contacts

public Iterator<Contact> contacts()
Returns an Iterator over all contacts, member of this ContactGroup.

Returns:
a java.util.Iterator over all contacts inside this ContactGroup. In case the group doesn't contain any members it will return an empty iterator.

getContact

public Contact getContact(String id)
Returns the Contact with the specified address or identifier.

Parameters:
id - the address or identifier of the Contact we are looking for.
Returns:
the Contact with the specified id or address.

getGroupName

public String getGroupName()
Returns the name of this group.

Returns:
a String containing the name of this group.

canContainSubgroups

public boolean canContainSubgroups()
Determines whether the group may contain subgroups or not.

Returns:
always false since only the root group may contain subgroups.

getGroup

public ContactGroup getGroup(int index)
Returns the subgroup with the specified index (i.e. always null since this group may not contain subgroups).

Parameters:
index - the index of the ContactGroup to retrieve.
Returns:
always null

getGroup

public ContactGroup getGroup(String groupName)
Returns the subgroup with the specified name.

Parameters:
groupName - the name of the ContactGroup to retrieve.
Returns:
the ContactGroup with the specified index.

subgroups

public Iterator<ContactGroup> subgroups()
Returns an empty iterator. Subgroups may only be present in the root group.

Returns:
an empty iterator

countSubgroups

public int countSubgroups()
Returns the number of subgroups contained by this group, which is always 0 since sub groups in the protocol may only be contained by the root group - RootContactGroupImpl.

Returns:
a 0 int.

hashCode

public int hashCode()
Returns a hash code value for the object, which is actually the hashcode value of the groupname.

Overrides:
hashCode in class Object
Returns:
a hash code value for this ContactGroup.

equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this group.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

getProtocolProvider

public ProtocolProviderService getProtocolProvider()
Returns the protocol provider that this group belongs to.

Returns:
a reference to the ProtocolProviderService instance that this ContactGroup belongs to.

toString

public String toString()
Returns a string representation of this group, in the form JabberGroup.GroupName[size]{ buddy1.toString(), buddy2.toString(), ...}.

Overrides:
toString in class Object
Returns:
a String representation of the object.

findContact

ContactJabberImpl findContact(String id)
Returns the contact encapsulating with the spcieified name or null if no such contact was found.

Parameters:
id - the id for the contact we're looking for.
Returns:
the ContactJabberImpl corresponding to the specified screnname or null if no such contact existed.

setNameCopy

void setNameCopy(String newName)
Sets the name copy field that we use as a means of detecting changes in the group name.

Parameters:
newName - String

getNameCopy

String getNameCopy()
Returns the name of the group as it was at the last call of initNameCopy.

Returns:
a String containing a copy of the name of this group as it was last time when we called initNameCopy.

isPersistent

public boolean isPersistent()
Determines whether or not this contact group is being stored by the server. Non persistent contact groups exist for the sole purpose of containing non persistent contacts.

Returns:
true if the contact group is persistent and false otherwise.

getPersistentData

public String getPersistentData()
Returns null as no persistent data is required and the contact address is sufficient for restoring the contact.

Returns:
null as no such data is needed.

isResolved

public boolean isResolved()
Determines whether or not this contact group has been resolved against the server. Unresolved group are used when initially loading a contact list that has been stored in a local file until the presence operation set has managed to retrieve all the contact list from the server and has properly mapped contacts and groups to their corresponding on-line buddies.

Returns:
true if the contact has been resolved (mapped against a buddy) and false otherwise.

setResolved

void setResolved(org.jivesoftware.smack.RosterGroup source)
Resolve this contact group against the specified group

Parameters:
source - the server stored group

getUID

public String getUID()
Returns a String that uniquely represents the group. In this we use the name of the group as an identifier. This may cause problems though, in case the name is changed by some other application between consecutive runs of the sip-communicator.

Returns:
a String representing this group in a unique and persistent way.

getSourceGroup

org.jivesoftware.smack.RosterGroup getSourceGroup()
The source group we are encapsulating

Returns:
RosterGroup

setSourceGroup

void setSourceGroup(org.jivesoftware.smack.RosterGroup newGroup)
Change the source group, used when renaming groups.

Parameters:
newGroup - RosterGroup

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.