diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-10-19 23:13:55 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-10-19 23:13:55 +0200 |
commit | a201f9e53f33109836a690488b9f8a98db4f5249 (patch) | |
tree | 41b010733e2efba6e1c7749a8459c7dec7fcaddf /src/eu/siacs/conversations/entities/Conversation.java | |
parent | e8bf75d79b74637d369d2a7134416c1f0852c420 (diff) |
got rid of copyonwrite array list for messages
Diffstat (limited to 'src/eu/siacs/conversations/entities/Conversation.java')
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index c984933f..600b9d38 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -1,8 +1,8 @@ package eu.siacs.conversations.entities; import java.security.interfaces.DSAPublicKey; +import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; import org.json.JSONException; import org.json.JSONObject; @@ -57,7 +57,7 @@ public class Conversation extends AbstractEntity { private String nextPresence; - private transient CopyOnWriteArrayList<Message> messages = null; + private transient ArrayList<Message> messages = new ArrayList<Message>(); private transient Account account = null; private transient SessionImpl otrSession; @@ -104,17 +104,6 @@ public class Conversation extends AbstractEntity { } public List<Message> getMessages() { - if (messages == null) { - this.messages = new CopyOnWriteArrayList<Message>(); // prevent null - // pointer - } - - // populate with Conversation (this) - - for (Message msg : messages) { - msg.setConversation(this); - } - return messages; } @@ -165,7 +154,7 @@ public class Conversation extends AbstractEntity { } } - public void setMessages(CopyOnWriteArrayList<Message> msgs) { + public void setMessages(ArrayList<Message> msgs) { this.messages = msgs; } @@ -507,4 +496,17 @@ public class Conversation extends AbstractEntity { } } } + + public void add(Message message) { + message.setConversation(this); + synchronized (this.messages) { + this.messages.add(message); + } + } + + public void addAll(int index, List<Message> messages) { + synchronized (this.messages) { + this.messages.addAll(index, messages); + } + } } |