<commit_before>package de.ibsys.planningTool.controller.tab.productionOrderTab;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.log4j.Logger;

import com.jfoenix.controls.JFXTextField;

import de.ibsys.planningTool.controller.tab.ProductionController;
import de.ibsys.planningTool.model.XmlInputData;
import de.ibsys.planningTool.model.xmlExportModel.Item;
import de.ibsys.planningTool.model.xmlInputModel.WaitingList;
import javafx.application.Application;

/**
 * Created by minhnguyen on 22.09.16.
 */
public abstract class BaseProductionTabController extends Application {

    public Logger logger = Logger.getLogger(this.getClass().getSimpleName());

    protected ProductionController productionOrderController;

    public void init(ProductionController productionOrderController) {
        this.productionOrderController = productionOrderController;
    }

    protected String getI18NText(String i18n) {
        return productionOrderController.getTranslation().getString(i18n);
    }

    protected int getForeCastInformationProductLine(String code) {
        return productionOrderController.getMainController().getForecastProductionList().get(code).getQuantity();
    }

    protected XmlInputData getXmlInputData() {
        return productionOrderController.getMainController().getXmlInputData();
    }

    protected int getStockValue(String code) {
        return getXmlInputData().getWareHouseArticles().get(code).getAmount();
    }

    protected int getQueueValue(String code) {
        return getXmlInputData().getWaitingListWorkPlaceMap().entrySet().parallelStream()
                .mapToInt(
                        stringWaitingListWorkPlaceEntry -> stringWaitingListWorkPlaceEntry.getValue().getWaitingLists()
                                .parallelStream().filter(waitingList -> waitingList.getArticleId().equals(code))
                                .mapToInt(WaitingList::getAmount).sum())
                .sum();
    }

    protected int getProcessValue(String code) {
        return getXmlInputData().getOrdersInWorkMap().entrySet().parallelStream()
                .filter(stringOrdersInWorkEntry -> stringOrdersInWorkEntry.getValue().getArticleId().equals(code))
                .mapToInt(value -> value.getValue().getAmount()).sum();
    }

    // get Production list which are on the machines
    protected int getWaitingListPartsAmount(String code) {
        return getXmlInputData().getStringWaitingListMissingPartsMap().entrySet().parallelStream()
                .filter(predicate -> predicate.getValue().getMissingPartsId().equals(code))
                .mapToInt(waitingList -> waitingList.getValue().getWaitingLists().parallelStream()
                        .mapToInt(WaitingList::getAmount).sum())
                .sum();
    }

    protected int getProductionValuePParts(String code, int sicherheitsbestand) {
        int vertriebwunsch = productionOrderController.getMainController().getForecastProductionList()
                .get("p" + code + "n").getQuantity();
        int lagerBestand = getStockValue(code);
        int warteschlange = getQueueValue(code);
        int bearbeitung = getProcessValue(code);
        // TODO maybe ?? need feedback with get WaitingLIstPartsAmount on
        // Machines ?
        // how to handle it

        return vertriebwunsch + sicherheitsbestand - lagerBestand - warteschlange - bearbeitung;
    }

    protected int getProductionValueEParts(int vertriebwunsch, int hilfszahl, int sicherheitsbestand,
                                           int lagerBestand, int warteschlange, int bearbeitung) {

        return vertriebwunsch + hilfszahl + sicherheitsbestand - lagerBestand - warteschlange - bearbeitung;

    }

    public int checkIsNegative(int production) {
        if (production < 0) {
            return 0;
        } else {
            return production;
        }
    }

    public List<Item> setMainProductionList(String product, List<JFXTextField> textfields) {
        List<Item> productionResultList = new ArrayList<>();
        List<String> parts = new ArrayList<String>();
        switch (product) {
            case "1":<commit_msg>Update BaseProductionTabController.java<commit_after>package de.ibsys.planningTool.controller.tab.productionOrderTab;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.log4j.Logger;

import com.jfoenix.controls.JFXTextField;

import de.ibsys.planningTool.controller.tab.ProductionController;
import de.ibsys.planningTool.model.XmlInputData;
import de.ibsys.planningTool.model.xmlExportModel.Item;
import de.ibsys.planningTool.model.xmlInputModel.WaitingList;
import javafx.application.Application;

/**
 * Created by minhnguyen on 22.09.16.
 */
public abstract class BaseProductionTabController extends Application {

    public Logger logger = Logger.getLogger(this.getClass().getSimpleName());

    protected ProductionController productionOrderController;

    public void init(ProductionController productionOrderController) {
        this.productionOrderController = productionOrderController;
    }

    protected String getI18NText(String i18n) {
        return productionOrderController.getTranslation().getString(i18n);
    }

    protected int getForeCastInformationProductLine(String code) {
        return productionOrderController.getMainController().getForecastProductionList().get(code).getQuantity();
    }

    protected XmlInputData getXmlInputData() {
        return productionOrderController.getMainController().getXmlInputData();
    }

    protected int getStockValue(String code) {
        return getXmlInputData().getWareHouseArticles().get(code).getAmount();
    }

    protected int getQueueValue(String code) {
        return getXmlInputData().getWaitingListWorkPlaceMap().entrySet().parallelStream()
                .mapToInt(
                        stringWaitingListWorkPlaceEntry -> stringWaitingListWorkPlaceEntry.getValue().getWaitingLists()
                                .parallelStream().filter(waitingList -> waitingList.getArticleId().equals(code))
                                .mapToInt(WaitingList::getAmount).sum())
                .sum();
    }

    protected int getProcessValue(String code) {
        return getXmlInputData().getOrdersInWorkMap().entrySet().parallelStream()
                .filter(stringOrdersInWorkEntry -> stringOrdersInWorkEntry.getValue().getArticleId().equals(code))
                .mapToInt(value -> value.getValue().getAmount()).sum();
    }

    // get Production list which are on the machines
    protected int getWaitingListPartsAmount(String code) {
        return getXmlInputData().getStringWaitingListMissingPartsMap().entrySet().parallelStream()
                .filter(predicate -> predicate.getValue().getMissingPartsId().equals(code))
                .mapToInt(waitingList -> waitingList.getValue().getWaitingLists().parallelStream()
                        .mapToInt(WaitingList::getAmount).sum())
                .sum();
    }

    protected int getProductionValuePParts(String code, int sicherheitsbestand) {
        int vertriebwunsch = productionOrderController.getMainController().getForecastProductionList()
                .get("p" + code + "n").getQuantity();
        int lagerBestand = getStockValue(code);
        int warteschlange = getQueueValue(code);
        int bearbeitung = getProcessValue(code);
        // TODO maybe ?? need feedback with get WaitingLIstPartsAmount on
        // Machines ?
        // how to handle it

        return vertriebwunsch + sicherheitsbestand - lagerBestand - warteschlange - bearbeitung;
    }

    protected int getProductionValueEParts(String code, int vertriebwunsch, int hilfszahl, int sicherheitsbestand,
                                           int lagerBestand, int warteschlange, int bearbeitung) {

        return vertriebwunsch + hilfszahl + sicherheitsbestand - lagerBestand - warteschlange - bearbeitung;

    }

    public int checkIsNegative(int production) {
        if (production < 0) {
            return 0;
        } else {
            return production;
        }
    }

    public List<Item> setMainProductionList(String product, List<JFXTextField> textfields) {
        List<Item> productionResultList = new ArrayList<>();
        List<String> parts = new ArrayList<String>();
        switch (product) {
            case "1":
{'fraction_non_alphanumeric': 0.0947856039909728, 'fraction_numerical': 0.003800926475828483, 'mean_word_length': 3.129475232957332, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4235884', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2167, 'n_words': 408}