Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.service.contactsource
Class AsyncContactQuery<T extends ContactSourceService>

java.lang.Object
  extended by net.java.sip.communicator.service.contactsource.AbstractContactQuery<T>
      extended by net.java.sip.communicator.service.contactsource.AsyncContactQuery<T>
Type Parameters:
T - the very type of ContactSourceService which performs the ContactQuery
All Implemented Interfaces:
ContactQuery
Direct Known Subclasses:
GoogleContactsQuery, LdapContactQuery, MacOSXAddrBookContactQuery, MsOutlookAddrBookContactQuery

public abstract class AsyncContactQuery<T extends ContactSourceService>
extends AbstractContactQuery<T>

Provides an abstract implementation of a ContactQuery which runs in a separate Thread.

Author:
Lyubomir Marinov

Field Summary
protected  Pattern query
          The Pattern for which the associated ContactSourceService is being queried.
 
Fields inherited from interface net.java.sip.communicator.service.contactsource.ContactQuery
QUERY_CANCELED, QUERY_COMPLETED, QUERY_ERROR, QUERY_IN_PROGRESS
 
Constructor Summary
protected AsyncContactQuery(T contactSource, Pattern query)
          Initializes a new AsyncContactQuery instance which is to perform a specific query on behalf of a specific contactSource.
 
Method Summary
protected  boolean addQueryResult(SourceContact sourceContact)
          Adds a specific SourceContact to the list of SourceContacts to be returned by this ContactQuery in response to getQueryResults().
protected  String getPhoneNumberQuery()
          Gets the query of this AsyncContactQuery as a String which represents a phone number (if possible).
 int getQueryResultCount()
          Gets the number of SourceContacts which match this ContactQuery.
 List<SourceContact> getQueryResults()
          Gets the List of SourceContacts which match this ContactQuery.
 String getQueryString()
          Returns the query string, this query was created for.
protected abstract  String normalizePhoneNumber(String phoneNumber)
          Normalizes a String phone number by converting alpha characters to their respective digits on a keypad and then stripping non-digit characters.
protected abstract  boolean phoneNumberMatches(String phoneNumber)
          Determines whether a specific String phone number matches the query of this AsyncContactQuery.
protected abstract  void run()
          Performs this ContactQuery in a background Thread.
 void start()
          Starts this AsyncContactQuery.
protected  void stopped(boolean completed)
          Notifies this AsyncContactQuery that it has stopped performing in the associated background Thread.
 
Methods inherited from class net.java.sip.communicator.service.contactsource.AbstractContactQuery
addContactQueryListener, cancel, fireContactReceived, fireQueryStatusChanged, getContactSource, getStatus, removeContactQueryListener, setStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

query

protected final Pattern query
The Pattern for which the associated ContactSourceService is being queried.

Constructor Detail

AsyncContactQuery

protected AsyncContactQuery(T contactSource,
                            Pattern query)
Initializes a new AsyncContactQuery instance which is to perform a specific query on behalf of a specific contactSource.

Parameters:
contactSource - the ContactSourceService which is to perform the new ContactQuery instance
query - the Pattern for which contactSource is being queried
Method Detail

addQueryResult

protected boolean addQueryResult(SourceContact sourceContact)
Adds a specific SourceContact to the list of SourceContacts to be returned by this ContactQuery in response to getQueryResults().

Parameters:
sourceContact - the SourceContact to be added to the queryResults of this ContactQuery
Returns:
true if the queryResults of this ContactQuery has changed in response to the call

getPhoneNumberQuery

protected String getPhoneNumberQuery()
Gets the query of this AsyncContactQuery as a String which represents a phone number (if possible).

Returns:
a String which represents the query of this AsyncContactQuery as a phone number if such parsing, formatting and validation is possible; otherwise, null

getQueryResultCount

public int getQueryResultCount()
Gets the number of SourceContacts which match this ContactQuery.

Returns:
the number of SourceContact which match this ContactQuery

getQueryResults

public List<SourceContact> getQueryResults()
Gets the List of SourceContacts which match this ContactQuery.

Returns:
the List of SourceContacts which match this ContactQuery
See Also:
ContactQuery.getQueryResults()

getQueryString

public String getQueryString()
Returns the query string, this query was created for.

Returns:
the query string, this query was created for

normalizePhoneNumber

protected abstract String normalizePhoneNumber(String phoneNumber)
Normalizes a String phone number by converting alpha characters to their respective digits on a keypad and then stripping non-digit characters.

Parameters:
phoneNumber - a String which represents a phone number to normalize
Returns:
a String which is a normalized form of the specified phoneNumber

phoneNumberMatches

protected abstract boolean phoneNumberMatches(String phoneNumber)
Determines whether a specific String phone number matches the query of this AsyncContactQuery.

Parameters:
phoneNumber - the String which represents the phone number to match to the query of this AsyncContactQuery
Returns:
true if the specified phoneNumber matches the query of this AsyncContactQuery; otherwise, false

run

protected abstract void run()
Performs this ContactQuery in a background Thread.


start

public void start()
Starts this AsyncContactQuery.


stopped

protected void stopped(boolean completed)
Notifies this AsyncContactQuery that it has stopped performing in the associated background Thread.

Parameters:
completed - true if this ContactQuery has successfully completed, false if an error has been encountered during its execution

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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