Meids Graph

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package meids.

graphs; import java.io.Serializable; import java.util.Vector; /** * * @author Student */ public class Graph implements Serializable { private Vector<Node> nodes; private Node start0,start1; public Vector<Node> getNodes() { return nodes; } public void setNodes(Vector<Node> nodes) { this.nodes = nodes; } public Node getStart0() { return start0; } public void setStart0(Node start0) { this.start0 = start0; } public Node getStart1() { return start1; } public void setStart1(Node start1) { this.start1 = start1; } public void addNode(Node n) { if(this.getNodes()==null) this.setNodes(new Vector<Node>()); this.getNodes().add(n); } public Node removeNode(Node n) { if(this.getNodes().contains(n)) this.getNodes().remove(n); else return null; return n; } } /* * To change this template, choose Tools | Templates

* and open the template in the editor. */ package meids.graphs; import java.io.Serializable; /** * * @author Student */ public class Link implements Serializable { private Node from,to; public Link(Node from, Node to) { this.from = from; this.to = to; } public Node getFrom() { return from; } public void setFrom(Node from) { this.from = from; } public Node getTo() { return to; } public void setTo(Node to) { this.to = to; } } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package meids.graphs; import java.io.Serializable; import java.util.Vector; /** * * @author Student */ public class Node implements Serializable { private String label; private Vector<Link> links; public String getLabel() { return label; }

public void setLabel(String label) { this.label = label; } public Vector<Link> getLinks() { return links; } public void setLinks(Vector<Link> links) { this.links = links; } public void addLink(Link l) { if(this.getLinks()==null) this.setLinks(new Vector<Link>()); this.getLinks().add(l); } public Link removeLink(Link l) { if(this.getLinks().contains(l)) this.getLinks().remove(l); else return null; return l; } @Override public String toString() { return this.label; } }

You might also like