aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIngo Bauersachs <ingo@jitsi.org>2014-11-27 16:02:25 +0100
committerIngo Bauersachs <ingo@jitsi.org>2014-11-27 16:14:50 +0100
commit80ea5390e3c15d179188c48d0c0b3504cf657609 (patch)
tree5be6212371b369900eb9771fd60862576bddbb3a /src
parent32de2595ac51308df94043d8f99008d8cebe9915 (diff)
downloadjitsi-80ea5390e3c15d179188c48d0c0b3504cf657609.zip
jitsi-80ea5390e3c15d179188c48d0c0b3504cf657609.tar.gz
jitsi-80ea5390e3c15d179188c48d0c0b3504cf657609.tar.bz2
Remove most pre-sorting in the history service to avoid eliminations.
The sorting introduced in commit 4c665742027d7e89f0c136d1e30ea946be2a1c0f didn't take into account that TreeSet mandates that the ordering "...must be consistent with equals if it is to correctly implement the Set interface.". This was not the case as the comparator only checks for the timestamp of a history event and as such it can have two or more events at exactly the same time (and thus ordering) which would be overwritten in the resulting set.
Diffstat (limited to 'src')
-rw-r--r--src/net/java/sip/communicator/impl/metahistory/MetaHistoryServiceImpl.java3
-rw-r--r--src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java127
2 files changed, 57 insertions, 73 deletions
diff --git a/src/net/java/sip/communicator/impl/metahistory/MetaHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/metahistory/MetaHistoryServiceImpl.java
index 78dac57..c8f3543 100644
--- a/src/net/java/sip/communicator/impl/metahistory/MetaHistoryServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/metahistory/MetaHistoryServiceImpl.java
@@ -199,7 +199,7 @@ public class MetaHistoryServiceImpl
MessageProgressWrapper listenWrapper
= new MessageProgressWrapper(services.length);
- TreeSet<Object> result = new TreeSet<Object>(new RecordsComparator());
+ LinkedList<Object> result = new LinkedList<Object>();
for (int i = 0; i < services.length; i++)
{
String name = services[i];
@@ -244,6 +244,7 @@ public class MetaHistoryServiceImpl
}
listenWrapper.fireLastProgress(startDate, endDate, null);
+ Collections.sort(result, new RecordsComparator());
return result;
}
diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java
index ee6da6b..1b73547 100644
--- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java
@@ -129,8 +129,8 @@ public class MessageHistoryServiceImpl
Date startDate)
throws RuntimeException
{
- TreeSet<EventObject> result =
- new TreeSet<EventObject>(new MessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
+
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
@@ -177,8 +177,7 @@ public class MessageHistoryServiceImpl
Date endDate)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new MessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
@@ -221,8 +220,7 @@ public class MessageHistoryServiceImpl
Date endDate)
throws RuntimeException
{
- TreeSet<EventObject> result
- = new TreeSet<EventObject>(new MessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
@@ -316,9 +314,7 @@ public class MessageHistoryServiceImpl
public Collection<EventObject> findLast(MetaContact contact, int count)
throws RuntimeException
{
- TreeSet<EventObject> result
- = new TreeSet<EventObject>(
- new MessageEventComparator<EventObject>());
+ LinkedList<EventObject> result = new LinkedList<EventObject>();
Iterator<Contact> iter = contact.getContacts();
while (iter.hasNext())
@@ -337,20 +333,19 @@ public class MessageHistoryServiceImpl
convertHistoryRecordToMessageEvent(recs.next(), item));
}
- } catch (IOException e)
+ }
+ catch (IOException e)
{
logger.error("Could not read history", e);
}
}
- LinkedList<EventObject> resultAsList
- = new LinkedList<EventObject>(result);
- int startIndex = resultAsList.size() - count;
-
+ Collections.sort(result, new MessageEventComparator<EventObject>());
+ int startIndex = result.size() - count;
if(startIndex < 0)
startIndex = 0;
- return resultAsList.subList(startIndex, resultAsList.size());
+ return result.subList(startIndex, result.size());
}
/**
@@ -394,9 +389,7 @@ public class MessageHistoryServiceImpl
boolean isSMSEnabled)
throws RuntimeException
{
- TreeSet<EventObject> result
- = new TreeSet<EventObject>(
- new MessageEventComparator<EventObject>(true));
+ HashSet<EventObject> result = new HashSet<EventObject>();
List<HistoryID> historyIDs=
this.historyService.getExistingHistories(
@@ -605,8 +598,7 @@ public class MessageHistoryServiceImpl
int count)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new MessageEventComparator<EventObject>());
+ LinkedList<EventObject> result = new LinkedList<EventObject>();
Iterator<Contact> iter = contact.getContacts();
while (iter.hasNext())
@@ -633,7 +625,8 @@ public class MessageHistoryServiceImpl
item));
}
- } catch (IOException e)
+ }
+ catch (IOException e)
{
logger.error("Could not read history", e);
}
@@ -663,14 +656,12 @@ public class MessageHistoryServiceImpl
startIx++;
}
- LinkedList<EventObject> resultAsList
- = new LinkedList<EventObject>(result);
-
+ Collections.sort(result, new MessageEventComparator<EventObject>());
int toIndex = startIx + count;
- if(toIndex > resultAsList.size())
- toIndex = resultAsList.size();
+ if(toIndex > result.size())
+ toIndex = result.size();
- return resultAsList.subList(startIx, toIndex);
+ return result.subList(startIx, toIndex);
}
/**
@@ -688,8 +679,7 @@ public class MessageHistoryServiceImpl
int count)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new MessageEventComparator<EventObject>());
+ LinkedList<EventObject> result = new LinkedList<EventObject>();
Iterator<Contact> iter = contact.getContacts();
while (iter.hasNext())
@@ -710,20 +700,19 @@ public class MessageHistoryServiceImpl
item));
}
- } catch (IOException e)
+ }
+ catch (IOException e)
{
logger.error("Could not read history", e);
}
}
- LinkedList<EventObject> resultAsList
- = new LinkedList<EventObject>(result);
- int startIndex = resultAsList.size() - count;
-
+ Collections.sort(result, new MessageEventComparator<EventObject>());
+ int startIndex = result.size() - count;
if(startIndex < 0)
startIndex = 0;
- return resultAsList.subList(startIndex, resultAsList.size());
+ return result.subList(startIndex, result.size());
}
/**
@@ -1867,7 +1856,7 @@ public class MessageHistoryServiceImpl
boolean caseSensitive)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(new MessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
@@ -1908,7 +1897,7 @@ public class MessageHistoryServiceImpl
boolean caseSensitive)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(new MessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
@@ -1949,7 +1938,7 @@ public class MessageHistoryServiceImpl
boolean caseSensitive)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(new MessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
// get the readers for this contact
Map<Contact, HistoryReader> readers = getHistoryReaders(contact);
@@ -2032,7 +2021,7 @@ public class MessageHistoryServiceImpl
public Collection<EventObject> findByStartDate(ChatRoom room, Date startDate)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(new ChatRoomMessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
try
{
// get the readers for this room
@@ -2069,7 +2058,7 @@ public class MessageHistoryServiceImpl
public Collection<EventObject> findByEndDate(ChatRoom room, Date endDate)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(new ChatRoomMessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
try
{
// get the readers for this room
@@ -2107,7 +2096,7 @@ public class MessageHistoryServiceImpl
public Collection<EventObject> findByPeriod(ChatRoom room, Date startDate, Date endDate)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(new ChatRoomMessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
try
{
// get the readers for this room
@@ -2168,8 +2157,7 @@ public class MessageHistoryServiceImpl
Date endDate, String[] keywords, boolean caseSensitive)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new ChatRoomMessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
try
{
// get the readers for this room
@@ -2225,8 +2213,7 @@ public class MessageHistoryServiceImpl
boolean caseSensitive)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new ChatRoomMessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
try
{
// get the readers for this room
@@ -2284,8 +2271,7 @@ public class MessageHistoryServiceImpl
boolean caseSensitive)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new ChatRoomMessageEventComparator<EventObject>());
+ HashSet<EventObject> result = new HashSet<EventObject>();
try
{
// get the readers for this room
@@ -2324,8 +2310,7 @@ public class MessageHistoryServiceImpl
public Collection<EventObject> findLast(ChatRoom room, int count)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new ChatRoomMessageEventComparator<EventObject>());
+ LinkedList<EventObject> result = new LinkedList<EventObject>();
try
{
@@ -2340,19 +2325,19 @@ public class MessageHistoryServiceImpl
room));
}
- } catch (IOException e)
+ }
+ catch (IOException e)
{
logger.error("Could not read history", e);
}
- LinkedList<EventObject> resultAsList
- = new LinkedList<EventObject>(result);
- int startIndex = resultAsList.size() - count;
-
+ Collections.sort(result,
+ new ChatRoomMessageEventComparator<EventObject>());
+ int startIndex = result.size() - count;
if(startIndex < 0)
startIndex = 0;
- return resultAsList.subList(startIndex, resultAsList.size());
+ return result.subList(startIndex, result.size());
}
/**
@@ -2370,8 +2355,7 @@ public class MessageHistoryServiceImpl
int count)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new ChatRoomMessageEventComparator<EventObject>());
+ LinkedList<EventObject> result = new LinkedList<EventObject>();
try
{
@@ -2386,19 +2370,19 @@ public class MessageHistoryServiceImpl
room));
}
- } catch (IOException e)
+ }
+ catch (IOException e)
{
logger.error("Could not read history", e);
}
- LinkedList<EventObject> resultAsList
- = new LinkedList<EventObject>(result);
-
+ Collections.sort(result,
+ new ChatRoomMessageEventComparator<EventObject>());
int toIndex = count;
- if(toIndex > resultAsList.size())
- toIndex = resultAsList.size();
+ if(toIndex > result.size())
+ toIndex = result.size();
- return resultAsList.subList(0, toIndex);
+ return result.subList(0, toIndex);
}
/**
@@ -2416,8 +2400,7 @@ public class MessageHistoryServiceImpl
int count)
throws RuntimeException
{
- TreeSet<EventObject> result = new TreeSet<EventObject>(
- new ChatRoomMessageEventComparator<EventObject>());
+ LinkedList<EventObject> result = new LinkedList<EventObject>();
try
{
@@ -2432,19 +2415,19 @@ public class MessageHistoryServiceImpl
room));
}
- } catch (IOException e)
+ }
+ catch (IOException e)
{
logger.error("Could not read history", e);
}
- LinkedList<EventObject> resultAsList
- = new LinkedList<EventObject>(result);
- int startIndex = resultAsList.size() - count;
-
+ Collections.sort(result,
+ new ChatRoomMessageEventComparator<EventObject>());
+ int startIndex = result.size() - count;
if(startIndex < 0)
startIndex = 0;
- return resultAsList.subList(startIndex, resultAsList.size());
+ return result.subList(startIndex, result.size());
}
/**