1 /*
2  * Copyright (C) 2011 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 in a guice dependency graph.
23  *
24  * @author bojand@google.com (Bojan Djordjevic)
25  * @since 4.0
26  */
27 public abstract class Edge {
28   private final NodeId fromId;
29   private final NodeId toId;
30 
Edge(NodeId fromId, NodeId toId)31   protected Edge(NodeId fromId, NodeId toId) {
32     this.fromId = fromId;
33     this.toId = toId;
34   }
35 
getFromId()36   public NodeId getFromId() {
37     return fromId;
38   }
39 
getToId()40   public NodeId getToId() {
41     return toId;
42   }
43 
44   @Override
equals(Object obj)45   public boolean equals(Object obj) {
46     if (!(obj instanceof Edge)) {
47       return false;
48     }
49     Edge other = (Edge) obj;
50     return Objects.equal(fromId, other.fromId) && Objects.equal(toId, other.toId);
51   }
52 
53   @Override
hashCode()54   public int hashCode() {
55     return Objects.hashCode(fromId, toId);
56   }
57 
58   /**
59    * Returns a copy of the edge with new node IDs.
60    *
61    * @param fromId new ID of the 'from' node
62    * @param toId new ID of the 'to' node
63    * @return copy of the edge with the new node IDs
64    */
copy(NodeId fromId, NodeId toId)65   public abstract Edge copy(NodeId fromId, NodeId toId);
66 }
67