package com.sagacloud.utils.relationUtils;

import java.util.HashSet;
import java.util.Objects;

/**
 * Created by Xiaoyu on 2019/1/4
 */
public class RelationNode {
    private String fromId;
    private String toId;
    private String graphType;
    private String graphId;
    private String relType;

    public RelationNode() {
    }

    ;

    public RelationNode(String fromId, String toId, String graphType, String graphId, String relType) {
        this.fromId = fromId;
        this.toId = toId;
        this.graphType = graphType;
        this.graphId = graphId;
        this.relType = relType;
    }

    public String getFromId() {
        return fromId;
    }

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

    public String getToId() {
        return toId;
    }

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

    public String getGraphType() {
        if (graphType != null) {
            return graphType;
        } else {
            if (graphId != null && graphId.length() > 5) {
                this.graphType = graphId.substring(2, graphId.length() - 3);
            }
        }
        return graphType;
    }

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

    public String getGraphId() {
        return graphId;
    }

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

    public String getRelType() {
        return relType;
    }

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

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RelationNode that = (RelationNode) o;
        return Objects.equals(fromId, that.fromId) &&
                Objects.equals(toId, that.toId) &&
                Objects.equals(graphId, that.graphId) &&
                Objects.equals(relType, that.relType);
    }

    @Override
    public int hashCode() {
        return Objects.hash(fromId, toId, graphId, relType);
    }
}
