blob: 7b487677199800e43d5cd73b683d99ce6dc54f6e [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
tome3489412014-08-29 02:30:38 -070016package org.onlab.graph;
17
18import java.util.Objects;
19
tomeadbb462014-09-07 16:10:19 -070020import static com.google.common.base.MoreObjects.toStringHelper;
tom144de692014-08-29 11:38:44 -070021
tome3489412014-08-29 02:30:38 -070022/**
23 * Test edge.
24 */
25public class TestEdge extends AbstractEdge<TestVertex> {
26
27 private final double weight;
28
29 /**
30 * Creates a new edge between the specified source and destination vertexes.
31 *
32 * @param src source vertex
33 * @param dst destination vertex
34 * @param weight edge weight
35 */
36 public TestEdge(TestVertex src, TestVertex dst, double weight) {
37 super(src, dst);
38 this.weight = weight;
39 }
40
41 /**
42 * Returns the edge weight.
43 *
44 * @return edge weight
45 */
46 public double weight() {
47 return weight;
48 }
49
50 @Override
51 public int hashCode() {
52 return 31 * super.hashCode() + Objects.hash(weight);
53 }
54
55 @Override
56 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070057 if (this == obj) {
58 return true;
59 }
tome3489412014-08-29 02:30:38 -070060 if (obj instanceof TestEdge) {
61 final TestEdge other = (TestEdge) obj;
62 return super.equals(obj) && Objects.equals(this.weight, other.weight);
63 }
64 return false;
65 }
tom144de692014-08-29 11:38:44 -070066
67 @Override
68 public String toString() {
69 return toStringHelper(this).add("src", src()).add("dst", dst()).
70 add("weight", weight).toString();
71 }
72
tome3489412014-08-29 02:30:38 -070073}