chapter_004/src/main/java/ru/job4j/trade/Repository.java
/**
     * Add application in the container.
     *
     * @param application - application.
     */
Add application in the container.
@param application - application.
Add application in the container . @param application - application .
public void addApplication(Application application) {
        if (application.getAction().equals(BUY.getName())) {
            for (Map.Entry<Double, Application> entry : this.sellSortTable.entrySet()) {
                if (entry.getValue().getPrice() <= application.getPrice()) {
                    if (entry.getValue().getVolume() >= application.getVolume()) {
                        entry.getValue().setVolume(entry.getValue().getVolume() - application.getVolume());
                        application.setVolume(0);
                        break;
                    } else {
                        application.setVolume(application.getVolume() - entry.getValue().getVolume());
                        this.sellSortTable.remove(entry.getKey());
                        break;
                    }
                }
            }
            if (this.buySortTable.get(application.getPrice()) != null && application.getVolume() > 0) {
                this.buySortTable.get(application.getPrice()).setVolume(this.buySortTable.get(application.getPrice()).getVolume() + application.getVolume());
            } else if (this.buySortTable.get(application.getPrice()) == null && application.getVolume() > 0) {
                this.buySortTable.put(application.getPrice(), application);
            }
        } else if (application.getAction().equals(SELL.getName())) {
            for (Map.Entry<Double, Application> entry : this.buySortTable.entrySet()) {
                if (entry.getValue().getPrice() >= application.getPrice()) {
                    if (entry.getValue().getVolume() >= application.getVolume()) {
                        entry.getValue().setVolume(entry.getValue().getVolume() - application.getVolume());
                        application.setVolume(0);
                        break;
                    } else {
                        application.setVolume(application.getVolume() - entry.getValue().getVolume());
                        this.buySortTable.remove(entry.getKey());
                    }
                }
            }
            if (this.sellSortTable.get(application.getPrice()) != null && application.getVolume() > 0) {
                this.sellSortTable.get(application.getPrice()).setVolume(this.sellSortTable.get(application.getPrice()).getVolume() + application.getVolume());
            } else if (this.sellSortTable.get(application.getPrice()) == null && application.getVolume() > 0) {
                this.sellSortTable.put(application.getPrice(), application);
            }
        }
    }
public void addApplication ( Application application ) { if ( application . getAction ( ) . equals ( BUY . getName ( ) ) ) { for ( Map . Entry < Double , Application > entry : this . sellSortTable . entrySet ( ) ) { if ( entry . getValue ( ) . getPrice ( ) <= application . getPrice ( ) ) { if ( entry . getValue ( ) . getVolume ( ) >= application . getVolume ( ) ) { entry . getValue ( ) . setVolume ( entry . getValue ( ) . getVolume ( ) - application . getVolume ( ) ) ; application . setVolume ( 0 ) ; break ; } else { application . setVolume ( application . getVolume ( ) - entry . getValue ( ) . getVolume ( ) ) ; this . sellSortTable . remove ( entry . getKey ( ) ) ; break ; } } } if ( this . buySortTable . get ( application . getPrice ( ) ) != null && application . getVolume ( ) > 0 ) { this . buySortTable . get ( application . getPrice ( ) ) . setVolume ( this . buySortTable . get ( application . getPrice ( ) ) . getVolume ( ) + application . getVolume ( ) ) ; } else if ( this . buySortTable . get ( application . getPrice ( ) ) == null && application . getVolume ( ) > 0 ) { this . buySortTable . put ( application . getPrice ( ) , application ) ; } } else if ( application . getAction ( ) . equals ( SELL . getName ( ) ) ) { for ( Map . Entry < Double , Application > entry : this . buySortTable . entrySet ( ) ) { if ( entry . getValue ( ) . getPrice ( ) >= application . getPrice ( ) ) { if ( entry . getValue ( ) . getVolume ( ) >= application . getVolume ( ) ) { entry . getValue ( ) . setVolume ( entry . getValue ( ) . getVolume ( ) - application . getVolume ( ) ) ; application . setVolume ( 0 ) ; break ; } else { application . setVolume ( application . getVolume ( ) - entry . getValue ( ) . getVolume ( ) ) ; this . buySortTable . remove ( entry . getKey ( ) ) ; } } } if ( this . sellSortTable . get ( application . getPrice ( ) ) != null && application . getVolume ( ) > 0 ) { this . sellSortTable . get ( application . getPrice ( ) ) . setVolume ( this . sellSortTable . get ( application . getPrice ( ) ) . getVolume ( ) + application . getVolume ( ) ) ; } else if ( this . sellSortTable . get ( application . getPrice ( ) ) == null && application . getVolume ( ) > 0 ) { this . sellSortTable . put ( application . getPrice ( ) , application ) ; } } }
Add application in the container.
Add application in the container .