• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 /**
22  * Edge that connects an interface to the type or instance that is bound to implement it.
23  *
24  * @author phopkins@gmail.com (Pete Hopkins)
25  * @since 4.0 (since 2.0 as an interface)
26  */
27 public class BindingEdge extends Edge {
28   /**
29    * Classification for what kind of binding this edge represents.
30    */
31   public enum Type {
32     /** Binding is to an instance or class of the binding's same type. */
33     NORMAL,
34     /** Binding is to an instance or class that provides the binding's type. */
35     PROVIDER,
36     /** Binding is to the interface for a constant of a different type. */
37     CONVERTED_CONSTANT
38   }
39 
40   private final Type type;
41 
BindingEdge(NodeId fromId, NodeId toId, Type type)42   public BindingEdge(NodeId fromId, NodeId toId, Type type) {
43     super(fromId, toId);
44     this.type = type;
45   }
46 
getType()47   public Type getType() {
48     return type;
49   }
50 
equals(Object obj)51   @Override public boolean equals(Object obj) {
52     if (!(obj instanceof BindingEdge)) {
53       return false;
54     }
55     BindingEdge other = (BindingEdge) obj;
56     return super.equals(other) && Objects.equal(type, other.type);
57   }
58 
hashCode()59   @Override public int hashCode() {
60     return 31 * super.hashCode() + Objects.hashCode(type);
61   }
62 
toString()63   @Override public String toString() {
64     return "BindingEdge{fromId=" + getFromId() + " toId=" + getToId() + " type=" + type + "}";
65   }
66 
copy(NodeId fromId, NodeId toId)67   @Override public Edge copy(NodeId fromId, NodeId toId) {
68     return new BindingEdge(fromId, toId, type);
69   }
70 }
71