package cookery_db;

import cookery_db.database.RecipeIngredient;
import java.util.Collection;
import java.util.Iterator;


/**
 * Acts as a general type converter for the Cookery database.
 * @author Nick Apperley
 */
public class TypeConverter
{
    /**
     * Converts a recipe ingredent collection to an array.
     * @param recipeIngredientCol The recipe ingredient collection to convert.
     * @return The recipe ingredients as an array.
     */
    public static RecipeIngredient[] toRecipeIngredientArray(Collection recipeIngredientCol)
    {
        RecipeIngredient[] recipeIngredientArr = new RecipeIngredient[recipeIngredientCol.size()];
        RecipeIngredient recipeIngredient = null;
        Iterator iter = recipeIngredientCol.iterator();
        int pos = 0;

        while (iter.hasNext())
        {
            recipeIngredient = (RecipeIngredient) iter.next();
            recipeIngredientArr[pos] = recipeIngredient;
            pos++;
        }
        return recipeIngredientArr;
    }
}
