tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 1 | package org.onlab.graph; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 5 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 6 | |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 7 | /** |
| 8 | * Test edge. |
| 9 | */ |
| 10 | public class TestEdge extends AbstractEdge<TestVertex> { |
| 11 | |
| 12 | private final double weight; |
| 13 | |
| 14 | /** |
| 15 | * Creates a new edge between the specified source and destination vertexes. |
| 16 | * |
| 17 | * @param src source vertex |
| 18 | * @param dst destination vertex |
| 19 | * @param weight edge weight |
| 20 | */ |
| 21 | public TestEdge(TestVertex src, TestVertex dst, double weight) { |
| 22 | super(src, dst); |
| 23 | this.weight = weight; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Returns the edge weight. |
| 28 | * |
| 29 | * @return edge weight |
| 30 | */ |
| 31 | public double weight() { |
| 32 | return weight; |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public int hashCode() { |
| 37 | return 31 * super.hashCode() + Objects.hash(weight); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public boolean equals(Object obj) { |
| 42 | if (obj instanceof TestEdge) { |
| 43 | final TestEdge other = (TestEdge) obj; |
| 44 | return super.equals(obj) && Objects.equals(this.weight, other.weight); |
| 45 | } |
| 46 | return false; |
| 47 | } |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 48 | |
| 49 | @Override |
| 50 | public String toString() { |
| 51 | return toStringHelper(this).add("src", src()).add("dst", dst()). |
| 52 | add("weight", weight).toString(); |
| 53 | } |
| 54 | |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 55 | } |