<commit_before>/*
 * Copyright 2006-2009 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.osedu.org/licenses/ECL-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kra.budget.calculator;

import java.util.List;

import org.kuali.kra.budget.calculator.query.Equals;
import org.kuali.kra.infrastructure.KraServiceLocator;
import org.kuali.rice.kns.service.BusinessObjectService;

/**
 * Holds the Calculation rules and order of calculation.
 * 
 */
public class FormulaMaker {

    private QueryList<ValidCalcType> validCalcTypes;
    private String ebOnLaRateClassCode;
    private String ebOnLARateTypeCode;
    private String vaOnLARateClassCode;
    private String vaOnLARateTypeCode;
    private BusinessObjectService businessObjectService;

    /**
     * Constructor....
     */
    public FormulaMaker() {
        this.businessObjectService = KraServiceLocator.getService(BusinessObjectService.class);
        initValidCalcTypes();
        sortCalcTypes();
        setEBAndVAonLAValues();
    } // end FormulaMaker


    private void initValidCalcTypes() {
        List validCalcTypesFromDB = (List)businessObjectService.findAll(ValidCalcType.class);
        this.validCalcTypes = new QueryList<ValidCalcType>(validCalcTypesFromDB);
    }


    /**
     * Does the sorting of Rate Class Types based on dependencies. ie, all the Rate Class Types which is not dependent on any other
     * comes first, followed by all other rate class types.
     */
    public void sortCalcTypes() {
        if (validCalcTypes != null && validCalcTypes.size() > 0) {
            QueryList<ValidCalcType> elTempCalcTypes = new QueryList<ValidCalcType>();
            String depRateClassType = "";
            String rateClassType = "";
            Equals equals;<commit_msg>KRACOEUS-2901: Fixed the sort order of the valid calc types so the calculation loop will ignore the duplicates as designed.<commit_after>/*
 * Copyright 2006-2009 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.osedu.org/licenses/ECL-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kra.budget.calculator;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.kuali.kra.budget.calculator.query.Equals;
import org.kuali.kra.infrastructure.KraServiceLocator;
import org.kuali.rice.kns.service.BusinessObjectService;

/**
 * Holds the Calculation rules and order of calculation.
 * 
 */
public class FormulaMaker {

    private QueryList<ValidCalcType> validCalcTypes;
    private String ebOnLaRateClassCode;
    private String ebOnLARateTypeCode;
    private String vaOnLARateClassCode;
    private String vaOnLARateTypeCode;
    private BusinessObjectService businessObjectService;

    /**
     * Constructor....
     */
    public FormulaMaker() {
        this.businessObjectService = KraServiceLocator.getService(BusinessObjectService.class);
        initValidCalcTypes();
        sortCalcTypes();
        setEBAndVAonLAValues();
    } // end FormulaMaker


    private void initValidCalcTypes() {
        Map<String, String> searchValues = new HashMap<String, String>();
        List validCalcTypesFromDB = (List)businessObjectService.findMatchingOrderBy(ValidCalcType.class, searchValues, "rateClassType", true);
        this.validCalcTypes = new QueryList<ValidCalcType>(validCalcTypesFromDB);
    }


    /**
     * Does the sorting of Rate Class Types based on dependencies. ie, all the Rate Class Types which is not dependent on any other
     * comes first, followed by all other rate class types.
     */
    public void sortCalcTypes() {
        if (validCalcTypes != null && validCalcTypes.size() > 0) {
            QueryList<ValidCalcType> elTempCalcTypes = new QueryList<ValidCalcType>();
            String depRateClassType = "";
            String rateClassType = "";
            Equals equals;
{'fraction_non_alphanumeric': 0.08077003557229546, 'fraction_numerical': 0.006277463904582548, 'mean_word_length': 3.5179584120982987, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1692996', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1293, 'n_words': 417}