Esempio n. 1
0
 public List<CookingRecipe> findRecipesWithExactIngredients(List<String> ingredients)
     throws Exception {
   System.out.println("Database: findRecipesWithExactIngredients(" + ingredients + ")");
   List<CookingRecipe> allCookingRecipes = getAllCookingRecipes();
   List<CookingRecipe> vyhovujuce = new ArrayList<>();
   boolean obsahuje = false;
   for (CookingRecipe cr : allCookingRecipes) {
     // iterujeme vsetky ingrediencie receptu
     // prechadzame ingrediencie a zistujeme ci sa dana ingrediencia nachadza
     for (String ci2 : ingredients) {
       obsahuje = false; // predpokladame ze danu ingredienciu neobsahuje
       for (CookingIngredient ci : cr.getIngredients()) {
         if (ci.getIngredient().equalsIgnoreCase(ci2)) {
           obsahuje = true;
           break;
         }
       }
       if (!obsahuje) {
         break;
       }
     }
     // ak najdeme vsetky ingrediencie v recepte, tak vyhovuje
     if (obsahuje) {
       vyhovujuce.add(cr);
     }
   }
   System.out.println("Database: vyhovujucich receptov: " + vyhovujuce.size());
   return vyhovujuce;
 }
Esempio n. 2
0
 private void insertIngredients(List<CookingIngredient> ingredients, long recipe_id) {
   System.out.println("Database: insertIngredients(" + ingredients + ", " + recipe_id + ")");
   // vytvor register log pre dany blocek
   StringBuilder sql =
       new StringBuilder("insert into ingredients(recipe_id,ingredient,quantity) values\n");
   if (ingredients.size() == 0) {
     throw new RuntimeException("ingredients size must not be 0");
   }
   for (int i = 0; i < ingredients.size() - 1; i++) {
     CookingIngredient ing = ingredients.get(i);
     sql.append(
         "(" + recipe_id + "  ,'" + ing.getIngredient() + "','" + ing.getQuantity() + "' ),\n");
   }
   CookingIngredient ing = ingredients.get(ingredients.size() - 1);
   sql.append("(" + recipe_id + "  ,'" + ing.getIngredient() + "','" + ing.getQuantity() + "' );");
   jdbcTemplate.execute(sql.toString());
 }
Esempio n. 3
0
 public List<CookingRecipe> findRecipesWithIngredients(List<String> ingredients) throws Exception {
   System.out.println("Database: findRecipesWithIngredients(" + ingredients + ")");
   List<CookingRecipe> allCookingRecipes = getAllCookingRecipes();
   List<CookingRecipe> vyhovujuce = new ArrayList<>();
   boolean naslo = false;
   for (CookingRecipe cr : allCookingRecipes) {
     // iterujeme vsetky ingrediencie receptu
     for (CookingIngredient ci : cr.getIngredients()) {
       naslo = false;
       for (String ci2 : ingredients) {
         if (ci.getIngredient().equalsIgnoreCase(ci2)) {
           vyhovujuce.add(cr);
           naslo = true;
           break;
         }
       }
       if (naslo) {
         break;
       }
     }
   }
   System.out.println("Database: vyhovujucich receptov: " + vyhovujuce.size());
   return vyhovujuce;
 }