package com.paritytrading.philadelphia.client;

import java.util.List;
import java.util.Scanner;

class WaitCommand implements Command {
    private static final long WAIT_TIME_MILLIS = 50;

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

        String msgType = arguments.next();

        if (arguments.hasNext())
            throw new IllegalArgumentException();

        while (true) {
            try {
                Thread.sleep(WAIT_TIME_MILLIS);

                if (msgType.equals(getLastMsgType(client.getMessages())))
                    break;

            } catch (InterruptedException e) {
                break;
            }
        }
    }

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

    @Override
    public String getDescription() {
        return "Wait for a specific MsgType(35)";
    }

    @Override
    public String getUsage() {
        return "wait <MsgType(35)>";
    }

    private String getLastMsgType(Messages messages) {
        List<Message> collect = messages.collect();

        if (collect.isEmpty())
            return null;

        return collect.get(collect.size() - 1).getMsgType();
    }
}

@@ -130,16 +130,17 @@
 mmand %7B%0A
+%0A
     priv
@@ -1022,27 +1022,24 @@
  %22wait %3C
-MsgT
+msg-t
 ype
-(35)
 %3E%22;%0A    
@@ -1053,16 +1053,23 @@
 private 
+static 
 String g
@@ -1132,16 +1132,19 @@
  collect
+ion
  = messa
@@ -1178,16 +1178,19 @@
 (collect
+ion
 .isEmpty
@@ -1241,16 +1241,19 @@
  collect
+ion
 .get(col
@@ -1256,16 +1256,19 @@
 (collect
+ion
 .size() 
@@ -1292,10 +1292,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Clean up 'WaitCommand'