📄 wire.java
字号:
package dk.itu.nulx30.networkModel;
import dk.itu.nulx30.eventSimulation.EventLocation;
import dk.itu.nulx30.eventSimulation.exceptions.IllegalTimeException;
import dk.itu.nulx30.graph.Edge;
import dk.itu.nulx30.networkModel.exceptions.UninitializedWireException;
/**
* Wire represents the physical medium over which packages are transferred from
* router to router. When a package is transferred through a wire it experinces
* a <code>delay</code>, which is the wires bandwidth normalized to a Integer.
* A low delay values represents a high bandwidth and a high delay represents a
* low bandwidth. A wire connects two routers in that sence that it is contained
* in a collection of wires in a <code>Router</code> object and only explicitly
* contains a reference to the <code>Router</code> connected to the
* <code>Router</code> in which it is contained.
*
* @author Jacob Wahl Winther
* @author Mikkel Bundgaard
* @author Troels C. Damgaard
* @author Federico Decara
*/
public class Wire extends Edge implements EventLocation {
/** Time for next event */
private double nextEvent = 0;
/**
* Public constructor, that creates a <code>Wire</code> with a given
* <code>targetRouter</code> and a <code>wireDelay</code>. A <code>Wire</code>
* object should be added to a router object, because it is implicitly
* connected to the router in which wire collection it is contained.
*
* @param sourceRouter the origin of the wire
* @param targetRouter the destination of the wire
* @param wireDelay the delay of the wire
* @exception UninitializedWireException this exception is thrown if
* <code>targetRouter</code> is null
*/
public Wire( Router sourceRouter, Router targetRouter, int wireDelay ) throws
UninitializedWireException {
super( sourceRouter, targetRouter, wireDelay );
if ( targetRouter == null ) {
throw new UninitializedWireException( "A wires targetRouter cannot be null" );
}
}
/**
* Sets the delay of the wire
*
* @param wireDelay the new delay of the wire
*/
public void setDelay( double wireDelay ) {
weight = wireDelay;
}
/**
* Return the delay of the wire
*
* @return the delay of the wire
*/
public double getDelay() {
return weight;
}
/**
* Return the target router of the wire
*
* @return target router of the wire
*/
public Router getTarget() {
return ( Router ) secondVertex;
}
/**
* Return the source router of the wire
*
* @return source router of the wire
*/
public Router getSource() {
return ( Router ) firstVertex;
}
/**
* Implementation of the <code>EventLocation</code> interface.
* <code>getNextEventTime()</code> returns the next event time of this wire.
*
* @return the next event time of the <code>Wire</code>
*/
public double getNextEventTime() {
return nextEvent;
}
/**
* Implementation of the <code>EventLocation</code> interface.
* <code>setNextEventTime()</code> sets the new next-event time.
*
* @param newEventTime the new next-event time.
*
* @exception IllegalTimeException this exception is thrown if the new
* next-event time is less than the old next-event time.
*/
public void setNextEventTime( double newEventTime ) throws IllegalTimeException {
if ( nextEvent > newEventTime ) {
throw new IllegalTimeException( "Wire eventTime: " + nextEvent +
" newEvent: " + newEventTime );
}
nextEvent = newEventTime;
}
/**
* Compares this wire to the specified object.
* The result is <code>true</code> if and only if the argument is not
* <code>null</code> and is a <code>Wire</code> object that represents
* the same wire as this object.
*
* @param o the object to compare this <code>Wire</code> against
*
* @return <code>true</code> if the <code>Wire</code> are equal;
* <code>false</code> otherwise
*/
public boolean equals( Object o ) {
Wire w = ( Wire ) o;
return w.getSource().equals( this.getSource() ) &&
w.getTarget().equals( this.getTarget() );
}
/**
* Provides a string representation of this <code>Wire</code>.
*
* @return a String representation of this <code>Wire</code>. The
* String contains the index of each of the routers at the end of the
* <code>Wire</code>.
*/
public String toString() {
return new StringBuffer( getSource().getIndex() + "/" +
getTarget().getIndex() ).toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -