blob: 9025d2e599fb8b6d15d9725f320433ca4d64eb32 [file] [log] [blame]
Thomas Vachuskaf9c84362015-04-15 11:20:45 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
16package org.onlab.stc;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.graph.AbstractEdge;
20
21import java.util.Objects;
22
23/**
24 * Representation of a dependency from one step on completion of another.
25 */
26public class Dependency extends AbstractEdge<Step> {
27
28 private boolean isSoft;
29
30 /**
31 * Creates a new edge between the specified source and destination vertexes.
32 *
33 * @param src source vertex
34 * @param dst destination vertex
35 * @param isSoft indicates whether this is a hard or soft dependency
36 */
37 public Dependency(Step src, Step dst, boolean isSoft) {
38 super(src, dst);
39 this.isSoft = isSoft;
40 }
41
42 /**
43 * Indicates whether this is a soft or hard dependency, i.e. one that
44 * requires successful completion of the dependency or just any completion.
45 *
46 * @return true if dependency is a soft one
47 */
48 public boolean isSoft() {
49 return isSoft;
50 }
51
52 @Override
53 public int hashCode() {
54 return 31 * super.hashCode() + Objects.hash(isSoft);
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59 if (this == obj) {
60 return true;
61 }
62 if (obj instanceof Dependency) {
63 final Dependency other = (Dependency) obj;
64 return super.equals(other) && Objects.equals(this.isSoft, other.isSoft);
65 }
66 return false;
67 }
68
69 @Override
70 public String toString() {
71 return MoreObjects.toStringHelper(this)
72 .add("name", src().name())
73 .add("requires", dst().name())
74 .add("isSoft", isSoft)
75 .toString();
76 }
77}