1b71955639ab617e0a4115b1439c8b9982227a018sberlin/** 2b71955639ab617e0a4115b1439c8b9982227a018sberlin * Copyright (C) 2011 Google Inc. 3b71955639ab617e0a4115b1439c8b9982227a018sberlin * 4b71955639ab617e0a4115b1439c8b9982227a018sberlin * Licensed under the Apache License, Version 2.0 (the "License"); 5b71955639ab617e0a4115b1439c8b9982227a018sberlin * you may not use this file except in compliance with the License. 6b71955639ab617e0a4115b1439c8b9982227a018sberlin * You may obtain a copy of the License at 7b71955639ab617e0a4115b1439c8b9982227a018sberlin * 8b71955639ab617e0a4115b1439c8b9982227a018sberlin * http://www.apache.org/licenses/LICENSE-2.0 9b71955639ab617e0a4115b1439c8b9982227a018sberlin * 10b71955639ab617e0a4115b1439c8b9982227a018sberlin * Unless required by applicable law or agreed to in writing, software 11b71955639ab617e0a4115b1439c8b9982227a018sberlin * distributed under the License is distributed on an "AS IS" BASIS, 12b71955639ab617e0a4115b1439c8b9982227a018sberlin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b71955639ab617e0a4115b1439c8b9982227a018sberlin * See the License for the specific language governing permissions and 14b71955639ab617e0a4115b1439c8b9982227a018sberlin * limitations under the License. 15b71955639ab617e0a4115b1439c8b9982227a018sberlin */ 16b71955639ab617e0a4115b1439c8b9982227a018sberlin 17b71955639ab617e0a4115b1439c8b9982227a018sberlinpackage com.google.inject.grapher; 18b71955639ab617e0a4115b1439c8b9982227a018sberlin 19b71955639ab617e0a4115b1439c8b9982227a018sberlinimport com.google.common.base.Objects; 20b71955639ab617e0a4115b1439c8b9982227a018sberlin 21b71955639ab617e0a4115b1439c8b9982227a018sberlin/** 22b71955639ab617e0a4115b1439c8b9982227a018sberlin * Edge in a guice dependency graph. 23b71955639ab617e0a4115b1439c8b9982227a018sberlin * 24b71955639ab617e0a4115b1439c8b9982227a018sberlin * @author bojand@google.com (Bojan Djordjevic) 25bac730fa1b717351736182034aff62827a383090Ben McCann * @since 4.0 26b71955639ab617e0a4115b1439c8b9982227a018sberlin */ 27b71955639ab617e0a4115b1439c8b9982227a018sberlinpublic abstract class Edge { 28b71955639ab617e0a4115b1439c8b9982227a018sberlin private final NodeId fromId; 29b71955639ab617e0a4115b1439c8b9982227a018sberlin private final NodeId toId; 30b71955639ab617e0a4115b1439c8b9982227a018sberlin 31b71955639ab617e0a4115b1439c8b9982227a018sberlin protected Edge(NodeId fromId, NodeId toId) { 32b71955639ab617e0a4115b1439c8b9982227a018sberlin this.fromId = fromId; 33b71955639ab617e0a4115b1439c8b9982227a018sberlin this.toId = toId; 34b71955639ab617e0a4115b1439c8b9982227a018sberlin } 35b71955639ab617e0a4115b1439c8b9982227a018sberlin 36b71955639ab617e0a4115b1439c8b9982227a018sberlin public NodeId getFromId() { 37b71955639ab617e0a4115b1439c8b9982227a018sberlin return fromId; 38b71955639ab617e0a4115b1439c8b9982227a018sberlin } 39b71955639ab617e0a4115b1439c8b9982227a018sberlin 40b71955639ab617e0a4115b1439c8b9982227a018sberlin public NodeId getToId() { 41b71955639ab617e0a4115b1439c8b9982227a018sberlin return toId; 42b71955639ab617e0a4115b1439c8b9982227a018sberlin } 43b71955639ab617e0a4115b1439c8b9982227a018sberlin 44b71955639ab617e0a4115b1439c8b9982227a018sberlin @Override public boolean equals(Object obj) { 45b71955639ab617e0a4115b1439c8b9982227a018sberlin if (!(obj instanceof Edge)) { 46b71955639ab617e0a4115b1439c8b9982227a018sberlin return false; 47b71955639ab617e0a4115b1439c8b9982227a018sberlin } 48b71955639ab617e0a4115b1439c8b9982227a018sberlin Edge other = (Edge) obj; 49b71955639ab617e0a4115b1439c8b9982227a018sberlin return Objects.equal(fromId, other.fromId) && Objects.equal(toId, other.toId); 50b71955639ab617e0a4115b1439c8b9982227a018sberlin } 51b71955639ab617e0a4115b1439c8b9982227a018sberlin 52b71955639ab617e0a4115b1439c8b9982227a018sberlin @Override public int hashCode() { 53b71955639ab617e0a4115b1439c8b9982227a018sberlin return Objects.hashCode(fromId, toId); 54b71955639ab617e0a4115b1439c8b9982227a018sberlin } 55b71955639ab617e0a4115b1439c8b9982227a018sberlin 56b71955639ab617e0a4115b1439c8b9982227a018sberlin /** 57b71955639ab617e0a4115b1439c8b9982227a018sberlin * Returns a copy of the edge with new node IDs. 58b71955639ab617e0a4115b1439c8b9982227a018sberlin * 59b71955639ab617e0a4115b1439c8b9982227a018sberlin * @param fromId new ID of the 'from' node 60b71955639ab617e0a4115b1439c8b9982227a018sberlin * @param toId new ID of the 'to' node 61b71955639ab617e0a4115b1439c8b9982227a018sberlin * @return copy of the edge with the new node IDs 62b71955639ab617e0a4115b1439c8b9982227a018sberlin */ 63b71955639ab617e0a4115b1439c8b9982227a018sberlin public abstract Edge copy(NodeId fromId, NodeId toId); 64b71955639ab617e0a4115b1439c8b9982227a018sberlin} 65