package ru.asemenov.OrderBook;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
/**
 * Class OrderBook решение задачи части 005.
 * @author asemenov
 * @version 1
 */
public class OrderBook {
    /**
     * Buy.
     */
    private Map<Double, Order> buy = new TreeMap<>(new Comparator<Double>() {
        @Override
        public int compare(Double o1, Double o2) {
            return o2.compareTo(o1);
        }
    });
    /**
     * Sell.
     */
    private Map<Double, Order> sell = new TreeMap<>();
    /**
     * Add new order.
     * @param order new.
     */
    void add(Order order) {
        if ("BUY".equals(order.getOperation())) {
            Order newOrder = buy.get(order.getPrice());
            if (newOrder != null) {
                newOrder.setVolume(newOrder.getVolume() + order.getVolume());
            } else {
                buy.put(order.getPrice(), order);
            }

        } else {
            Order newOrder = sell.get(order.getPrice());
            if (newOrder != null) {
                newOrder.setVolume(newOrder.getVolume() + order.getVolume());
            } else {
                sell.put(order.getPrice(), order);
            }
        }
    }

    /**
     * Delete order.
     * @param orderId delete.
     * @return boolean.
     */
    boolean delete(int orderId) {
        for (Map.Entry<Double, Order> e: buy.entrySet()) {
            if (e.getValue().getOrderId() == orderId) {
                buy.remove(e.getKey());
                return true;
            }
        }
        for (Map.Entry<Double, Order> e: sell.entrySet()) {
            if (e.getValue().getOrderId() == orderId) {
                buy.remove(e.getKey());
                return true;
            }
        }
        return false;
    }

    /**
     * Print order.
     */
    void print() {
        for (Map.Entry<Double, Order> e: buy.entrySet()) {
            System.out.println("\t\t" + e.getKey() + "@" + e.getValue().getVolume());
        }

        for (Map.Entry<Double, Order> e: sell.entrySet()) {
            System.out.println(e.getValue().getVolume() + "@" +  e.getKey());
        }
    }
}

@@ -54,16 +54,42 @@
 arator;%0A
+import java.util.HashMap;%0A
 import j
@@ -240,16 +240,76 @@
 rBook %7B%0A
+    private Map%3CInteger, Order%3E allOrder = new HashMap%3C%3E();%0A
     /**%0A
@@ -717,320 +717,374 @@
     
-if (%22BUY%22.equals(order.getOperation())) %7B%0A            Order newOrder = buy.get(order.getPrice());%0A   
+allOrder.put(order.getOrderId(), order);%0A    %7D%0A%0A    /**%0A     * Delete order.%0A     * @param orderId delete.%0A
      
+*/%0A
     
-if (newOrder != null) %7B%0A                newOrder.setVolume(newOrder.getVolume() + order.getVolume()
+void delete(int orderId) %7B%0A        allOrder.remove(orderId
 );%0A    
+%7D%0A%0A
     
-    %7D else %7B
+/**%0A     * Print order.
 %0A     
+*/%0A
     
-       buy.put(order.getPrice(), o
+void print() %7B%0A        for (Map.Entry%3CInteger, O
 rder
-);%0A       
+%3E e : allOrder.entrySet()) %7B%0A
      
-%7D%0A%0A
        
- %7D else
+if (%22BUY%22.equals(e.getValue().getOperation()))
  %7B%0A 
@@ -1094,16 +1094,20 @@
         
+    
 Order ne
@@ -1119,22 +1119,28 @@
 r = 
-sell
+buy
 .get(
-order
+e.getValue()
 .get
@@ -1145,24 +1145,28 @@
 etPrice());%0A
+    
             
@@ -1205,16 +1205,20 @@
         
+    
 newOrder
@@ -1251,21 +1251,28 @@
 ume() + 
-order
+e.getValue()
 .getVolu
@@ -1270,32 +1270,36 @@
 ).getVolume());%0A
+    
             %7D el
@@ -1323,43 +1323,64 @@
     
-sell.put(order.getPrice(), order);%0A
+    buy.put(e.getValue().getPrice(), e.getValue());%0A    
     
@@ -1401,292 +1401,213 @@
     
-%7D%0A
     %7D
-%0A%0A    /**%0A     * Delete order.%0A     * @param orderId del
+ else %7B%0A                Order newOrder = sell.g
 et
+(
 e.
-%0A     * @return boolean.
+getValue().getPrice());
 %0A     
-*/%0A
     
-boolean delete(int orderId) %7B%0A        for (Map.Entry%3CDouble, Order%3E e: buy.entrySet()) %7B%0A            if (e.getVa
+       if (newOrder != null) %7B%0A                    newOrder.setVo
 lu
+m
 e(
-).getOrderId() == orderId) %7B%0A                buy.remove(e
+newOrder.getVolume() + e.getValue()
 .get
-Key
+Volume
 ());
@@ -1627,34 +1627,16 @@
     
-return true;%0A            %7D
+%7D else %7B
 %0A   
@@ -1640,26 +1640,24 @@
         
-%7D%0A
         
 for (Map
@@ -1652,151 +1652,56 @@
     
-for (Map.Entry%3CDouble, Order%3E e: sell.entrySet()) %7B%0A            if (e.getValue().getOrderId() == orderId) %7B%0A                buy.remove(e.getKey
+    sell.put(e.getValue().getPrice(), e.getValue
 ());
@@ -1721,20 +1721,9 @@
     
-return true;
+%7D
 %0A   
@@ -1747,91 +1747,8 @@
   %7D%0A
-        return false;%0A    %7D%0A%0A    /**%0A     * Print order.%0A     */%0A    void print() %7B
 %0A   
@@ -1988,19 +1988,30 @@
 ut.print
-ln(
+f(%22%257s@%25s%5Cn%22, 
 e.getVal
@@ -2026,25 +2026,17 @@
 Volume()
- + %22@%22 + 
+,
  e.getKe

Order book update