package bank;

import java.util.*;

/**
 * Created by vr on 15.03.2017.
 */
public class Bank {
    private long opens;
    private long closes;
    private Event[] eventlog;



    public Bank(long opens, long closes, Event[] events) {
        this.opens = opens;
        this.closes = closes;
        this.eventlog = events;
    }


    public void addEvent(Event event){
    }

    public ArrayList<TimeRange> findMaxLoad(HashMap<Long, Integer> map){
        ArrayList<TimeRange> result = new ArrayList<TimeRange>();
        long timeFrom = this.opens;
        long timeTo = this.closes;
        int max = 0;
        for (Map.Entry<Long, Integer> pair : map.entrySet()) {
            if (pair.getValue() > max) {
                max = pair.getValue();
            }
        }
        Iterator it = map.entrySet().iterator();
        while (it.hasNext())
        {
            Map.Entry<Long, Integer> item = (Map.Entry) it.next();
            System.out.println(item.getKey() + " " + item.getValue());
            if (item.getValue() == max) {
                timeFrom = item.getKey();
                System.out.println("ok");
                if (it.hasNext()){
                    timeTo =  ((Map.Entry<Long, Integer>) it.next()).getKey();
                }
                System.out.println(timeFrom + " " + timeTo);
                result.add(new TimeRange(timeFrom,timeTo));
                timeTo = this.closes;
            }
        }
        System.out.println(max);
        return result;
    }

    public TimeRange findMinLoad(){
        return null;
    }

    public HashMap<Long, Integer> createTimetable(){
        LinkedHashMap<Long, Integer> map = new LinkedHashMap<Long, Integer>();
        int count = 0;
        for (Event event: eventlog) {
            long eventTime = event.getTime();
            int increment = (event.getEventType() == 1) ? 1 : -1;
            count += increment;
            map.put(eventTime, count);
        }
        System.out.println(map);
        return map;
    }

    public static void main(String[] args) {
        Bank bank = new Bank(8,20, new Event[] {new In(9), new In(9), new Out(11),new In(12)});
        bank.findMaxLoad(bank.createTimetable());
    }

}

@@ -2004,32 +2004,34 @@
 urn map;%0A    %7D%0A%0A
+//
     public stati
@@ -2055,24 +2055,26 @@
 g%5B%5D args) %7B%0A
+//
         Bank
@@ -2157,16 +2157,18 @@
 (12)%7D);%0A
+//
         
@@ -2205,21 +2205,23 @@
 metable());%0A
+//
     %7D%0A%0A%7D%0A

add at the beginning