8788899091929394959697
public Message addMessage(String msg) { return addMessage(msg, new Date()); } private Message addMessage(String msg, Date date) { Message m = new Message(date, msg, getNewId()); list.add(0, m); return m; }
96979899100101102103104105106
return m; } public Message getMessage(int uniqueId) { int index = 0; Message m; while(index < list.size()) { if((m = list.get(index)).getUniqueId() == uniqueId) return m; index++;
8081828384858687888990
return singleton.getMessages(); } @POST public Response addMessage(String msg) throws URISyntaxException { Message m = singleton.addMessage(msg); URI msgURI = ui.getRequestUriBuilder().path(Integer.toString(m.getUniqueId())).build(); return Response.created(msgURI).build(); }
90919293949596979899100
} @Path("{msgNum}") @GET public Message getMessage(@PathParam("msgNum") int msgNum) { Message m = singleton.getMessage(msgNum); if(m == null) { // This exception will be passed through to the JAX-RS runtime // No other runtime exception will behave this way unless the // exception is annotated with javax.ejb.ApplicationException
8687888990919293949596
public synchronized Message addMessage(String msg) { return addMessage(msg, new Date()); } private synchronized Message addMessage(String msg, Date date) { Message m = new Message(date, msg, getNewId()); list.addFirst(m); return m; }
9596979899100101102103104105