1/**
2 * Copyright (C) 2008 Google Inc.
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 */
16
17package com.google.inject.grapher;
18
19import com.google.common.base.Objects;
20import com.google.inject.spi.InjectionPoint;
21
22/**
23 * Edge from a class or {@link InjectionPoint} to the interface node that will satisfy the
24 * dependency.
25 *
26 * @author phopkins@gmail.com (Pete Hopkins)
27 * @since 4.0 (since 2.0 as an interface)
28 */
29public class DependencyEdge extends Edge {
30  /**
31   * Injection point to which this dependency belongs, or null if the dependency isn't attached to a
32   * particular injection point.
33   */
34  private final InjectionPoint injectionPoint;
35
36  public DependencyEdge(NodeId fromId, NodeId toId, InjectionPoint injectionPoint) {
37    super(fromId, toId);
38    this.injectionPoint = injectionPoint;
39  }
40
41  public InjectionPoint getInjectionPoint() {
42    return injectionPoint;
43  }
44
45  @Override public boolean equals(Object obj) {
46    if (!(obj instanceof DependencyEdge)) {
47      return false;
48    }
49    DependencyEdge other = (DependencyEdge) obj;
50    return super.equals(other) && Objects.equal(injectionPoint, other.injectionPoint);
51  }
52
53  @Override public int hashCode() {
54    return 31 * super.hashCode() + Objects.hashCode(injectionPoint);
55  }
56
57  @Override public String toString() {
58    return "DependencyEdge{fromId=" + getFromId() + " toId=" + getToId()
59        + " injectionPoint=" + injectionPoint + "}";
60  }
61
62  @Override public Edge copy(NodeId fromId, NodeId toId) {
63    return new DependencyEdge(fromId, toId, injectionPoint);
64  }
65}
66