KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > graph > Edge


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.util.graph;
23
24 /**
25  * A directed, weighted edge in a graph
26  *
27  * @author Scott.Stark@jboss.org
28  * @version $Revision$
29  */

30 public class Edge<T>
31 {
32    private Vertex<T> from;
33    private Vertex<T> to;
34    private int cost;
35    private boolean mark;
36
37    // Create an edge with 0 cost
38
public Edge(Vertex<T> one, Vertex<T> two)
39    {
40       from = one;
41       to = two;
42       cost = 0;
43       mark = false;
44    }
45
46    // Create an edge and define the cost
47
public Edge(Vertex<T> one, Vertex<T> two, int c)
48    {
49       from = one;
50       to = two;
51       cost = c;
52       mark = false;
53    }
54
55    public Vertex<T> getTo()
56    {
57       return to;
58    }
59
60    public Vertex<T> getFrom()
61    {
62       return from;
63    }
64
65    public int getCost()
66    {
67       return cost;
68    }
69
70    // Mark an edge
71
public void mark()
72    {
73       mark = true;
74    }
75
76    // Clear the mark
77
public void clearMark()
78    {
79       mark = false;
80    }
81
82    // Test the mark
83
public boolean isMarked()
84    {
85       return mark;
86    }
87
88    public String JavaDoc toString()
89    {
90       StringBuffer JavaDoc tmp = new StringBuffer JavaDoc("Edge[from: ");
91       tmp.append(from.getName());
92       tmp.append(",to: ");
93       tmp.append(to.getName());
94       tmp.append(", cost: ");
95       tmp.append(cost);
96       tmp.append("]");
97       return tmp.toString();
98    }
99 }
100
Popular Tags