blob: b53f2f22dd7a39959e498c40a2ce640435108222 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tome3489412014-08-29 02:30:38 -070019package org.onlab.graph;
20
21import java.util.Objects;
22
tomeadbb462014-09-07 16:10:19 -070023import static com.google.common.base.MoreObjects.toStringHelper;
tom144de692014-08-29 11:38:44 -070024
tome3489412014-08-29 02:30:38 -070025/**
26 * Test edge.
27 */
28public class TestEdge extends AbstractEdge<TestVertex> {
29
30 private final double weight;
31
32 /**
33 * Creates a new edge between the specified source and destination vertexes.
34 *
35 * @param src source vertex
36 * @param dst destination vertex
37 * @param weight edge weight
38 */
39 public TestEdge(TestVertex src, TestVertex dst, double weight) {
40 super(src, dst);
41 this.weight = weight;
42 }
43
44 /**
45 * Returns the edge weight.
46 *
47 * @return edge weight
48 */
49 public double weight() {
50 return weight;
51 }
52
53 @Override
54 public int hashCode() {
55 return 31 * super.hashCode() + Objects.hash(weight);
56 }
57
58 @Override
59 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070060 if (this == obj) {
61 return true;
62 }
tome3489412014-08-29 02:30:38 -070063 if (obj instanceof TestEdge) {
64 final TestEdge other = (TestEdge) obj;
65 return super.equals(obj) && Objects.equals(this.weight, other.weight);
66 }
67 return false;
68 }
tom144de692014-08-29 11:38:44 -070069
70 @Override
71 public String toString() {
72 return toStringHelper(this).add("src", src()).add("dst", dst()).
73 add("weight", weight).toString();
74 }
75
tome3489412014-08-29 02:30:38 -070076}