001package org.biopax.paxtools.query.model; 002 003/** 004 * The base class for an edge in the traversed graph. 005 * 006 * @author Ozgun Babur 007 */ 008public abstract class AbstractEdge implements Edge 009{ 010 private Node source; 011 private Node target; 012 private Graph graph; 013 014 /** 015 * Edges should know their source and target nodes, and their graph. 016 * 017 * @param source source node 018 * @param target target node 019 * @param graph graph 020 */ 021 public AbstractEdge(Node source, Node target, Graph graph) 022 { 023 this.source = source; 024 this.target = target; 025 this.graph = graph; 026 } 027 028 /** 029 * @return The target node 030 */ 031 public Node getTargetNode() 032 { 033 return target; 034 } 035 036 /** 037 * @return The source node 038 */ 039 public Node getSourceNode() 040 { 041 return source; 042 } 043 044 /** 045 * @return The owner graph 046 */ 047 public Graph getGraph() 048 { 049 return graph; 050 } 051 052 /** 053 * @return Key to use in a map 054 */ 055 public String getKey() 056 { 057 return source.getKey() + "|" + target.getKey(); 058 } 059 060 @Override 061 public int hashCode() 062 { 063 return source.hashCode() + target.hashCode() + graph.hashCode(); 064 } 065 066 @Override 067 /** 068 * Two edges are equal if source, target and owner graphs are identical. 069 */ 070 public boolean equals(Object obj) 071 { 072 if (obj instanceof AbstractEdge) 073 { 074 AbstractEdge e = (AbstractEdge) obj; 075 return source == e.getSourceNode() && 076 target == e.getTargetNode() && 077 graph == e.getGraph(); 078 } 079 return false; 080 } 081 082 /** 083 * Edges are positive by default. 084 * @return 1 indicating a positive edge 085 */ 086 @Override 087 public int getSign() 088 { 089 return 1; 090 } 091 092 /** 093 * Does nothing yet. 094 */ 095 public void clear() 096 { 097 } 098}