package com.lekebilen.quasseldroid;

import java.util.List;
import java.util.PriorityQueue;

public class Buffer {
	private BufferInfo info;
	private PriorityQueue<Message> backlog = null;
	private int lastSeenMessage;
	private int markerLineMessage;
	

	public Buffer(BufferInfo info) {
		this.info = info;
	}
	
	public void addBacklog(Message message) {
		if (backlog == null)
			backlog = new PriorityQueue<Message>();
		
//		System.out.println("Buffer " + new String(info.name.array()) + " got message: " + message);
		backlog.add(message); // TODO: sort
	}
	public void setLastSeenMessage(int lastSeenMessage) {
		this.lastSeenMessage = lastSeenMessage;
	}	
	public void setMarkerLineMessage(int markerLineMessage) {
		this.markerLineMessage = markerLineMessage;
	}
	public BufferInfo getInfo() {
		return info;
	}
	public PriorityQueue<Message> getBacklog() {
		return backlog;
	}
	public int getLastSeenMessage() {
		return lastSeenMessage;
	}
	public int getMarkerLineMessage() {
		return markerLineMessage;
	}
}

@@ -90,27 +90,76 @@
 e;%0A%0A
-public class Buffer
+import java.util.Observable;%0A%0Apublic class Buffer extends Observable
  %7B%0A%09
@@ -346,24 +346,66 @@
 nfo = info;%0A
+%09%09backlog = new PriorityQueue%3CMessage%3E();%0A
 %09%7D%0A%09%0A%09public
@@ -446,208 +446,57 @@
 %7B%0A%09%09
-if (
 backlog
- == null)%0A%09%09%09backlog = new PriorityQueue%3CM
+.add(m
 essage
-%3E(
 );%0A%09%09
-%0A//%09%09System.out.println(%22Buffer %22 + new String(info.name.array()) + %22 got message: %22 + message);%0A%09%09backlog.add(message); // TODO: sort
+notifyObservers(message);
 %0A%09%7D%0A

make the Buffer observable for new messages