Class DefaultTransit
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.DefaultTransit
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>
,PropertyChangeProvider
,NamedBean
,Transit
public class DefaultTransit extends AbstractNamedBean implements Transit
A Transit is a group of Sections representing a specified path through a layout.A Transit may have the following states:
- IDLE
- available for assignment to a train
- ASSIGNED
- linked to a train in an
ActiveTrain
When assigned to a Transit, options may be set for the assigned Section. The Section and its options are kept in a
TransitSection
object.To accommodate passing sidings and other track features, there may be multiple Sections connecting two other Sections in a Transit. If so, one Section is assigned as primary, and the other connecting Sections are assigned as alternates.
A Section may be in a Transit more than once, for example if a train is to make two or more loops around a layout before going elsewhere.
A Transit is normally traversed in the forward direction, that is, the direction of increasing Section Numbers. When a Transit traversal is started up, it is always started in the forward direction. However, to accommodate point-to-point (back and forth) route designs, the direction of travel in a Transit may be "reversed". While the Transit direction is "reversed", the direction of travel is the direction of decreasing Section numbers. Whether a Transit is in the "reversed" direction is kept in the ActiveTrain using the Transit.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
-
Field Summary
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description DefaultTransit(java.lang.String systemName)
DefaultTransit(java.lang.String systemName, java.lang.String userName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTransitSection(TransitSection s)
Add a Section to this Transit.boolean
canBeResetWhenDone()
Check if this Transit is capable of continuous running.boolean
containsBlock(Block block)
Check if a Block is in this Transit.boolean
containsSection(Section s)
Check if a Section is in this Transit.java.lang.String
getBeanType()
For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.int
getBlockCount(Block block)
Get the number of times a Block is in this Transit.java.util.ArrayList<java.lang.Integer>
getBlockSeqList()
Get a list of sequence numbers in this Transit.java.util.ArrayList<java.lang.Integer>
getDestBlocksSeqList()
Get a list of destination Block sequence numbers in this Transit.java.util.ArrayList<Block>
getDestinationBlocksList(Block startBlock, boolean startInTransit)
Get a list of all destination blocks that can be reached from a specified starting block.int
getDirectionFromSectionAndSeq(Section s, int seq)
Get the direction of a Section in the transit from its sequence number.java.util.ArrayList<Block>
getEntryBlocksList()
Get a list of all entry Blocks to this Transit.java.util.ArrayList<Block>
getInternalBlocksList()
Get a list of all blocks internal to this Transit.int
getMaxSequence()
Get the maximum sequence number used in this Transit.Section
getSectionFromBlockAndSeq(Block b, int seq)
Get a Section from one of its Blocks and its sequence number.Section
getSectionFromConnectedBlockAndSeq(Block b, int seq)
Get Section from one of its EntryPoint Blocks and its sequence number.java.util.ArrayList<Section>
getSectionListBySeq(int seq)
Get a List of Sections with a given sequence number.java.util.ArrayList<java.lang.Integer>
getSeqListBySection(Section s)
Get a List of sequence numbers for a given Section.int
getState()
Query the state of this Transit.TransitSection
getTransitSectionFromSectionAndSeq(Section s, int seq)
Get a TransitSection in the transit from its Section and sequence number.java.util.ArrayList<TransitSection>
getTransitSectionList()
Get the list of TransitSections.java.util.ArrayList<TransitSection>
getTransitSectionListBySeq(int seq)
Get a List of TransitSections with a given sequence number.java.util.List<NamedBeanUsageReport>
getUsageReport(NamedBean bean)
Get a list of references for the specified bean.int
initializeBlockingSensors()
Initialize blocking sensors for Sections in this Transit.void
removeAllSections()
Remove all TransitSections in this Transit.boolean
removeLastTemporarySection(Section s)
void
removeTemporarySections()
void
setState(int state)
Set the state of this Transit.void
vetoableChange(java.beans.PropertyChangeEvent evt)
-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, describeState, dispose, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, hashCode, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, describeState, dispose, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
DefaultTransit
public DefaultTransit(java.lang.String systemName, java.lang.String userName)
-
DefaultTransit
public DefaultTransit(java.lang.String systemName)
-
-
Method Detail
-
getState
public int getState()
Query the state of this Transit.- Specified by:
getState
in interfaceNamedBean
- Returns:
Transit.IDLE
orTransit.ASSIGNED
-
setState
public void setState(int state)
Set the state of this Transit.- Specified by:
setState
in interfaceNamedBean
- Specified by:
setState
in interfaceTransit
- Parameters:
state
-Transit.IDLE
orTransit.ASSIGNED
-
addTransitSection
public void addTransitSection(TransitSection s)
Add a Section to this Transit.- Specified by:
addTransitSection
in interfaceTransit
- Parameters:
s
- the Section object to add
-
getTransitSectionList
public java.util.ArrayList<TransitSection> getTransitSectionList()
Get the list of TransitSections.- Specified by:
getTransitSectionList
in interfaceTransit
- Returns:
- a copy of the internal list of TransitSections or an empty list
-
getMaxSequence
public int getMaxSequence()
Get the maximum sequence number used in this Transit.- Specified by:
getMaxSequence
in interfaceTransit
- Returns:
- the maximum sequence
-
removeAllSections
public void removeAllSections()
Remove all TransitSections in this Transit.- Specified by:
removeAllSections
in interfaceTransit
-
containsSection
public boolean containsSection(Section s)
Check if a Section is in this Transit.- Specified by:
containsSection
in interfaceTransit
- Parameters:
s
- the section to check for- Returns:
- true if the section is present; false otherwise
-
getSectionListBySeq
public java.util.ArrayList<Section> getSectionListBySeq(int seq)
Get a List of Sections with a given sequence number.- Specified by:
getSectionListBySeq
in interfaceTransit
- Parameters:
seq
- the sequence number- Returns:
- the list of of matching sections or an empty list if none
-
getTransitSectionListBySeq
public java.util.ArrayList<TransitSection> getTransitSectionListBySeq(int seq)
Get a List of TransitSections with a given sequence number.- Specified by:
getTransitSectionListBySeq
in interfaceTransit
- Parameters:
seq
- the sequence number- Returns:
- the list of of matching sections or an empty list if none
-
getSeqListBySection
public java.util.ArrayList<java.lang.Integer> getSeqListBySection(Section s)
Get a List of sequence numbers for a given Section.- Specified by:
getSeqListBySection
in interfaceTransit
- Parameters:
s
- the section to match- Returns:
- the list of matching sequence numbers or an empty list if none
-
containsBlock
public boolean containsBlock(Block block)
Check if a Block is in this Transit.- Specified by:
containsBlock
in interfaceTransit
- Parameters:
block
- the block to check for- Returns:
- true if block is present; false otherwise
-
getBlockCount
public int getBlockCount(Block block)
Get the number of times a Block is in this Transit.- Specified by:
getBlockCount
in interfaceTransit
- Parameters:
block
- the block to check for- Returns:
- the number of times block is present; 0 if block is not present
-
getSectionFromBlockAndSeq
public Section getSectionFromBlockAndSeq(Block b, int seq)
Get a Section from one of its Blocks and its sequence number.- Specified by:
getSectionFromBlockAndSeq
in interfaceTransit
- Parameters:
b
- the block within the Sectionseq
- the sequence number of the Section- Returns:
- the Section or null if no matching Section is present
-
getSectionFromConnectedBlockAndSeq
public Section getSectionFromConnectedBlockAndSeq(Block b, int seq)
Get Section from one of its EntryPoint Blocks and its sequence number.- Specified by:
getSectionFromConnectedBlockAndSeq
in interfaceTransit
- Parameters:
b
- the connecting block to the Sectionseq
- the sequence number of the Section- Returns:
- the Section or null if no matching Section is present
-
getDirectionFromSectionAndSeq
public int getDirectionFromSectionAndSeq(Section s, int seq)
Get the direction of a Section in the transit from its sequence number.- Specified by:
getDirectionFromSectionAndSeq
in interfaceTransit
- Parameters:
s
- the Section to checkseq
- the sequence number of the Section- Returns:
- the direction of the Section (one of
Section.FORWARD
orSection.REVERSE
or zero if s and seq are not in a TransitSection together
-
getTransitSectionFromSectionAndSeq
public TransitSection getTransitSectionFromSectionAndSeq(Section s, int seq)
Get a TransitSection in the transit from its Section and sequence number.- Specified by:
getTransitSectionFromSectionAndSeq
in interfaceTransit
- Parameters:
s
- the Section to checkseq
- the sequence number of the Section- Returns:
- the transit section or null if not found
-
getInternalBlocksList
public java.util.ArrayList<Block> getInternalBlocksList()
Get a list of all blocks internal to this Transit. Since Sections may be present more than once, blocks may be listed more than once. The sequence numbers of the Section the Block was found in are accumulated in a parallel list, which can be accessed by immediately callinggetBlockSeqList()
.- Specified by:
getInternalBlocksList
in interfaceTransit
- Returns:
- the list of all Blocks or an empty list if none are present
-
getBlockSeqList
public java.util.ArrayList<java.lang.Integer> getBlockSeqList()
Get a list of sequence numbers in this Transit. This list is generated by callinggetInternalBlocksList()
orgetEntryBlocksList()
.- Specified by:
getBlockSeqList
in interfaceTransit
- Returns:
- the list of all sequence numbers or an empty list if no Blocks are present
-
getEntryBlocksList
public java.util.ArrayList<Block> getEntryBlocksList()
Get a list of all entry Blocks to this Transit. These are Blocks that a Train might enter from and be going in the direction of this Transit. The sequence numbers of the Section the Block will enter are accumulated in a parallel list, which can be accessed by immediately callinggetBlockSeqList()
.- Specified by:
getEntryBlocksList
in interfaceTransit
- Returns:
- the list of all blocks or an empty list if none are present
-
getDestinationBlocksList
public java.util.ArrayList<Block> getDestinationBlocksList(Block startBlock, boolean startInTransit)
Get a list of all destination blocks that can be reached from a specified starting block. The sequence numbers of the Sections destination blocks were found in are accumulated in a parallel list, which can be accessed by immediately callinggetDestBlocksSeqList()
.Note: A Train may not terminate in the same Section in which it starts.
Note: A Train must terminate in a Block within the Transit.
- Specified by:
getDestinationBlocksList
in interfaceTransit
- Parameters:
startBlock
- the starting Block to find destinations forstartInTransit
- true if startBlock is within this Transit; false otherwise- Returns:
- a list of destination Blocks or an empty list if none exist
-
getDestBlocksSeqList
public java.util.ArrayList<java.lang.Integer> getDestBlocksSeqList()
Get a list of destination Block sequence numbers in this Transit. This list is generated by callinggetDestinationBlocksList(jmri.Block, boolean)
.- Specified by:
getDestBlocksSeqList
in interfaceTransit
- Returns:
- the list of all destination Block sequence numbers or an empty list if no destination Blocks are present
-
canBeResetWhenDone
public boolean canBeResetWhenDone()
Check if this Transit is capable of continuous running.A Transit is capable of continuous running if, after an Active Train completes the Transit, it can automatically be restarted. To be restartable, the first Section and the last Section must be the same Section, and the first and last Sections must be defined to run in the same direction. If the last Section is an alternate Section, the previous Section is tested. However, if the Active Train does not complete its Transit in the same Section it started in, the restart will not take place.
- Specified by:
canBeResetWhenDone
in interfaceTransit
- Returns:
- true if continuous running is possible; otherwise false
-
initializeBlockingSensors
public int initializeBlockingSensors()
Initialize blocking sensors for Sections in this Transit. This should be done before any Sections are allocated for this Transit. Only Sections that areSection.FREE
are initialized, so as not to interfere with running active trains. If any Section does not have blocking sensors, warning messages are logged.- Specified by:
initializeBlockingSensors
in interfaceTransit
- Returns:
- 0 if no errors, number of errors otherwise.
-
removeTemporarySections
public void removeTemporarySections()
- Specified by:
removeTemporarySections
in interfaceTransit
-
removeLastTemporarySection
public boolean removeLastTemporarySection(Section s)
- Specified by:
removeLastTemporarySection
in interfaceTransit
-
getBeanType
public java.lang.String getBeanType()
Description copied from interface:NamedBean
For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.- Specified by:
getBeanType
in interfaceNamedBean
- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
vetoableChange
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException
Description copied from class:AbstractNamedBean
- Specified by:
vetoableChange
in interfaceNamedBean
- Overrides:
vetoableChange
in classAbstractNamedBean
- Throws:
java.beans.PropertyVetoException
-
getUsageReport
public java.util.List<NamedBeanUsageReport> getUsageReport(NamedBean bean)
Description copied from interface:NamedBean
Get a list of references for the specified bean.- Specified by:
getUsageReport
in interfaceNamedBean
- Parameters:
bean
- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-
-