package com.sagacloud.utils.objects;
/*
 * Author: Jxing
 * Create Time: 2018/12/13
 */

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class RelationCriteria {
    private String graphId;
    private String graphType;
    private String relType = "1";
    private RelationSide side = RelationSide.both;
    private String fromId;
    private String toId;
    private ArrayList<String> fromIdArr;
    private ArrayList<String> toIdArr;

    private Set<String>  fromSet;
    private Set<String> toSet;

    public RelationCriteria() {
        fromSet = new HashSet<>();
        toSet = new HashSet<>();
    }

    public String getFromId() {
        if(fromId == null)
            fromId = "";
        return fromId;
    }

    public void setFromId(String fromId) {
        this.fromId = fromId;
    }

    public String getToId() {
        if(toId == null)
            toId = "";
        return toId;
    }

    public void setToId(String toId) {
        this.toId = toId;
    }

    public String getGraphId() {
        return graphId == null ? null : graphId.trim();
    }

    public void setGraphId(String graphId) {
        this.graphId = graphId;
    }

    public String getGraphType() {
        return graphType == null ? null : graphType.trim();
    }

    public void setGraphType(String graphType) {
        this.graphType = graphType;
    }

    public String getRelType() {
        if(relType == null || relType.length() == 0)
            return "1";
        return relType;
    }

    public ArrayList<String> getFromIdArr() {
        return fromIdArr;
    }

    public void setFromIdArr(ArrayList<String> fromIdArr) {
        this.fromIdArr = fromIdArr;
    }

    public ArrayList<String> getToIdArr() {
        return toIdArr;
    }

    public void setToIdArr(ArrayList<String> toIdArr) {
        this.toIdArr = toIdArr;
    }

    public Set<String> getFromSet() {
        return fromSet;
    }

    public void setFromSet(Set<String> fromSet) {
        this.fromSet = fromSet;
    }

    public Set<String> getToSet() {
        return toSet;
    }

    public void setToSet(Set<String> toSet) {
        this.toSet = toSet;
    }

    public void setRelType(String relType) {
        this.relType = relType;
    }

    public RelationSide getSide() {
        if(side == null)
            return RelationSide.both;
        return side;
    }

    public void setSide(RelationSide side) {
        this.side = side;
    }

    public void processFromToId() {
        if(fromId != null && fromId.length() > 0){
            fromSet.add(fromId);
        }
        if(toId != null && toId.length() > 0){
            toSet.add(toId);
        }
        if(fromIdArr != null && fromIdArr.size() > 0){
            fromSet.addAll(fromIdArr);
        }
        if(toIdArr != null && toIdArr.size() > 0){
            toSet.addAll(toIdArr);
        }
    }
}
