import java.util.*;

public class ChatService {
   public static final int MAX_MSG = 25;
   private static LinkedList _msgList = new LinkedList();

   public String post(String msg) {
      synchronized(_msgList) {
         if(_msgList.size() >= MAX_MSG)
            _msgList.remove(0);
         _msgList.add(msg);
      }
      return read();
   }

   public String read() {
      synchronized(_msgList) {
         Iterator it = _msgList.iterator();
         StringBuffer buf = new StringBuffer();
         while(it.hasNext()) {
            buf.append(it.next().toString());
         }
         return buf.toString();
      }
   }
}