<commit_before>/*
 * This file is part of NavalPlan
 *
 * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
 *                         Desenvolvemento Tecnolóxico de Galicia
 * Copyright (C) 2010-2011 Igalia, S.L.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.navalplanner.business.common;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.math.fraction.Fraction;

/**
 * @author <NAME> <<EMAIL>>
 */
public class ProportionalDistributor {

    public static ProportionalDistributor create(int... initialShares) {
        return new ProportionalDistributor(toFractions(
                sumIntegerParts(initialShares), initialShares));
    }

    public static int sumIntegerParts(int[] numbers) {
        int sum = 0;
        for (Number each : numbers) {
            sum += each.intValue();
        }
        return sum;
    }

    private static Fraction[] toFractions(int initialTotal, int... shares) {
        Fraction[] result = new Fraction[shares.length];
        for (int i = 0; i < result.length; i++) {
            result[i] = initialTotal == 0 ? Fraction.ZERO : new Fraction(
                    shares[i], initialTotal);
        }
        return result;
    }

    private static class FractionWithPosition implements
            Comparable<FractionWithPosition> {

        public static List<FractionWithPosition> transform(Fraction[] fractions) {
            List<FractionWithPosition> result = new ArrayList<FractionWithPosition>();
            for (int i = 0; i < fractions.length; i++) {<commit_msg>It's inefficient to use boxed objects<commit_after>/*
 * This file is part of NavalPlan
 *
 * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
 *                         Desenvolvemento Tecnolóxico de Galicia
 * Copyright (C) 2010-2011 Igalia, S.L.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.navalplanner.business.common;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.math.fraction.Fraction;

/**
 * @author <NAME> <<EMAIL>>
 */
public class ProportionalDistributor {

    public static ProportionalDistributor create(int... initialShares) {
        return new ProportionalDistributor(toFractions(
                sumIntegerParts(initialShares), initialShares));
    }

    public static int sumIntegerParts(int[] numbers) {
        int sum = 0;
        for (int each : numbers) {
            sum += each;
        }
        return sum;
    }

    private static Fraction[] toFractions(int initialTotal, int... shares) {
        Fraction[] result = new Fraction[shares.length];
        for (int i = 0; i < result.length; i++) {
            result[i] = initialTotal == 0 ? Fraction.ZERO : new Fraction(
                    shares[i], initialTotal);
        }
        return result;
    }

    private static class FractionWithPosition implements
            Comparable<FractionWithPosition> {

        public static List<FractionWithPosition> transform(Fraction[] fractions) {
            List<FractionWithPosition> result = new ArrayList<FractionWithPosition>();
            for (int i = 0; i < fractions.length; i++) {
{'fraction_non_alphanumeric': 0.08689839572192513, 'fraction_numerical': 0.009358288770053475, 'mean_word_length': 2.900086880973067, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, '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': '424799', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1174, 'n_words': 447}