Ejemplo n.º 1
0
 /**
  * Scales a Recipe's Ingredients, Serving Size, and Nutritional Information to match the scaled
  * factor.
  *
  * @param recipe Recipe to scale.
  * @param scaleFactor The factor to scale it by.
  * @return A new Recipe object with scaled fields.
  */
 public static Recipe scaleRecipe(Recipe recipe, double scaleFactor) {
   // rebuild and scale ingredients
   ArrayList<RecipeIngredient> newIngredientsList = new ArrayList<RecipeIngredient>();
   for (RecipeIngredient ingredient : recipe.getIngredients()) {
     if (ingredient.getAmount() == null) newIngredientsList.add(ingredient);
     else newIngredientsList.add(ingredient.scale(scaleFactor));
   }
   // build the new Recipe and return
   return new Recipe(
       recipe.getName(),
       recipe.getInstructions(),
       recipe.getServingSize().scale(scaleFactor),
       recipe.getServings(),
       recipe.getRating(),
       newIngredientsList,
       recipe.getNutritionInformation().scale(scaleFactor));
 }