Skip to content
Permalink
3b99e145f5
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
293 lines (243 sloc) 5.95 KB
package activity;
import java.util.ArrayList;
import java.util.List;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class Activity {
private int id;
private String verb;
private String object;
private String ori_verb;
private String ori_object;
private String url_img;
private String categoryID;
private String linkID;
private double rating;
private int view;
private int clusterID;
private String clusterName;
private String video;//just for the root action
private List<Integer> subactivities;
private String parent;
private String prev;
private String next;
public Activity(String v, String o, String v_o, String o_o){
verb = v;
object = o;
ori_verb = v_o;
ori_object = o_o;
}
public Activity(int id, String v, String o, String v_o, String o_o,
String cateID, String linkID, double rate, int view, String url, String video){
this.id = id;
verb = v;
object = o;
ori_verb = v_o;
ori_object = o_o;
this.url_img = url;
this.video = video;
this.setCategoryID(cateID);
this.setLinkID(linkID);
setRating(rate);
this.setView(view);
subactivities = new ArrayList<>();
parent = "-1";
prev = "-1";
next = "-1";
this.setClusterID(-1);
clusterName = "";
}
public Activity(Activity act){
this.id = act.getID();
verb = act.getVerb();
object = act.getObject();
ori_object = act.getOriObject();
ori_verb = act.getOriVerb();
setCategoryID(act.getCategoryID());
this.setLinkID(act.getLinkID());
setRating(act.getRating());
this.setView(act.getView());
url_img = act.getUrlImage();
setClusterID(act.getClusterID());
clusterName = act.getClusterName();
this.video = act.getVideo();
subactivities = act.getSubActivities();
this.parent = act.getParent();
this.prev = act.getPrev();
this.next = act.getNext();
}
public Activity(int id, String v, String o, String v_o, String o_o,
String cateID, String linkID, double rate, int view, String url,
int clusterid, String clustername, String video,
ArrayList<Integer> sub, String parent, String pre, String next){
this.id = id;
verb = v;
object = o;
ori_object = o_o;
ori_verb = v_o;
setCategoryID(cateID);
this.setLinkID(linkID);
setRating(rate);
this.setView(view);
url_img = url;
setClusterID(clusterid);
clusterName = clustername;
this.video = video;
subactivities = sub;
this.parent = parent;
this.prev = pre;
this.next = next;
}
public Activity() {
// TODO Auto-generated constructor stub
}
public int getID(){
return id;
}
public void setID(int id){
this.id = id;
}
public String getVerb(){
return verb;
}
public void setVerb(String v){
verb = v;
}
public String getObject(){
return object;
}
public void setObject(String o){
object = o;
}
public String getOriVerb(){
return ori_verb;
}
public void setOriVerb(String ori){
this.ori_verb = ori;
}
public String getOriObject(){
return ori_object;
}
public void setOriObject(String ori){
this.ori_object = ori;
}
public String getUrlImage(){
return url_img;
}
public void setUrlImage(String url){
url_img = url;
}
public List<Integer> getSubActivities(){
return subactivities;
}
public void setSubActivities(ArrayList<Integer> sub){
subactivities = sub;
}
public String getParent(){
return parent;
}
public void setParent(String parent){
this.parent = parent;
}
public String getPrev(){
return prev;
}
public void setPrev(String prev){
this.prev = prev;
}
public String getNext(){
return next;
}
public void setNext(String next){
this.next = next;
}
public String getClusterName(){
return clusterName;
}
public void setClusterName(String cluster){
this.clusterName = cluster;
}
public String getCategoryID() {
return categoryID;
}
public void setCategoryID(String categoryID) {
this.categoryID = categoryID;
}
public String getLinkID() {
return linkID;
}
public void setLinkID(String linkID) {
this.linkID = linkID;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
public int getView() {
return view;
}
public void setView(int view) {
this.view = view;
}
public int getClusterID() {
return clusterID;
}
public void setClusterID(int clusterID) {
this.clusterID = clusterID;
}
public String getVideo() {
return video;
}
public void setVideo(String video) {
this.video = video;
}
//List of subactivities to JSON array
@SuppressWarnings("unchecked")
public JSONArray subacttoJSONArray(){
JSONArray sub = new JSONArray();
if (getSubActivities().size() > 0){
for (int k=0; k<getSubActivities().size(); k++){
sub.add(getSubActivities().get(k));
}
}
return sub;
}
//Activity to JSON format
@SuppressWarnings("unchecked")
public JSONObject toJsonObject(){
JSONObject obj = new JSONObject();
obj.put("id", getID());
obj.put("verb", getVerb());
obj.put("object", getObject());
obj.put("ori-verb", getOriVerb());
obj.put("ori-object", getOriObject());
obj.put("image", getUrlImage());
obj.put("categoryid", getCategoryID());
obj.put("linkid", getLinkID());
obj.put("rating", getRating());
obj.put("view", getView());
obj.put("clusterid", getClusterID());
obj.put("clustername", getClusterName());
obj.put("video", getVideo());
obj.put("parent", getParent());
obj.put("prev", getPrev());
obj.put("next", getNext());
obj.put("sub-activity", subacttoJSONArray());
return obj;
}
public Activity setNormalized(){
this.setVerb(normString(this.getVerb()));
this.setObject(normString(this.getObject()));
this.setOriVerb(normString(this.getOriVerb()));
this.setOriObject(normString(this.getOriObject()));
return this;
}
public static String normString(String s){
return s.replaceAll("\"", "").replaceAll("}", "")
.replaceAll("\\{", "").replaceAll("\\[", "").replaceAll("]", "")
.replaceAll(":", "").replaceAll(",", " ")
.replaceAll("\\s+", " ").trim().toLowerCase();
}
}