Permalink
Cannot retrieve contributors at this time
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?
HowToKB/src/kb/howtokb/wkhobject/Ingredients.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
86 lines (75 sloc)
2.11 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |