001: /*
002: * Generic graph library
003: * Copyright (C) 2000,2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.graph;
021:
022: /**
023: * GraphEdge implementation for use with AbstractGraph.
024: *
025: * @see GraphEdge
026: * @see AbstractGraph
027: * @see AbstractVertex
028: * @author David Hovemeyer
029: */
030: public class AbstractEdge<ActualEdgeType extends AbstractEdge<ActualEdgeType, VertexType>, VertexType extends AbstractVertex<ActualEdgeType, VertexType>>
031: implements GraphEdge<ActualEdgeType, VertexType> {
032:
033: private VertexType source;
034: private VertexType target;
035: private int label;
036: private ActualEdgeType nextOutgoingEdge;
037: private ActualEdgeType nextIncomingEdge;
038:
039: /**
040: * Constructor.
041: * @param source the source vertex of the edge
042: * @param target the target vertex of the edge
043: */
044: public AbstractEdge(VertexType source, VertexType target) {
045: this .source = source;
046: this .target = target;
047: }
048:
049: public VertexType getSource() {
050: return source;
051: }
052:
053: public VertexType getTarget() {
054: return target;
055: }
056:
057: public int getLabel() {
058: return label;
059: }
060:
061: public void setLabel(int label) {
062: this .label = label;
063: }
064:
065: @Override
066: public int hashCode() {
067: return source.hashCode() + target.hashCode() * 3;
068: }
069:
070: @Override
071: public boolean equals(Object o) {
072: if (!(o instanceof AbstractEdge))
073: return false;
074: ActualEdgeType other = (ActualEdgeType) o;
075: return source.equals(other.source)
076: && target.equals(other.target);
077: }
078:
079: public int compareTo(ActualEdgeType other) {
080: int cmp = source.compareTo(other.source);
081: if (cmp != 0)
082: return cmp;
083: return target.compareTo(other.target);
084: }
085:
086: void setNextOutgoingEdge(ActualEdgeType edge) {
087: nextOutgoingEdge = edge;
088: }
089:
090: ActualEdgeType getNextOutgoingEdge() {
091: return nextOutgoingEdge;
092: }
093:
094: void setNextIncomingEdge(ActualEdgeType edge) {
095: nextIncomingEdge = edge;
096: }
097:
098: ActualEdgeType getNextIncomingEdge() {
099: return nextIncomingEdge;
100: }
101:
102: }
103:
104: // vim:ts=4
|