1 | /* |
2 | * $Id: Edge.java 5865 2005-10-25 21:02:06Z dfs $ |
3 | * |
4 | * Copyright 2004 Daniel F. Savarese |
5 | * Copyright 2005 Savarese Software Research |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
10 | * |
11 | * https://www.savarese.com/software/ApacheLicense-2.0 |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
18 | */ |
19 | |
20 | package com.savarese.algorithms.graph; |
21 | |
22 | /** |
23 | * An Edge represents a directed or undirected connection between two |
24 | * vertices with an associated weight. The vertices can be |
25 | * interpreted as source and destination in the case of a directed |
26 | * edge or simply as endpoints in the case of an undirected edge. |
27 | * |
28 | * @author <a href="https://www.savarese.com/">Daniel F. Savarese</a> |
29 | */ |
30 | |
31 | public class Edge<V, W> { |
32 | |
33 | private W __weight; |
34 | private V __src, __dest; |
35 | |
36 | |
37 | /** |
38 | * Creates an Edge between source and destination vertices, |
39 | * assigning a weight to the link. |
40 | * |
41 | * @param src The source vertex. |
42 | * @param dest The destination vertex. |
43 | * @param weight The weight associated with the edge. |
44 | */ |
45 | public Edge(V src, V dest, W weight) { |
46 | __src = src; |
47 | __dest = dest; |
48 | __weight = weight; |
49 | } |
50 | |
51 | |
52 | /** |
53 | * Returns the source vertex. |
54 | * @return The source vertex. |
55 | */ |
56 | public V getSource() { |
57 | return __src; |
58 | } |
59 | |
60 | |
61 | /** |
62 | * Returns the destination vertex. |
63 | * |
64 | * @return The destination vertex. |
65 | */ |
66 | public V getDestination() { |
67 | return __dest; |
68 | } |
69 | |
70 | |
71 | /** |
72 | * Returns the edge weight. |
73 | * |
74 | * @return The edge weight. |
75 | */ |
76 | public W getWeight() { |
77 | return __weight; |
78 | } |
79 | |
80 | } |