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 
17 package com.google.inject.grapher;
18 
19 import com.google.common.base.Objects;
20 import 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  */
29 public 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 
DependencyEdge(NodeId fromId, NodeId toId, InjectionPoint injectionPoint)36   public DependencyEdge(NodeId fromId, NodeId toId, InjectionPoint injectionPoint) {
37     super(fromId, toId);
38     this.injectionPoint = injectionPoint;
39   }
40 
getInjectionPoint()41   public InjectionPoint getInjectionPoint() {
42     return injectionPoint;
43   }
44 
45   @Override
equals(Object obj)46   public boolean equals(Object obj) {
47     if (!(obj instanceof DependencyEdge)) {
48       return false;
49     }
50     DependencyEdge other = (DependencyEdge) obj;
51     return super.equals(other) && Objects.equal(injectionPoint, other.injectionPoint);
52   }
53 
54   @Override
hashCode()55   public int hashCode() {
56     return 31 * super.hashCode() + Objects.hashCode(injectionPoint);
57   }
58 
59   @Override
toString()60   public String toString() {
61     return "DependencyEdge{fromId="
62         + getFromId()
63         + " toId="
64         + getToId()
65         + " injectionPoint="
66         + injectionPoint
67         + "}";
68   }
69 
70   @Override
copy(NodeId fromId, NodeId toId)71   public Edge copy(NodeId fromId, NodeId toId) {
72     return new DependencyEdge(fromId, toId, injectionPoint);
73   }
74 }
75