summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java
blob: cf0764bbc9a747d01d53b27404b407848700939a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package bjc.utils.graph;

/**
 * An edge in a weighted graph
 * 
 * @author ben
 *
 * @param <T>
 *            The type of the nodes in the graph
 */
public class Edge<T> {
	/**
	 * The distance from initial to terminal node
	 */
	private final int	distance;

	/**
	 * The initial and terminal nodes of this edge
	 */
	private final T		source, target;

	/**
	 * Create a new edge with set parameters
	 * 
	 * @param node1
	 *            The initial node of the edge
	 * @param node2
	 *            The terminal node of the edge
	 * @param distance
	 *            The distance between initial and terminal edge
	 */
	public Edge(T node1, T node2, int distance) {
		this.source = node1;
		this.target = node2;
		this.distance = distance;
	}

	/**
	 * Get the distance in this edge
	 * 
	 * @return The distance between the initial and terminal nodes of this
	 *         edge
	 */
	public int getDistance() {
		return distance;
	}

	/**
	 * Get the initial node of an edge
	 * 
	 * @return The initial node of this edge
	 */
	public T getSource() {
		return source;
	}

	/**
	 * Get the target node of an edge
	 * 
	 * @return The target node of this edge
	 */
	public T getTarget() {
		return target;
	}

	@Override
	public String toString() {
		return " first vertex " + source + " to vertex " + target
				+ " with distance: " + distance;
	}
}