KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > graph > AbstractEdge


1 /*
2  * Generic graph library
3  * Copyright (C) 2000,2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.graph;
21
22 /**
23  * GraphEdge implementation for use with AbstractGraph.
24  *
25  * @see GraphEdge
26  * @see AbstractGraph
27  * @see AbstractVertex
28  * @author David Hovemeyer
29  */

30 public class AbstractEdge
31         <
32         ActualEdgeType extends AbstractEdge<ActualEdgeType, VertexType>,
33         VertexType extends AbstractVertex<ActualEdgeType, VertexType>
34         > implements GraphEdge<ActualEdgeType, VertexType> {
35
36     private VertexType source;
37     private VertexType target;
38     private int label;
39     private ActualEdgeType nextOutgoingEdge;
40     private ActualEdgeType nextIncomingEdge;
41
42     /**
43      * Constructor.
44      * @param source the source vertex of the edge
45      * @param target the target vertex of the edge
46      */

47     public AbstractEdge(VertexType source, VertexType target) {
48         this.source = source;
49         this.target = target;
50     }
51
52     public VertexType getSource() {
53         return source;
54     }
55
56     public VertexType getTarget() {
57         return target;
58     }
59
60     public int getLabel() {
61         return label;
62     }
63
64     public void setLabel(int label) {
65         this.label = label;
66     }
67
68     public int hashCode() {
69         return source.hashCode() + target.hashCode()*3;
70     }
71     public boolean equals(Object JavaDoc o) {
72         if (!(o instanceof AbstractEdge)) return false;
73         ActualEdgeType other = (ActualEdgeType) o;
74         return source.equals(other.source) && target.equals(other.target);
75     }
76     public int compareTo(ActualEdgeType other) {
77         int cmp = source.compareTo(other.source);
78         if (cmp != 0)
79             return cmp;
80         return target.compareTo(other.target);
81     }
82
83     void setNextOutgoingEdge(ActualEdgeType edge) {
84         nextOutgoingEdge = edge;
85     }
86
87     ActualEdgeType getNextOutgoingEdge() {
88         return nextOutgoingEdge;
89     }
90
91     void setNextIncomingEdge(ActualEdgeType edge) {
92         nextIncomingEdge = edge;
93     }
94
95     ActualEdgeType getNextIncomingEdge() {
96         return nextIncomingEdge;
97     }
98
99 }
100
101 // vim:ts=4
102
Popular Tags