/**
 * Edge.java created on 2016年12月1日 下午2:13:26 by jiminghu
 */
package com.dgt.graphdemo.entity.fqz;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import org.apache.commons.lang3.StringUtils;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 
 * @author: jiminghu
 * @since: 2016年12月1日
 */
public class Edge extends CommonBean<Edge>{

	/**
	 */
	private static final long serialVersionUID = -1925481982912372949L;

	private String id;
	
	private String source;
	
	private String target;
	
	private String weaverSource;
	
	private String weaverTarget;
	
	private List<String> weaverId;
	
	private List<String> rel;

	private List<EdgeAttr> attr;
	
	private Boolean delete;
	
	public Edge(){}
	
	public Edge(Object weaverIds, Object rels){
		weaverId = new ArrayList<>();
		if(null!=weaverIds){
			String x = Objects.toString(weaverIds);
			if(StringUtils.isNotBlank(x)){
				String[] xs = x.split(",");
				weaverId = Arrays.asList(xs);
			}
		}
		rel = new ArrayList<>();
		if(null!=rels){
			String x = Objects.toString(rels);
			if(StringUtils.isNotBlank(x)){
				String[] xs = x.split(",");
				rel = Arrays.asList(xs);
			}
		}
		attr = new ArrayList<EdgeAttr>();
	}
	
	public List<EdgeAttr> getAttr() {
		return attr;
	}


	public void setAttr(List<EdgeAttr> attr) {
		this.attr = attr;
	}


	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	
	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	
	/**
	 * @return the source
	 */
	public String getSource() {
		return source;
	}

	
	/**
	 * @param source the source to set
	 */
	public void setSource(String source) {
		this.source = source;
	}

	
	/**
	 * @return the target
	 */
	public String getTarget() {
		return target;
	}

	
	/**
	 * @param target the target to set
	 */
	public void setTarget(String target) {
		this.target = target;
	}

	
	/**
	 * @return the rel
	 */
	public List<String> getRel() {
		return rel;
	}

	
	/**
	 * @param rel the rel to set
	 */
	public void setRel(List<String> rel) {
		this.rel = rel;
	}


	public JsonObject toJsonObject() {
		JsonObject ob = new JsonObject();
		ob.addProperty("id", this.id);
		ob.addProperty("source", this.source);
		ob.addProperty("target", this.target);
		JsonArray arr = new JsonArray();
		for(String s:this.rel)
		{
			arr.add(new JsonPrimitive(s));
		}
		ob.add("rel", arr);
		return ob;
	}

	
	/**
	 * @return the weaverId
	 */
	public List<String> getWeaverId() {
		return weaverId;
	}


	
	/**
	 * @param weaverId the weaverId to set
	 */
	public void setWeaverId(List<String> weaverId) {
		this.weaverId = weaverId;
	}

	public String getWeaverSource() {
		return weaverSource;
	}

	public void setWeaverSource(String weaverSource) {
		this.weaverSource = weaverSource;
	}

	public String getWeaverTarget() {
		return weaverTarget;
	}

	public void setWeaverTarget(String weaverTarget) {
		this.weaverTarget = weaverTarget;
	}

	/**
	 * @return the delete
	 */
	public Boolean getDelete() {
		return delete;
	}

	
	/**
	 * @param delete the delete to set
	 */
	public void setDelete(Boolean delete) {
		this.delete = delete;
	}

}
