All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.graph.Vertex Maven / Gradle / Ivy

package com.datastax.graph;

import java.util.*;

/**
 * Anders Hong 6/24/2015.
 */
public class Vertex {
    private long id=-1;
    private String name;
    private List labels;
    private Map properties=new LinkedHashMap<>();

    //用于进行【复合主键】的判断
    private List idColumns;

    //一般只会在节点的属性比较多的情况下才会用到
    //缺点:每个节点都会自带分组信息,前后端传输数据量增多
    private LinkedHashMap propertyGroup;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map getProperties() {
        return properties;
    }

    public void setProperties(Map properties) {
        this.properties = properties;
    }

    public List getLabels() {
        return labels;
    }

    public void setLabels(List labels) {
        this.labels = labels;
    }

    public void setProperty(String key,Object value){
        properties.put(key,value);
    }

    public void addProperties(Map properties){
        for(String key : properties.keySet()){
            setProperty(key,properties.get(key));
        }
    }

    public void addLabel(String label){
        if(null==labels){
            labels=new ArrayList<>();
        }
        labels.add(label);
    }

    public void addLabels(String[] labels){
        if(null==labels) return;

        for(String label : labels){
            addLabel(label);
        }
    }

    public LinkedHashMap getPropertyGroup() {
        return propertyGroup;
    }

    public void setPropertyGroup(LinkedHashMap propertyGroup) {
        this.propertyGroup = propertyGroup;
    }

    public List getIdColumns() {
        return idColumns;
    }

    public void setIdColumns(List idColumns) {
        this.idColumns = idColumns;
    }

    @Override
    public boolean equals(Object obj) {
        boolean flag=false;
        Vertex v=(Vertex) obj;
        Vertex vertex=this;

        if(v.getId()==vertex.getId() && v.getId()!=-1) {
            return true;
        }

        if(v.getId()!=vertex.getId()) {
            return false;
        }

        if(v.idColumns!=null && vertex.idColumns!=null){
            for(String idColumn : idColumns){
                Object p1=v.getProperties().get(idColumn);
                Object p2=vertex.getProperties().get(idColumn);
                if(p1==null && p2==null){
                    continue;
                }
                if(p1==null && p2!=null){
                    return false;
                    }
                if(p1!=null && p2==null){
                    return false;
                }
                if(!p1.equals(p2)){
                    return false;
                }
            }
            return true;
        }

        if(v!=null && vertex!=null && v.getName()!=null && vertex.getName()!=null &&
                v.getName().equals(vertex.getName())){
            Object o1=v.getProperties().get("tag");
            Object o2=vertex.getProperties().get("tag");
            if(o1==null && o2==null) return true;
            if((o1!=null && o2!=null) && o1.toString().equals(o2.toString())) return true;
        }

        return flag;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy