/*
 * Copyright (C) 2025  Tim Zimmermann <tim@aglais.org>
 *
 * 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.aglais.zms.util;

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

/**
 * Utility class for converting between List of Integer objects and arrays of primitive int.
 */
public class IntUtil {

    /**
     * Converts a List of Integer objects to an array of primitive int.
     *
     * @param list The List of Integer to be converted
     * @return an array of primitive int containing the elements of the list
     */
    public static int[] toArray(List<Integer> list) {
        int[] result = new int[list.size()];

        for (int i = 0; i < list.size(); i++) {
            result[i] = list.get(i);
        }

        return result;
    }

    /**
     * Converts an array of primitive int to a List of Integer objects.
     *
     * @param array The array of primitive int to be converted
     * @return a List of Integer containing the elements of the array
     */
    public static List<Integer> toList(int[] array) {
        List<Integer> result = new ArrayList<>();

        for (int i : array) {
            result.add(i);
        }

        return result;
    }
}