1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-22 17:02:21 -05:00

Synchronized all LinkedLists - see issue 2

This commit is contained in:
Sebastian Kaspari 2010-03-11 23:41:31 +01:00
parent 54c968f302
commit 14ca3e0668
3 changed files with 27 additions and 10 deletions

View File

@ -20,7 +20,9 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.adapter; package org.yaaic.adapter;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import org.yaaic.model.Conversation; import org.yaaic.model.Conversation;
import org.yaaic.view.MessageListView; import org.yaaic.view.MessageListView;
@ -40,10 +42,18 @@ public class DeckAdapter extends BaseAdapter
{ {
public static final String TAG = "Yaaic/DeckAdapter"; public static final String TAG = "Yaaic/DeckAdapter";
private LinkedList<Conversation> conversations = new LinkedList<Conversation>(); private List<Conversation> conversations;
private MessageListView currentView; private MessageListView currentView;
private String currentChannel; private String currentChannel;
/**
* Create a new DeckAdapter instance
*/
public DeckAdapter()
{
conversations = Collections.synchronizedList(new LinkedList<Conversation>());
}
/** /**
* Get number of item * Get number of item
*/ */

View File

@ -20,7 +20,9 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.adapter; package org.yaaic.adapter;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import org.yaaic.model.Conversation; import org.yaaic.model.Conversation;
import org.yaaic.model.Message; import org.yaaic.model.Message;
@ -38,7 +40,7 @@ import android.widget.TextView;
*/ */
public class MessageListAdapter extends BaseAdapter public class MessageListAdapter extends BaseAdapter
{ {
private LinkedList<TextView> messages = new LinkedList<TextView>(); private List<TextView> messages;
private Context context; private Context context;
/** /**
@ -49,6 +51,7 @@ public class MessageListAdapter extends BaseAdapter
*/ */
public MessageListAdapter(Conversation conversation, Context context) public MessageListAdapter(Conversation conversation, Context context)
{ {
this.messages = Collections.synchronizedList(new LinkedList<TextView>());
this.context = context; this.context = context;
// Render channel name as first message in channel // Render channel name as first message in channel

View File

@ -20,7 +20,9 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.model; package org.yaaic.model;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
/** /**
* Base class for conversations * Base class for conversations
@ -39,8 +41,8 @@ public abstract class Conversation
private static final int HISTORY_SIZE = 30; private static final int HISTORY_SIZE = 30;
private LinkedList<Message> buffer = new LinkedList<Message>(); private List<Message> buffer;
private LinkedList<Message> history = new LinkedList<Message>(); private List<Message> history;
private String name; private String name;
/** /**
@ -57,6 +59,8 @@ public abstract class Conversation
*/ */
public Conversation(String name) public Conversation(String name)
{ {
this.buffer = Collections.synchronizedList(new LinkedList<Message>());
this.history = Collections.synchronizedList(new LinkedList<Message>());
this.name = name; this.name = name;
} }
@ -73,11 +77,11 @@ public abstract class Conversation
*/ */
public void addMessage(Message message) public void addMessage(Message message)
{ {
buffer.addFirst(message); buffer.add(0, message);
history.addLast(message); history.add(message);
if (history.size() > HISTORY_SIZE) { if (history.size() > HISTORY_SIZE) {
history.removeFirst(); history.remove(0);
} }
} }
@ -86,7 +90,7 @@ public abstract class Conversation
* *
* @return * @return
*/ */
public LinkedList<Message> getHistory() public List<Message> getHistory()
{ {
return history; return history;
} }
@ -98,8 +102,8 @@ public abstract class Conversation
*/ */
public Message pollBufferedMessage() public Message pollBufferedMessage()
{ {
Message message = buffer.getLast(); Message message = buffer.get(buffer.size() - 1);
buffer.removeLast(); buffer.remove(buffer.size() - 1);
return message; return message;
} }