package com.paritytrading.philadelphia.client.command;

import com.paritytrading.philadelphia.client.TerminalClient;
import com.paritytrading.philadelphia.client.message.Message;
import com.paritytrading.philadelphia.client.message.Messages;
import java.util.Scanner;

class MessagesCommand implements Command {

    @Override
    public void execute(TerminalClient client, Scanner arguments) throws CommandException {
        if (arguments.hasNext())
            throw new CommandException();

        for (Message message : client.getMessages().collect())
            client.printf("%s\n", message);
    }

    @Override
    public String getName() {
        return "messages";
    }

    @Override
    public String getDescription() {
        return "Display received messages";
    }

    @Override
    public String getUsage() {
        return "messages";
    }

}

@@ -260,16 +260,71 @@
 Scanner;
+%0Aimport org.eclipse.collections.api.list.ImmutableList;
 %0A%0Aclass 
@@ -495,24 +495,26 @@
 s.hasNext())
+ %7B
 %0A           
@@ -518,39 +518,485 @@
     
-throw new CommandException();%0A%0A
+int index = arguments.nextInt();%0A%0A            ImmutableList%3CMessage%3E messages = client.getMessages().collect();%0A%0A            if (index %3E= 0 && index %3C +messages.size())%0A                client.printf(%22%25s%5Cn%22, messages.get(index));%0A%0A            if (index %3E= -messages.size() && index %3C 0)%0A                client.printf(%22%25s%5Cn%22, messages.get(index + messages.size()));%0A%0A            if (arguments.hasNext())%0A                throw new CommandException();%0A        %7D%0A        else %7B%0A    
     
@@ -1058,32 +1058,36 @@
 ())%0A            
+    
 client.printf(%22%25
@@ -1102,16 +1102,26 @@
 ssage);%0A
+        %7D%0A
     %7D%0A%0A 
@@ -1360,28 +1360,38 @@
 return %22messages
+ %5B%3Cindex%3E%5D
 %22;%0A    %7D%0A%0A%7D%0A

Improve 'messages' command