001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.lib.common.graph;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018:
019: public class Edge {
020: private int cost;
021: private int edgeNumber;
022: @NotNull
023: private Vertex fromVertex;
024: @NotNull
025: private Vertex toVertex;
026:
027: public Edge(@NotNull
028: Vertex fromVertex, @NotNull
029: Vertex toVertex, int cost) {
030: this .cost = cost;
031: this .fromVertex = fromVertex;
032: this .toVertex = toVertex;
033:
034: attachToVertices();
035: }
036:
037: public void attachToVertices() {
038: fromVertex.getIncidenceContainer().addOutIncidentEdge(this );
039: toVertex.getIncidenceContainer().addInIncidentEdge(this );
040: }
041:
042: public void detachFromVertices() {
043: fromVertex.getIncidenceContainer().removeOutIncidentEdge(this );
044: toVertex.getIncidenceContainer().removeInIncidentEdge(this );
045: }
046:
047: @NotNull
048: public Vertex getFromVertex() {
049: return fromVertex;
050: }
051:
052: public void setFromVertex(@NotNull
053: Vertex fromVertex) {
054: this .fromVertex = fromVertex;
055: }
056:
057: @NotNull
058: public Vertex getToVertex() {
059: return toVertex;
060: }
061:
062: public void setToVertex(@NotNull
063: Vertex toVertex) {
064: this .toVertex = toVertex;
065: }
066:
067: public int getCost() {
068: return cost;
069: }
070:
071: public boolean equals(@Nullable
072: Object o) {
073: if (!(o instanceof Edge))
074: return false;
075:
076: Edge edge = (Edge) o;
077:
078: if (!fromVertex.equals(edge.fromVertex))
079: return false;
080: return toVertex.equals(edge.toVertex);
081:
082: }
083:
084: public int hashCode() {
085: int result;
086: result = fromVertex.hashCode();
087: result = 29 * result + toVertex.hashCode();
088: return result;
089: }
090:
091: @NotNull
092: public String toString() {
093: //noinspection ObjectToString
094: return fromVertex + " --> " + toVertex;
095: }
096:
097: public int getEdgeNumber() {
098: return edgeNumber;
099: }
100:
101: public void setEdgeNumber(int edgeNumber) {
102: this.edgeNumber = edgeNumber;
103: }
104: }
|