Adds a missing return and removes a few instance fields in the contact list UI, spares a few allocations in the history.

cusax-fix
Lyubomir Marinov 15 years ago
parent ee06f7d446
commit e314c85e74

@ -18,7 +18,8 @@
*
* @author Yana Stamcheva
*/
public class CallHistoryContactSource implements ContactSourceService
public class CallHistoryContactSource
implements ContactSourceService
{
/**
* The display name of this contact source.
@ -252,10 +253,10 @@ private void fireQueryEvent(SourceContact contact)
*/
private void fireQueryStatusEvent(int newStatus)
{
Collection<ContactQueryListener> listeners;
ContactQueryStatusEvent event
= new ContactQueryStatusEvent(this, newStatus);
Collection<ContactQueryListener> listeners;
synchronized (queryListeners)
{
listeners

@ -131,9 +131,7 @@ private void fireQueryEvent(CallRecord record)
synchronized (queryListeners)
{
for (CallHistoryQueryListener l : queryListeners)
{
l.callRecordReceived(event);
}
}
}
@ -150,9 +148,7 @@ private void fireQueryStatusEvent(int newStatus)
synchronized (queryListeners)
{
for (CallHistoryQueryListener l : queryListeners)
{
l.queryStatusChanged(event);
}
}
}

@ -303,7 +303,6 @@ public CallHistoryQuery findByPeer(String address, int recordCount)
History history = this.getHistory(null, null);
InteractiveHistoryReader historyReader
= history.getInteractiveReader();
HistoryQuery historyQuery
= historyReader.findByKeyword(
address, "callParticipantIDs", recordCount);

@ -80,14 +80,12 @@ public boolean isMatching(UIContact uiContact)
{
SourceContact sourceContact = (SourceContact) descriptor;
if ((sourceContact.getContactSource().getIdentifier()
.equals(ContactSourceService.CALL_HISTORY)))
if (sourceContact.getContactSource().getIdentifier()
.equals(ContactSourceService.CALL_HISTORY))
return true;
}
else if (uiContact instanceof NotificationContact)
{
return true;
}
return false;
}
@ -100,12 +98,7 @@ else if (uiContact instanceof NotificationContact)
*/
public boolean isMatching(UIGroup uiGroup)
{
if (uiGroup instanceof NotificationGroup)
{
return true;
}
return false;
return (uiGroup instanceof NotificationGroup);
}
/**
@ -122,11 +115,11 @@ private void addMatching( List<SourceContact> sourceContacts,
while (contactsIter.hasNext())
{
GuiActivator.getContactList()
.addContact(uiSource.createUIContact(contactsIter.next()),
uiSource.getUIGroup(),
false,
true);
GuiActivator.getContactList().addContact(
uiSource.createUIContact(contactsIter.next()),
uiSource.getUIGroup(),
false,
true);
}
}

@ -72,6 +72,7 @@ public ContactNode findFirstContactNode()
public void clear()
{
if (!SwingUtilities.isEventDispatchThread())
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
@ -90,6 +91,8 @@ public void run()
{
e.printStackTrace();
}
return;
}
// The following code is always invoked in the swing thread.
int childCount = rootGroupNode.getChildCount();
@ -153,7 +156,7 @@ private ContactNode findFirstContactNode(GroupNode parentNode)
/**
* The <tt>RootUIGroup</tt> is the root group in this contact list model.
*/
private class RootUIGroup
private static class RootUIGroup
implements UIGroup
{
/**

@ -21,7 +21,7 @@ public class ContactNode
/**
* The <tt>UIContact</tt> corresponding to this contact node.
*/
private UIContact contact;
private final UIContact contact;
/**
* Indicates if this node is currently active. Has unread messages waiting.

@ -53,9 +53,9 @@ public class FilterQuery
/**
* The list of filter queries.
*/
private Map<Object, List<SourceContact>> filterQueries
= Collections.synchronizedMap(new Hashtable<Object,
List<SourceContact>>());
private final Map<Object, List<SourceContact>> filterQueries
= Collections.synchronizedMap(
new Hashtable<Object, List<SourceContact>>());
/**
* Indicates the number of running queries.
@ -94,9 +94,7 @@ public void addContactQuery(Object contactQuery)
externalQuery.addContactQueryListener(this);
}
else if (contactQuery instanceof MetaContactQuery)
{
((MetaContactQuery) contactQuery).addContactQueryListener(this);
}
filterQueries.put(contactQuery, queryResults);
runningQueries++;
@ -139,16 +137,14 @@ public boolean isCanceled()
*/
public void cancel()
{
Iterator<Object> queriesIter;
synchronized(filterQueries)
{
isCanceled = true;
queriesIter = filterQueries.keySet().iterator();
Iterator<Object> queriesIter = filterQueries.keySet().iterator();
while (queriesIter.hasNext())
{
cancelQuery(queriesIter.next());
}
}
}
@ -198,7 +194,7 @@ public void queryStatusChanged(ContactQueryStatusEvent event)
// Check if this query is in our filter queries list.
if (!filterQueries.containsKey(query)
|| event.getEventType() == ContactQuery.QUERY_IN_PROGRESS)
|| event.getEventType() == ContactQuery.QUERY_IN_PROGRESS)
return;
removeQuery(query);
@ -263,7 +259,7 @@ private void cancelQuery(Object query)
{
if (query instanceof ContactQuery)
{
ContactQuery contactQuery = ((ContactQuery) query);
ContactQuery contactQuery = (ContactQuery) query;
contactQuery.cancel();
contactQuery.removeContactQueryListener(
GuiActivator.getContactList());
@ -272,7 +268,7 @@ private void cancelQuery(Object query)
}
else if (query instanceof MetaContactQuery)
{
MetaContactQuery metaContactQuery = ((MetaContactQuery) query);
MetaContactQuery metaContactQuery = (MetaContactQuery) query;
metaContactQuery.cancel();
metaContactQuery.removeContactQueryListener(
GuiActivator.getContactList());

@ -9,6 +9,7 @@
import java.util.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.tree.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
@ -25,9 +26,10 @@ public class GroupNode
implements ContactListNode
{
/**
* The Group node logger.
* The <tt>Logger</tt> used by the <tt>GroupNode</tt> class and its
* instances for logging output.
*/
private final Logger logger = Logger.getLogger(GroupNode.class);
private static final Logger logger = Logger.getLogger(GroupNode.class);
/**
* The parent contact list model.
@ -40,9 +42,15 @@ public class GroupNode
private final UIGroup group;
/**
* A node comparator used to sort the list of children.
* The <tt>ContactListNode</tt> <tt>Comparator</tt> used to sort the list of
* children.
* <p>
* Since the <tt>NodeComparator</tt> class is static, it makes sense to not
* have it instantiated per <tt>GroupNode</tt> instance but rather share one
* and the same between all of them.
* </p>
*/
private final NodeComparator nodeComparator = new NodeComparator();
private static final NodeComparator nodeComparator = new NodeComparator();
/**
* Indicates if this group node is collapsed or expanded.
@ -296,7 +304,9 @@ public boolean isCollapsed()
*/
public void clear()
{
for (int i = 0; i < getChildCount(); i ++)
int childCount = getChildCount();
for (int i = 0; i < childCount; i ++)
{
TreeNode treeNode = getChildAt(i);
@ -324,9 +334,7 @@ else if (treeNode instanceof GroupNode)
*/
private void fireNodeInserted(int index)
{
int[] newIndexs = new int[1];
newIndexs[0] = index;
treeModel.nodesWereInserted(this, newIndexs);
treeModel.nodesWereInserted(this, new int[]{index});
}
/**
@ -337,29 +345,29 @@ private void fireNodeInserted(int index)
*/
private void fireNodeRemoved(ContactListNode node, int index)
{
int[] removedIndexs = new int[1];
removedIndexs[0] = index;
treeModel.nodesWereRemoved(this, removedIndexs, new Object[]{node});
treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{node});
}
/**
* Notifies all interested listeners that all nodes has changed.
* Notifies all interested listeners that all nodes have changed.
*/
private void fireNodesChanged()
{
int childCount = getChildCount();
int[] changedIndexs = new int[childCount];
int[] changedIndexes = new int[childCount];
for (int i = 0; i < childCount; i++)
changedIndexs[i] = i;
changedIndexes[i] = i;
treeModel.nodesChanged(this, changedIndexs);
treeModel.nodesChanged(this, changedIndexes);
}
/**
* Note: this comparator imposes orderings that are inconsistent with
* equals.
*/
private class NodeComparator implements Comparator<ContactListNode>
private static class NodeComparator
implements Comparator<ContactListNode>
{
/**
* Compares its two arguments for order. Returns a negative integer,
@ -373,21 +381,25 @@ private class NodeComparator implements Comparator<ContactListNode>
*/
public int compare(ContactListNode node1, ContactListNode node2)
{
int index1 = node1.getSourceIndex();
int index2 = node2.getSourceIndex();
// Child groups are shown after child contacts.
if (node1 instanceof GroupNode && node2 instanceof ContactNode)
return 1;
if (node1 instanceof GroupNode)
{
if (node2 instanceof ContactNode)
return 1;
}
else if (node1 instanceof ContactNode)
{
if (node2 instanceof GroupNode)
return -1;
}
if (node1 instanceof ContactNode && node2 instanceof GroupNode)
return -1;
int index1 = node1.getSourceIndex();
int index2 = node2.getSourceIndex();
// If the first index is unknown then we position it to the end.
// If the first index is unknown then we position it at the end.
if (index1 < 0)
return 1;
// If the second index is unknown then we position it to the end.
// If the second index is unknown then we position it at the end.
if (index2 < 0)
return -1;
@ -405,14 +417,11 @@ public int compare(ContactListNode node1, ContactListNode node2)
private int getLeadSelectionRow()
{
JTree tree = treeModel.getParentTree();
int[] rows = tree.getSelectionRows();
int selectedRow = -1;
if (rows != null && rows.length > 0)
{
if ((rows != null) && (rows.length != 0))
selectedRow = rows[0];
}
return selectedRow;
}
@ -436,15 +445,15 @@ private TreePath getLeadSelectionPath()
private void refreshSelection(int lastSelectedIndex, int newSelectedIndex)
{
JTree tree = treeModel.getParentTree();
TreeUI treeUI = tree.getUI();
TreePath oldSelectionPath = tree.getPathForRow(lastSelectedIndex);
TreePath newSelectionPath = tree.getPathForRow(newSelectedIndex);
if (tree.getUI() instanceof SIPCommTreeUI)
if (treeUI instanceof SIPCommTreeUI)
{
SIPCommTreeUI treeUI = (SIPCommTreeUI) tree.getUI();
SIPCommTreeUI sipCommTreeUI = (SIPCommTreeUI) treeUI;
TreePath oldSelectionPath = tree.getPathForRow(lastSelectedIndex);
TreePath newSelectionPath = tree.getPathForRow(newSelectedIndex);
treeUI.selectionChanged(oldSelectionPath, newSelectionPath);
sipCommTreeUI.selectionChanged(oldSelectionPath, newSelectionPath);
}
}
}

@ -146,10 +146,13 @@ public boolean isMatching(UIContact uiContact)
{
Iterator<String> searchStrings = uiContact.getSearchStrings();
while (searchStrings != null && searchStrings.hasNext())
if (searchStrings != null)
{
if (isMatching(searchStrings.next()))
return true;
while (searchStrings.hasNext())
{
if (isMatching(searchStrings.next()))
return true;
}
}
return false;
}
@ -210,36 +213,29 @@ private boolean isMatching(SourceContact contact)
*/
private boolean isMatching(String text)
{
Matcher matcher = filterPattern.matcher(text);
if(matcher.find())
return true;
return false;
return filterPattern.matcher(text).find();
}
/**
* Adds the list of <tt>sourceContacts</tt> to the contact list.
* @param sourceContacts the list of <tt>SourceContact</tt>s to add
*/
private void addMatching( List<SourceContact> sourceContacts)
private void addMatching(List<SourceContact> sourceContacts)
{
Iterator<SourceContact> contactsIter = sourceContacts.iterator();
while (contactsIter.hasNext())
{
addSourceContact(contactsIter.next());
}
}
/**
* Adds the given <tt>sourceContact</tt> to the contact list.
* @param sourceContact the <tt>SourceContact</tt> to add
*/
private void addSourceContact( SourceContact sourceContact)
private void addSourceContact(SourceContact sourceContact)
{
ContactSourceService contactSource
= sourceContact.getContactSource();
ExternalContactSource sourceUI
= TreeContactList.getContactSource(contactSource);
@ -272,13 +268,12 @@ public void setSearchSourceType(int searchSourceType)
break;
case HISTORY_SOURCE:
{
Collection<ExternalContactSource> historySources
= new LinkedList<ExternalContactSource>();
ExternalContactSource historySource
= TreeContactList.getContactSource(
ContactSourceService.CALL_HISTORY);
Collection<ExternalContactSource> historySources
= new LinkedList<ExternalContactSource>();
historySources.add(historySource);
contactSources = historySources;
break;
@ -296,7 +291,6 @@ public Collection<ExternalContactSource> getContactSources()
{
if (contactSources == null)
contactSources = TreeContactList.getContactSources();
return contactSources;
}

@ -73,13 +73,13 @@ public class TreeContactList
* these contacts with a special icon.
*/
private final java.util.List<ContactNode> activeContacts
= new Vector<ContactNode>();
= new ArrayList<ContactNode>();
/**
* A list of all registered <tt>ContactListListener</tt>-s.
*/
private final java.util.List<ContactListListener> contactListListeners
= new Vector<ContactListListener>();
= new ArrayList<ContactListListener>();
/**
* The presence filter.
@ -171,16 +171,12 @@ public TreeContactList()
public void childContactsReordered(MetaContactGroupEvent evt)
{
MetaContactGroup metaGroup = evt.getSourceMetaContactGroup();
UIGroup uiGroup;
UIGroup uiGroup = null;
if (!MetaContactListSource.isRootGroup(metaGroup))
{
uiGroup = MetaContactListSource.getUIGroup(metaGroup);
}
else
{
if (MetaContactListSource.isRootGroup(metaGroup))
uiGroup = treeModel.getRoot().getGroupDescriptor();
}
else
uiGroup = MetaContactListSource.getUIGroup(metaGroup);
if (uiGroup != null)
{
@ -328,15 +324,12 @@ public void metaContactMoved(final MetaContactMovedEvent evt)
if (uiContact == null)
return;
UIGroup oldUIGroup = null;
if (!MetaContactListSource.isRootGroup(oldParent))
{
oldUIGroup = MetaContactListSource.getUIGroup(oldParent);
}
else
{
UIGroup oldUIGroup;
if (MetaContactListSource.isRootGroup(oldParent))
oldUIGroup = treeModel.getRoot().getGroupDescriptor();
}
else
oldUIGroup = MetaContactListSource.getUIGroup(oldParent);
if (oldUIGroup != null)
removeContact(uiContact);
@ -729,9 +722,7 @@ public boolean isContactActive(UIContact contact)
{
ContactNode contactNode = contact.getContactNode();
if (contactNode != null)
return contactNode.isActive();
return false;
return (contactNode == null) ? false : contactNode.isActive();
}
/**
@ -775,9 +766,7 @@ public void run()
if (isGroupSorted)
groupNode = parentNode.sortedAddContactGroup(group);
else
{
groupNode = parentNode.addContactGroup(group);
}
}
}
@ -789,7 +778,7 @@ public void run()
groupNode.addContact(contact);
if ((!currentFilter.equals(presenceFilter)
|| !groupNode.isCollapsed()))
|| !groupNode.isCollapsed()))
this.expandGroup(groupNode);
else
this.expandGroup(treeModel.getRoot());
@ -854,7 +843,7 @@ public void run()
// If in the meantime the filter has changed we don't
// add the contact.
if (query != null
&& currentFilterQuery.containsQuery(query))
&& currentFilterQuery.containsQuery(query))
{
addContact(contact, group, isSorted, true);
}
@ -1243,7 +1232,6 @@ public void fireContactListEvent(Object source, int eventID, int clickCount)
fireContactListEvent(
new Vector<ContactListListener>(contactListListeners),
evt);
return;
}
}
}
@ -1478,9 +1466,7 @@ private void openRightButtonMenu(Point contactListPoint)
SwingUtilities.convertPointToScreen(contactListPoint, this);
rightButtonMenu.setInvoker(this);
rightButtonMenu.setLocation(contactListPoint.x, contactListPoint.y);
rightButtonMenu.setVisible(true);
}
@ -1500,7 +1486,7 @@ public void treeCollapsed(TreeExpansionEvent event)
// For now we only save the group state only if we're in presence
// filter mode.
if (collapsedNode instanceof GroupNode
&& currentFilter.equals(presenceFilter))
&& currentFilter.equals(presenceFilter))
{
GroupNode groupNode = (GroupNode) collapsedNode;
String id = groupNode.getGroupDescriptor().getId();
@ -1522,7 +1508,7 @@ public void treeExpanded(TreeExpansionEvent event)
// For now we only save the group state only if we're in presence
// filter mode.
if (collapsedNode instanceof GroupNode
&& currentFilter.equals(presenceFilter))
&& currentFilter.equals(presenceFilter))
{
GroupNode groupNode = (GroupNode) collapsedNode;
String id = groupNode.getGroupDescriptor().getId();
@ -1794,7 +1780,6 @@ public static NotificationContactSource getNotificationContactSource()
{
if (notificationSource == null)
notificationSource = new NotificationContactSource();
return notificationSource;
}
@ -1954,7 +1939,7 @@ public void contactReceived(ContactReceivedEvent event)
// If we find that the contact is actually a number, we get rid of the
// @ if it exists.
if (atIndex >= 0
&& StringUtils.isNumber(contactString.substring(0, atIndex)))
&& StringUtils.isNumber(contactString.substring(0, atIndex)))
{
setSourceContactImage( contactString.substring(0, atIndex),
label, imgWidth, imgHeight);
@ -1972,9 +1957,7 @@ private static void cancelImageQueries(
Iterator<ContactQuery> queriesIter = loadedQueries.iterator();
while (queriesIter.hasNext())
{
queriesIter.next().cancel();
}
}
/**
@ -2071,8 +2054,8 @@ public static void showAddContactDialog(ContactDetail contactDetail)
ProtocolProviderService preferredProvider = null;
List<Class<? extends OperationSet>> opSetClasses
= contactDetail.getSupportedOperationSets();
if (opSetClasses != null
&& opSetClasses.size() > 0)
if (opSetClasses != null && opSetClasses.size() > 0)
{
preferredProvider
= contactDetail.getPreferredProtocolProvider(
@ -2089,7 +2072,7 @@ public static void showAddContactDialog(ContactDetail contactDetail)
* Listens for adding and removing of <tt>ContactSourceService</tt>
* implementations.
*/
private class ContactSourceServiceListener
private static class ContactSourceServiceListener
implements ServiceListener
{
public void serviceChanged(ServiceEvent event)
@ -2134,13 +2117,15 @@ public void serviceChanged(ServiceEvent event)
public void contactPresenceStatusChanged(
final ContactPresenceStatusChangeEvent evt)
{
final Contact sourceContact = evt.getSourceContact();
if (evt.getOldStatus() == evt.getNewStatus())
return;
final MetaContact metaContact = GuiActivator.getContactListService()
.findMetaContactByContact(sourceContact);
final Contact sourceContact = evt.getSourceContact();
final MetaContact metaContact
= GuiActivator.getContactListService().findMetaContactByContact(
sourceContact);
if (metaContact == null
|| (evt.getOldStatus() == evt.getNewStatus()))
if (metaContact == null)
return;
UIContact uiContact
@ -2148,8 +2133,7 @@ public void contactPresenceStatusChanged(
if (uiContact == null)
{
uiContact = MetaContactListSource
.createUIContact(metaContact);
uiContact = MetaContactListSource.createUIContact(metaContact);
if (currentFilter != null && currentFilter.isMatching(uiContact))
{
@ -2159,12 +2143,11 @@ public void contactPresenceStatusChanged(
UIGroup uiGroup = null;
if (!MetaContactListSource.isRootGroup(parentGroup))
{
uiGroup = MetaContactListSource
.getUIGroup(parentGroup);
uiGroup = MetaContactListSource.getUIGroup(parentGroup);
if (uiGroup == null)
uiGroup = MetaContactListSource
.createUIGroup(parentGroup);
uiGroup
= MetaContactListSource.createUIGroup(parentGroup);
}
if (logger.isDebugEnabled())
@ -2173,8 +2156,7 @@ public void contactPresenceStatusChanged(
addContact(uiContact, uiGroup, true, true);
}
else
MetaContactListSource
.removeUIContact(metaContact);
MetaContactListSource.removeUIContact(metaContact);
}
else
{
@ -2195,7 +2177,8 @@ public void contactPresenceStatusChanged(
* <tt>RenameAction</tt> is invoked when user presses the F2 key. Depending
* on the selection opens the appropriate form for renaming.
*/
private class RenameAction extends AbstractAction
private class RenameAction
extends AbstractAction
{
private static final long serialVersionUID = 0L;
@ -2216,13 +2199,12 @@ public void actionPerformed(ActionEvent e)
RenameContactDialog dialog = new RenameContactDialog(
GuiActivator.getUIService().getMainFrame(),
(MetaContact) metaUIContact.getDescriptor());
Dimension screenSize
= Toolkit.getDefaultToolkit().getScreenSize();
dialog.setLocation(
Toolkit.getDefaultToolkit().getScreenSize().width/2
- 200,
Toolkit.getDefaultToolkit().getScreenSize().height/2
- 50
);
screenSize.width/2 - 200,
screenSize.height/2 - 50);
dialog.setVisible(true);

@ -142,22 +142,16 @@ public HistoryReader getReader()
*/
public InteractiveHistoryReader getInteractiveReader()
{
if (this.interactiveReader == null)
{
this.interactiveReader = new InteractiveHistoryReaderImpl(this);
}
return this.interactiveReader;
if (interactiveReader == null)
interactiveReader = new InteractiveHistoryReaderImpl(this);
return interactiveReader;
}
public HistoryWriter getWriter()
{
if (this.writer == null)
{
this.writer = new HistoryWriterImpl(this);
}
return this.writer;
if (writer == null)
writer = new HistoryWriterImpl(this);
return writer;
}
protected HistoryServiceImpl getHistoryServiceImpl()

@ -204,7 +204,7 @@ public synchronized QueryResultSet<HistoryRecord> findLast(int count) throws Run
String ts = node.getAttributes().getNamedItem("timestamp")
.getNodeValue();
Date timestamp = new Date(Long.parseLong(ts));
long timestamp = Long.parseLong(ts);
ArrayList<String> nameVals = new ArrayList<String>();
@ -352,7 +352,7 @@ public QueryResultSet<HistoryRecord> findFirstRecordsAfter(Date date, int count)
String ts = node.getAttributes().getNamedItem("timestamp")
.getNodeValue();
Date timestamp = new Date(Long.parseLong(ts));
long timestamp = Long.parseLong(ts);
if(!isInPeriod(timestamp, date, null))
continue;
@ -446,7 +446,7 @@ public QueryResultSet<HistoryRecord> findLastRecordsBefore(Date date, int count)
String ts = node.getAttributes().getNamedItem("timestamp")
.getNodeValue();
Date timestamp = new Date(Long.parseLong(ts));
long timestamp = Long.parseLong(ts);
if(!isInPeriod(timestamp, null, date))
continue;
@ -547,8 +547,7 @@ private QueryResultSet<HistoryRecord> find(
String ts = node.getAttributes().getNamedItem("timestamp")
.getNodeValue();
Date timestamp = new Date(Long.parseLong(ts));
long timestamp = Long.parseLong(ts);
if(isInPeriod(timestamp, startDate, endDate))
{
@ -590,21 +589,23 @@ private QueryResultSet<HistoryRecord> find(
* @param endDate Date the end of the period
* @return boolean
*/
static boolean isInPeriod(Date timestamp, Date startDate, Date endDate)
static boolean isInPeriod(long timestamp, Date startDate, Date endDate)
{
if(startDate == null)
{
if(endDate == null)
return true;
else
return timestamp.before(endDate);
return timestamp < endDate.getTime();
}
else
{
if(endDate == null)
return timestamp.after(startDate);
return timestamp > startDate.getTime();
else
return timestamp.after(startDate) && timestamp.before(endDate);
return
timestamp > startDate.getTime()
&& timestamp < endDate.getTime();
}
}
@ -621,7 +622,7 @@ static boolean isInPeriod(Date timestamp, Date startDate, Date endDate)
* @return HistoryRecord
*/
static HistoryRecord filterByKeyword( NodeList propertyNodes,
Date timestamp,
long timestamp,
String[] keywords,
String field,
boolean caseSensitive)
@ -951,8 +952,14 @@ private static class HistoryRecordComparator
{
public int compare(HistoryRecord h1, HistoryRecord h2)
{
return h1.getTimestamp().
compareTo(h2.getTimestamp());
long d = (h2.getTimestamp() - h1.getTimestamp());
if (d == 0)
return 0;
else if (d < 0)
return -1;
else
return 1;
}
}
}

@ -58,12 +58,15 @@ public void addRecord(HistoryRecord record)
public void addRecord(String[] propertyValues)
throws IOException
{
this.addRecord(structPropertyNames, propertyValues, new Date());
addRecord(
structPropertyNames,
propertyValues,
System.currentTimeMillis());
}
public void addRecord(String[] propertyValues, Date timestamp)
throws IOException {
this.addRecord(structPropertyNames, propertyValues, timestamp);
this.addRecord(structPropertyNames, propertyValues, timestamp.getTime());
}
/**
@ -79,10 +82,10 @@ public void addRecord(String[] propertyValues, Date timestamp)
*/
private void addRecord(String[] propertyNames,
String[] propertyValues,
Date date)
long date)
throws InvalidParameterException, IOException
{
// Synchronized to assure that two concurent threads can insert records
// Synchronized to assure that two concurrent threads can insert records
// safely.
synchronized (this.docCreateLock)
{
@ -99,7 +102,7 @@ private void addRecord(String[] propertyNames,
synchronized (root)
{
Element elem = this.currentDoc.createElement("record");
elem.setAttribute("timestamp", Long.toString(date.getTime()));
elem.setAttribute("timestamp", Long.toString(date));
for (int i = 0; i < propertyNames.length; i++)
{
@ -159,7 +162,7 @@ private void addRecord(String[] propertyNames,
* @param date Date
* @param loadLastFile boolean
*/
private void createNewDoc(Date date, boolean loadLastFile)
private void createNewDoc(long date, boolean loadLastFile)
{
boolean loaded = false;
@ -180,7 +183,7 @@ private void createNewDoc(Date date, boolean loadLastFile)
loaded = true;
}
// if something happend and file was not loaded
// if something happened and file was not loaded
// then we must create new one
if(this.currentDoc == null)
{
@ -190,7 +193,7 @@ private void createNewDoc(Date date, boolean loadLastFile)
if (!loaded)
{
this.currentFile = Long.toString(date.getTime());
this.currentFile = Long.toString(date);
// while (this.currentFile.length() < 8)
// {
// this.currentFile = "0" + this.currentFile;

@ -94,14 +94,19 @@ private HistoryQuery find( final Date startDate,
final boolean caseSensitive,
final int resultCount)
{
String queryString = "";
StringBuilder queryString = new StringBuilder();
for (String s : keywords)
queryString += " " + s;
{
queryString.append(' ');
queryString.append(s);
}
final HistoryQueryImpl query = new HistoryQueryImpl(queryString);
final HistoryQueryImpl query
= new HistoryQueryImpl(queryString.toString());
new Thread()
{
@Override
public void run()
{
find(startDate, endDate, keywords, field, caseSensitive,
@ -133,12 +138,11 @@ private void find( Date startDate,
Vector<String> filelist
= HistoryReaderImpl.filterFilesByDate( history.getFileList(),
startDate, endDate, true);
Iterator<String> fileIterator = filelist.iterator();
while (fileIterator.hasNext() && resultCount > 0 && !query.isCanceled())
{
String filename = fileIterator.next();
Document doc = history.getDocumentForFile(filename);
if(doc == null)
@ -146,17 +150,14 @@ private void find( Date startDate,
NodeList nodes = doc.getElementsByTagName("record");
Node node;
for ( int i = nodes.getLength() - 1;
i >= 0 && !query.isCanceled();
i--)
{
node = nodes.item(i);
Node node = nodes.item(i);
String ts = node.getAttributes().getNamedItem("timestamp")
.getNodeValue();
Date timestamp = new Date(Long.parseLong(ts));
long timestamp = Long.parseLong(ts);
if(HistoryReaderImpl.isInPeriod(timestamp, startDate, endDate))
{

@ -638,7 +638,7 @@ private EventObject convertHistoryRecordToMessageEvent( HistoryRecord hr,
// the HistoryRecord timestamp is the timestamp when the record
// was written
long messageReceivedDate = msg.getMessageReceivedDate();
long hrTimestamp = hr.getTimeInMillis();
long hrTimestamp = hr.getTimestamp();
if (messageReceivedDate != 0)
{
if(messageReceivedDate - hrTimestamp > 86400000) // 24*60*60*1000
@ -684,7 +684,7 @@ private EventObject convertHistoryRecordToMessageEvent(
// the HistoryRecord timestamp is the timestamp when the record
// was written
long messageReceivedDate = msg.getMessageReceivedDate();
long hrTimestamp = hr.getTimeInMillis();
long hrTimestamp = hr.getTimestamp();
if(messageReceivedDate != 0)
{
if(messageReceivedDate - hrTimestamp > 86400000) // 24*60*60*1000

@ -6,17 +6,14 @@
*/
package net.java.sip.communicator.service.history.records;
import java.util.*;
/**
* @author Alexander Pelov
*/
public class HistoryRecord
{
private Date timestamp;
private String[] propertyNames;
private String[] propertyValues;
private final long timestamp;
private final String[] propertyNames;
private final String[] propertyValues;
/**
* Constructs an entry containing multiple name-value pairs, where the names
@ -29,7 +26,10 @@ public class HistoryRecord
public HistoryRecord(HistoryRecordStructure entryStructure,
String[] propertyValues)
{
this(entryStructure.getPropertyNames(), propertyValues, new Date());
this(
entryStructure.getPropertyNames(),
propertyValues,
System.currentTimeMillis());
}
/**
@ -41,7 +41,7 @@ public HistoryRecord(HistoryRecordStructure entryStructure,
*/
public HistoryRecord(String[] propertyNames, String[] propertyValues)
{
this(propertyNames, propertyValues, new Date());
this(propertyNames, propertyValues, System.currentTimeMillis());
}
/**
@ -53,7 +53,8 @@ public HistoryRecord(String[] propertyNames, String[] propertyValues)
* @param timestamp
*/
public HistoryRecord(HistoryRecordStructure entryStructure,
String[] propertyValues, Date timestamp)
String[] propertyValues,
long timestamp)
{
this(entryStructure.getPropertyNames(), propertyValues, timestamp);
}
@ -66,8 +67,9 @@ public HistoryRecord(HistoryRecordStructure entryStructure,
* @param propertyValues
* @param timestamp
*/
public HistoryRecord(String[] propertyNames, String[] propertyValues,
Date timestamp)
public HistoryRecord(String[] propertyNames,
String[] propertyValues,
long timestamp)
{
// TODO: Validate: Assert.assertNonNull(propertyNames, "The property names should be non-null.");
// TODO: Validate: Assert.assertNonNull(propertyValues, "The property values should be non-null.");
@ -91,16 +93,11 @@ public String[] getPropertyValues()
return this.propertyValues;
}
public Date getTimestamp()
public long getTimestamp()
{
return this.timestamp;
}
public long getTimeInMillis()
{
return (timestamp == null) ? 0 : timestamp.getTime();
}
/**
* Returns the String representation of this HistoryRecord.
*
@ -108,12 +105,15 @@ public long getTimeInMillis()
*/
public String toString()
{
String s = "History Record: ";
StringBuilder s = new StringBuilder("History Record: ");
for (int i = 0; i < propertyNames.length; i++)
{
s += propertyNames[i] + "=" + propertyValues[i] + "\n";
s.append(propertyNames[i]);
s.append('=');
s.append(propertyValues[i]);
s.append('\n');
}
return s;
return s.toString();
}
}

Loading…
Cancel
Save