Package com.amalgamasimulation.trains
Class RailTrack
java.lang.Object
com.amalgamasimulation.trains.RailTrack
Rail track represents a bi-directional section of rail road between any two
rail nodes. All rail tracks are bi-directional and thus contain references to
two graph arcs: forward arc and backward arc. Rail track is considered to be
directed along its forward arc. The beginning of the rail track is at the
same position as the beginning of the track's forward arc.
- Author:
- Andrey Malykhanov, Andrey Korotin
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterHeadEntered(Train train) Callback that is called immediately after head of a train enters this track.protected voidbeforeTailExited(Train train) Callback that is called right before tail of a train exits this track.voidbook(BookingSlot bookingSlot) Inserts the specifiedBookingSlotinto the booking sequence.Returns the graph arc corresponding to backward direction of this track.Returns theBookingSequenceassociated with this track.getBookingSlots(BiPredicate<RailTrack, Object> considerBookedTracks) Returns a list ofBookingSlots that satisfy the specified condition.getCurrentTimeBooker(double atTime) Returns the booker associated with the booking slot that includes the specified time.Returns the graph arc corresponding to forward direction of this track.getFreeMovementGaps(BiPredicate<RailTrack, Object> considerBookedTracks) Returns anIntervalSetrepresenting the time intervals during which this track is not booked (i.e., free for movement).doubleReturns the length of the track, i.e.getName()Returns the name of this train.Returns a polyline representing the forward trajectory along the track.Returns the list of trains occupying (maybe partially) this track.booleanisFree()Checks if there are no trains on this track.toString()
-
Constructor Details
-
RailTrack
protected RailTrack(String name, Graph<RailNode, RailArc>.Arc forwardArc, Graph<RailNode, RailArc>.Arc backwardArc) Creates a new instance of a rail track using the forward and backward arcs specified. All rail tracks are bidirectional.- Parameters:
name- name of the rail trackforwardArc- forward arcbackwardArc- backward arc
-
-
Method Details
-
afterHeadEntered
Callback that is called immediately after head of a train enters this track.- Parameters:
train- train that enters the track
-
beforeTailExited
Callback that is called right before tail of a train exits this track.- Parameters:
train- train that exits the track
-
book
Inserts the specifiedBookingSlotinto the booking sequence.The slot is placed into the sequence according to its starting time.
- Parameters:
bookingSlot- the booking slot to insert into the sequence
-
getCurrentTimeBooker
Returns the booker associated with the booking slot that includes the specified time.If no slot covers the given point in time, this method returns
null.- Parameters:
atTime- the time for which to retrieve the active booker- Returns:
- the booker object at the specified time, or
nullif none is found
-
getFreeMovementGaps
Returns anIntervalSetrepresenting the time intervals during which this track is not booked (i.e., free for movement).The result is computed by excluding all intervals of bookings that satisfy the given
BiPredicate.- Parameters:
considerBookedTracks- a predicate determining which bookings should be considered as occupying the track; the first argument is thisRailTrack, and the second is the booker object- Returns:
- an
IntervalSetrepresenting free (unbooked) time intervals
-
getBookingSlots
Returns a list ofBookingSlots that satisfy the specified condition.This method filters the existing booking sequence according to the given
BiPredicate, which determines whether a booking made by a particular booker on thisRailTrackshould be considered.- Parameters:
considerBookedTracks- a predicate that tests whether a booking should be included; the first argument is thisRailTrack, and the second is the booker object- Returns:
- a list of booking slots that satisfy the specified condition
-
getName
Returns the name of this train.- Returns:
- name of this train
-
getPolyline
Returns a polyline representing the forward trajectory along the track.- Returns:
- polyline
-
getLength
public double getLength()Returns the length of the track, i.e. length of the polyline representing the forward or backward trajectory along the track, in pixels.- Returns:
- length of the track
-
getTrains
Returns the list of trains occupying (maybe partially) this track. The list is sorted by trains' offset from the beginning of this track.- Returns:
- list of trains occupying (maybe partially) this track
-
isFree
public boolean isFree()Checks if there are no trains on this track.- Returns:
trueif there are no trains on this track,falseotherwise
-
getForwardArc
Returns the graph arc corresponding to forward direction of this track.- Returns:
- forward graph arc
-
getBackwardArc
Returns the graph arc corresponding to backward direction of this track.- Returns:
- backward graph arc
-
toString
-
getBookingSequence
Returns theBookingSequenceassociated with this track.The booking sequence contains all
BookingSlots representing reservations or occupied time intervals on this track.- Returns:
- the
BookingSequencethat manages the booking slots for this track
-