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/Things.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.01 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 Things { | |
private String name_method; | |
private ArrayList<String> things = new ArrayList<String>(); | |
Pattern pattern = Pattern.compile("[a-zA-Z]"); | |
public Things(String name, ArrayList<String> thing){ | |
this.name_method = name; | |
this.things = thing; | |
} | |
// ====================================================================== | |
/** | |
* Get name of method/part | |
* @return name of method | |
*/ | |
public String getName(){ | |
if (!pattern.matcher(name_method).find()){ | |
return Global.GENERAL_THING; | |
} | |
return name_method; | |
} | |
// ====================================================================== | |
/** | |
* Get list of things you will need | |
* @return list of things | |
*/ | |
public ArrayList<String> getThings(){ | |
return things; | |
} | |
public void setName_method(String name_method) { | |
this.name_method = name_method; | |
} | |
public void setThings(ArrayList<String> things) { | |
this.things = things; | |
} | |
@Override | |
public String toString(){ | |
String s = getName() + "\n"; | |
for (int i=0; i<getThings().size(); i++){ | |
s += getThings().get(i) + "\n"; | |
} | |
return s; | |
} | |
public String toText(){ | |
String s = getName() + " "; | |
for (int i=0; i<getThings().size(); i++){ | |
s += getThings().get(i) + " "; | |
} | |
return s; | |
} | |
// ====================================================================== | |
/** | |
* Return a json array that converted from list of things | |
* @return JSONArray | |
*/ | |
@SuppressWarnings("unchecked") | |
public JSONArray getThingsJSONArray(){ | |
JSONArray things = new JSONArray(); | |
if (getThings().size() > 0){ | |
for (int k=0; k<getThings().size(); k++){ | |
things.add(getThings().get(k)); | |
} | |
} | |
return things; | |
} | |
public Things setNormalized(){ | |
this.setName_method(NormalizationText.normString(this.getName())); | |
this.setThings(NormalizationText.normString(this.getThings())); | |
return this; | |
} | |
} |