package com.paritytrading.parity.ticker;

import static com.paritytrading.parity.ticker.MarketDataListener.*;

import com.paritytrading.foundation.ASCII;
import com.paritytrading.parity.book.OrderBook;
import com.paritytrading.parity.book.Side;
import com.paritytrading.parity.util.Timestamps;
import it.unimi.dsi.fastutil.longs.Long2ObjectArrayMap;
import java.util.List;
import java.util.Locale;

class DisplayFormat extends MarketDataListener {

    private static final String HEADER = "" +
        "Timestamp    Inst     Bid Px    Bid Size   Ask Px    Ask Size   Last Px   Last Size\n" +
        "------------ -------- --------- ---------- --------- ---------- --------- ----------";

    private static final String MISSING = String.format("%9s %10s", "-", "-");

    private Long2ObjectArrayMap<Trade> trades;

    private long second;
    private long timestamp;

    private int counter;

    public DisplayFormat(List<String> instruments) {
        trades = new Long2ObjectArrayMap<>();

        for (String instrument : instruments)
            trades.put(ASCII.packLong(instrument), new Trade());

        printf("\n%s\n", HEADER);
    }

    @Override
    public void update(OrderBook book, boolean bbo) {
        if (!bbo)
            return;

        long instrument = book.getInstrument();

        long bidPrice = book.getBestBidPrice();
        long bidSize  = book.getBidSize(bidPrice);

        long askPrice = book.getBestAskPrice();
        long askSize  = book.getAskSize(askPrice);

        printf("%12s %8s ", Timestamps.format(timestampMillis()), ASCII.unpackLong(instrument));

        if (bidSize != 0)
            printf("%9.2f %10d ", bidPrice / PRICE_FACTOR, bidSize);
        else
            printf("%s ", MISSING);

        if (askSize != 0)
            printf("%9.2f %10d ", askPrice / PRICE_FACTOR, askSize);
        else
            printf("%s ", MISSING);

        Trade trade = trades.get(instrument);

        if (trade.size != 0)
            printf("%9.2f %10d\n", trade.price / PRICE_FACTOR, trade.size);
        else
            printf("%s\n", MISSING);
    }

    @Override
    public void trade(OrderBook book, Side side, long price, long size) {
        Trade trade = trades.get(book.getInstrument());

        trade.price = price;
        trade.size  = size;
    }

    private void printf(String format, Object... args) {
        System.out.printf(Locale.US, format, args);
    }

    private static class Trade {
        public long price;
        public long size;
    }

}

@@ -748,16 +748,17 @@
 %259s %2510s
+ 
 %22, %22-%22, 
@@ -1720,33 +1720,25 @@
        print
-f(%22%25s %22, 
+(
 MISSING);%0A%0A 
@@ -1865,17 +1865,9 @@
 rint
-f(%22%25s %22, 
+(
 MISS
@@ -2059,18 +2059,11 @@
 rint
-f(%22%25s%5Cn%22, 
+ln(
 MISS
@@ -2337,24 +2337,24 @@
 ... args) %7B%0A
-
         Syst
@@ -2392,32 +2392,178 @@
 , args);%0A    %7D%0A%0A
+    private void print(String x) %7B%0A        System.out.print(x);%0A    %7D%0A%0A    private void println(String x) %7B%0A        System.out.println(x);%0A    %7D%0A%0A
     private stat

Clean up output formatting in stock ticker