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

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

The newest version!
package com.datastax.graph;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * Anders Hong 6/24/2015.
 */
public class Graph {
    private long id;
    private String name;
    private List vertices=new ArrayList<>();
    private List edges=new ArrayList<>();

    public String getName() {
        return name;
    }

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

    public List getVertices() {
        return vertices;
    }

    public void setVertices(List vertices) {
        this.vertices = vertices;
    }

    public List getEdges() {
        return edges;
    }

    public void setEdges(List edges) {
        this.edges = edges;
    }

    public void addVertex(Vertex vertex){
        if(!containsVertex(vertex)){
            vertices.add(vertex);
        }
    }

    public boolean containsVertex(Vertex vertex){
        boolean flag=false;
        for(Vertex v : vertices){
            if(v.equals(vertex)) return true;
        }
        return flag;
    }

    public void addEdge(Edge edge){
        if(!containsEdge(edge)){
            if(edge!=null && edge.getProperties().size()>0){
                edge.addPropertiesToList(edge.getProperties());
                edge.addEdgeIds(edge.getId());
            }
            edges.add(edge);
        }
    }

    public boolean containsEdge(Edge edge){
        boolean flag=false;
        for(Edge e : edges){
            if(edge.getStart()>=0 && edge.getEnd()>=0
                    && edge.getStart()!=edge.getEnd()) {
                if (e.getStart() == edge.getStart() &&
                        e.getEnd() == edge.getEnd() &&
                        e.getType().equals(edge.getType())) {
                    flag = true;

                    if(edge!=null && edge.getProperties().size()>0){
                        e.addPropertiesToList(edge.getProperties());
                        e.addEdgeIds(edge.getId());

                        if((e.getProperties()==null || e.getProperties().size()==0)){
                            e.setProperties(edge.getProperties());
                        }
                    }
                    break;
                }
            }

            if(e.getStartName()!=null && edge.getEndName()!=null) {
                if (e.getStartName().equals(edge.getStartName()) &&
                        e.getEndName().equals(edge.getEndName()) &&
                        e.getType().equals(edge.getType())) {
                    flag = true;
                    if(edge!=null && edge.getProperties().size()>0){
                        e.addPropertiesToList(edge.getProperties());
                        e.addEdgeIds(edge.getId());

                        if((e.getProperties()==null || e.getProperties().size()==0)){
                            e.setProperties(edge.getProperties());
                        }
                    }
                    break;
                }
            }
        }
        return flag;
    }

    public long getId() {
        return id;
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy