Originally Posted by
jps
The snippet looks ok..
Post a
SSCCE
The code runs and what not. However, right or a wrong keyword match still displays the error message. If wrong, it iterates 10 times (10 recipes in the array list) and then brings up a blank interface without showing any recipes. If it is right - the match, it iterates 10 times and then displays the correct recipe.
I need to break from the iteration, somehow. The break only stops the iteration, BUT invalid input = no recipes on the interface (which should still have all the recipes) and if it's correct input = no recipe match cos it obviously breaks where it isn't receiving the code to display the recipes.
/**
* Searches the cakes using the search string
* @param searchString
* list of keywords to be searched in a cake recipe
*/
private void searchAll(String searchString)
{
if(searchString.isEmpty())
{
createCenterPanel();
}
else
{
ArrayList<CakeRecipe> searchRecipe = new ArrayList<>();
centerPanel.removeAll();
String[] keys = searchString.split(" ");
for(CakeRecipe recipe : recipeSet.getAllCakeRecipes())
{
if(recipe.foundWords(keys) != true)
{
JOptionPane.showMessageDialog(this,"No recipe containing search words found.", "Error!",
JOptionPane.ERROR_MESSAGE);
}
else
{
searchRecipe.add(recipe);
}
break;
}
Collections.sort(searchRecipe);