Skip to content
Permalink
0d82ff1dc4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
86 lines (75 sloc) 2.11 KB
package kb.howtokb.wkhobject;
import java.util.ArrayList;
import java.util.regex.Pattern;
import org.json.simple.JSONArray;
import kb.howtokb.global.Global;
import kb.howtokb.tools.NormalizationText;
public class Ingredients {
private String name_method;
private ArrayList<String> ingredients = new ArrayList<String>();
Pattern pattern = Pattern.compile("[a-zA-Z]");
public Ingredients(String name, ArrayList<String> thing){
this.name_method = name;
this.ingredients = thing;
}
// ======================================================================
/**
* Get name of method/part
* @return name of method
*/
public String getName(){
if (!pattern.matcher(name_method).find()){
return Global.GENERAL_INGREDIENT;
}
return name_method;
}
// ======================================================================
/**
* Get list of ingredients
* @return list of ingredients
*/
public ArrayList<String> getIngredients(){
return ingredients;
}
public void setName_method(String name_method) {
this.name_method = name_method;
}
public void setIngredients(ArrayList<String> ingredients) {
this.ingredients = ingredients;
}
@Override
public String toString(){
String s = getName() + "\n";
for (int i=0; i<getIngredients().size(); i++){
s += getIngredients().get(i) + "\n";
}
return s;
}
public String toText(){
String s = getName() + " ";
for (int i=0; i<getIngredients().size(); i++){
s += getIngredients().get(i) + " ";
}
return s;
}
// ======================================================================
/**
* Return a json array that converted from list of ingredients
* @return a json array
*/
@SuppressWarnings("unchecked")
public JSONArray getIngredientsJSONArray(){
JSONArray ingre = new JSONArray();
if (getIngredients().size() > 0){
for (int k=0; k<getIngredients().size(); k++){
ingre.add(getIngredients().get(k));
}
}
return ingre;
}
public Ingredients setNormalized(){
this.setName_method(NormalizationText.normString(this.getName()));
this.setIngredients(NormalizationText.normString(this.getIngredients()));
return this;
}
}