Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.mock
Class MockContact

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.mock.MockContact
All Implemented Interfaces:
Contact

public class MockContact
extends Object
implements Contact

A simple, straightforward mock implementation of the Contact interface that can be manually created and used in testing a MetaContactList service

Author:
Emil Ivov

Constructor Summary
MockContact(String id, MockProvider parentProvider)
          Creates an instance of a meta contact with the specified string used as a name and identifier.
 
Method Summary
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one which in terms of contacts translates to having equal ids.
 String getAddress()
          Returns a String that can be used for identifying the contact.
 String getDisplayName()
          Returns a String that could be used by any user interacting modules for referring to this contact.
 byte[] getImage()
          Returns a byte array containing an image (most often a photo or an avatar) that the contact uses as a representation.
 ContactGroup getParentContactGroup()
          Returns the group that contains this contact.
 String getPersistentData()
          Returns null as no persistent data is required and the contact address is sufficient for restoring the contact.
 PresenceStatus getPresenceStatus()
          Returns the status of the contact.
 ProtocolProviderService getProtocolProvider()
          Returns a reference to the protocol provider that created the contact.
 String getStatusMessage()
          Return the current status message of this contact.
 boolean isLocal()
          Determines whether or not this contact represents our own identity.
 boolean isPersistent()
          Determines whether or not this contact is being stored by the server.
 boolean isResolved()
          Determines whether or not this contact has been resolved against the server.
 void setDisplayName(String displayName)
          Modify the display name of this contact.
(package private)  void setParentGroup(MockContactGroup newParentGroup)
          This method is only called when the contact is added to a new MockContactGroup by the MockContactGroup itself.
 void setPresenceStatus(MockStatusEnum mockPresenceStatus)
          Sets mockPresenceStatus as the PresenceStatus that this contact is currently in.
 void setResolved(boolean resolved)
          Makes the contact resolved or unresolved.
 String toString()
          Returns a string representation of this contact, containing most of its representative details.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockContact

public MockContact(String id,
                   MockProvider parentProvider)
Creates an instance of a meta contact with the specified string used as a name and identifier.

Parameters:
id - the identifier of this contact (also used as a name).
parentProvider - the provider that created us.
Method Detail

setParentGroup

void setParentGroup(MockContactGroup newParentGroup)
This method is only called when the contact is added to a new MockContactGroup by the MockContactGroup itself.

Parameters:
newParentGroup - the MockContactGroup that is now parent of this MockContact

getAddress

public String getAddress()
Returns a String that can be used for identifying the contact.

Specified by:
getAddress in interface Contact
Returns:
a String id representing and uniquely identifying the contact.

getDisplayName

public String getDisplayName()
Returns a String that could be used by any user interacting modules for referring to this contact.

Specified by:
getDisplayName in interface Contact
Returns:
a String that can be used for referring to this contact when interacting with the user.

setDisplayName

public void setDisplayName(String displayName)
Modify the display name of this contact.

Parameters:
displayName - the new display name for this contact.

getImage

public byte[] getImage()
Returns a byte array containing an image (most often a photo or an avatar) that the contact uses as a representation.

Specified by:
getImage in interface Contact
Returns:
byte[] an image representing the contact.

getPresenceStatus

public PresenceStatus getPresenceStatus()
Returns the status of the contact.

Specified by:
getPresenceStatus in interface Contact
Returns:
always IcqStatusEnum.ONLINE.

setPresenceStatus

public void setPresenceStatus(MockStatusEnum mockPresenceStatus)
Sets mockPresenceStatus as the PresenceStatus that this contact is currently in.

Parameters:
mockPresenceStatus - the MockPresenceStatus currently valid for this contact.

getProtocolProvider

public ProtocolProviderService getProtocolProvider()
Returns a reference to the protocol provider that created the contact.

Specified by:
getProtocolProvider in interface Contact
Returns:
a refererence to an instance of the ProtocolProviderService

isLocal

public boolean isLocal()
Determines whether or not this contact represents our own identity.

Returns:
true in case this is a contact that represents ourselves and false otherwise.

getParentContactGroup

public ContactGroup getParentContactGroup()
Returns the group that contains this contact.

Specified by:
getParentContactGroup in interface Contact
Returns:
a reference to the MockContactGroup that contains this contact.

toString

public String toString()
Returns a string representation of this contact, containing most of its representative details.

Overrides:
toString in class Object
Returns:
a string representation of this contact.

isPersistent

public boolean isPersistent()
Determines whether or not this contact is being stored by the server. Non persistent contacts are common in the case of simple, non-persistent presence operation sets. They could however also be seen in persistent presence operation sets when for example we have received an event from someone not on our contact list. Non persistent contacts are volatile even when coming from a persistent presence op. set. They would only exist until the application is closed and will not be there next time it is loaded.

Specified by:
isPersistent in interface Contact
Returns:
true if the contact 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.

Specified by:
getPersistentData in interface Contact
Returns:
null as no such data is needed.

isResolved

public boolean isResolved()
Determines whether or not this contact has been resolved against the server. Unresolved contacts 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 to their on-line buddies.

Specified by:
isResolved in interface Contact
Returns:
true if the contact has been resolved (mapped against a buddy) and false otherwise.

setResolved

public void setResolved(boolean resolved)
Makes the contact resolved or unresolved.

Parameters:
resolved - true to make the contact resolved; false to make it unresolved

equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one which in terms of contacts translates to having equal ids. The resolved status of the contacts deliberately ignored so that contacts would be declared equal even if it differs.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this contact has the same id as that of the obj argument.

getStatusMessage

public String getStatusMessage()
Return the current status message of this contact.

Specified by:
getStatusMessage in interface Contact
Returns:
null as the protocol has currently no support of status messages

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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