• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
equals(Object obj)44   @Override public boolean equals(Object obj) {
45     if (!(obj instanceof Edge)) {
46       return false;
47     }
48     Edge other = (Edge) obj;
49     return Objects.equal(fromId, other.fromId) && Objects.equal(toId, other.toId);
50   }
51 
hashCode()52   @Override public int hashCode() {
53     return Objects.hashCode(fromId, toId);
54   }
55 
56   /**
57    * Returns a copy of the edge with new node IDs.
58    *
59    * @param fromId new ID of the 'from' node
60    * @param toId new ID of the 'to' node
61    * @return copy of the edge with the new node IDs
62    */
copy(NodeId fromId, NodeId toId)63   public abstract Edge copy(NodeId fromId, NodeId toId);
64 }
65