KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > GraphEdge


1 package org.apache.ojb.broker;
2
3
4 /**
5  * GraphNode and GraphEdge model oriented graph with named nodes.
6  * In this case there are two relations between two classes.
7  * @author Oleg Nitz
8  */

9 public class GraphEdge implements java.io.Serializable JavaDoc
10 {
11     private int id;
12     private int sourceId;
13     private int sinkId;
14     private GraphNode source;
15     private GraphNode sink;
16
17     public GraphEdge()
18     {
19     }
20
21     public GraphEdge(int id, int sourceId, int sinkId)
22     {
23         this.id = id;
24         this.sourceId = sourceId;
25         this.sinkId = sinkId;
26     }
27
28     public GraphEdge(GraphNode source, GraphNode sink)
29     {
30         source.addOutgoingEdge(this);
31         sink.addIncomingEdge(this);
32         
33         // how could it ever work without this:
34
this.source = source;
35         this.sourceId = source.getId();
36         this.sink = sink;
37         this.sinkId = sink.getId();
38         
39     }
40
41     public int getSourceId()
42     {
43         return sourceId;
44     }
45
46     public int getSinkId()
47     {
48         return sinkId;
49     }
50
51     public GraphNode getSource()
52     {
53         return source;
54     }
55
56     public GraphNode getSink()
57     {
58         return sink;
59     }
60
61     public int getId()
62     {
63         return id;
64     }
65
66     public void setSourceId(int sourceId)
67     {
68         this.sourceId = sourceId;
69     }
70
71     public void setSinkId(int sinkId)
72     {
73         this.sinkId = sinkId;
74     }
75
76     public void setSource(GraphNode source)
77     {
78         this.source = source;
79     }
80
81     public void setSink(GraphNode sink)
82     {
83         this.sink = sink;
84     }
85
86     public void setId(int id)
87     {
88         this.id = id;
89     }
90
91     public String JavaDoc toString()
92     {
93         return "(" + (source == null ? "null" : source.getName()) + " -> "
94                 + (sink == null ? "null" : (sink == source ? sink.getName() : sink.toString())) + ")";
95     }
96 }
97
Popular Tags