001package com.hfg.network; 002 003import com.hfg.util.CompareUtil; 004 005//------------------------------------------------------------------------------ 006/** 007 Representation of a network edge. 008 <div> 009 @author J. Alex Taylor, hairyfatguy.com 010 </div> 011 */ 012//------------------------------------------------------------------------------ 013// com.hfg Library 014// 015// This library is free software; you can redistribute it and/or 016// modify it under the terms of the GNU Lesser General Public 017// License as published by the Free Software Foundation; either 018// version 2.1 of the License, or (at your option) any later version. 019// 020// This library is distributed in the hope that it will be useful, 021// but WITHOUT ANY WARRANTY; without even the implied warranty of 022// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 023// Lesser General Public License for more details. 024// 025// You should have received a copy of the GNU Lesser General Public 026// License along with this library; if not, write to the Free Software 027// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 028// 029// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 030// jataylor@hairyfatguy.com 031//------------------------------------------------------------------------------ 032 033public class Edge<T> implements Comparable<Edge> 034{ 035 public T mFrom; 036 public T mTo; 037 038 public Float mDistance; 039 040 041 //########################################################################## 042 // CONSTRUCTORS 043 //########################################################################## 044 045 //-------------------------------------------------------------------------- 046 public Edge(T inFrom, T inTo) 047 { 048 mFrom = inFrom; 049 mTo = inTo; 050 } 051 052 //-------------------------------------------------------------------------- 053 public Edge(T inFrom, T inTo, Float inDistance) 054 { 055 this(inFrom, inTo); 056 mDistance = inDistance; 057 } 058 059 //########################################################################## 060 // PUBLIC METHODS 061 //########################################################################## 062 063 //-------------------------------------------------------------------------- 064 @Override 065 public String toString() 066 { 067 return mFrom + " --> " + mTo + ": " + mDistance; 068 } 069 070 //-------------------------------------------------------------------------- 071 public Edge<T> setFrom(T inValue) 072 { 073 mFrom = inValue; 074 return this; 075 } 076 077 //-------------------------------------------------------------------------- 078 public T getFrom() 079 { 080 return mFrom; 081 } 082 083 //-------------------------------------------------------------------------- 084 public Edge<T> setTo(T inValue) 085 { 086 mTo = inValue; 087 return this; 088 } 089 090 //-------------------------------------------------------------------------- 091 public T getTo() 092 { 093 return mTo; 094 } 095 096 //-------------------------------------------------------------------------- 097 public Float getDistance() 098 { 099 return mDistance; 100 } 101 102 //-------------------------------------------------------------------------- 103 public Edge setDistance(Float inValue) 104 { 105 mDistance = inValue; 106 return this; 107 } 108 109 //-------------------------------------------------------------------------- 110 public void switchDirection() 111 { 112 T tmp = mTo; 113 mTo = mFrom; 114 mFrom = tmp; 115 } 116 117 //-------------------------------------------------------------------------- 118 public int compareTo(Edge inEdge2) 119 { 120 int result = 0; 121 122 if (inEdge2 != null) 123 { 124 result = CompareUtil.compare(getDistance(), inEdge2.getDistance()); 125 } 126 else 127 { 128 result = -1; 129 } 130 131 return result; 132 } 133}