Class Portal


  • public class Portal
    extends java.lang.Object
    A Portal is a boundary between two Blocks.

    A Portal has Lists of the OPaths that connect through it. The direction of trains passing through the portal is managed from the BlockOrders of the Warrant the train is running under. The Portal fires a PropertyChangeEvent that a PortalIcon can listen for to set direction arrows for a given route. The Portal also supplies speed information from any signals set at its location that the Warrant passes on the Engineer.

    • Constructor Detail

      • Portal

        public Portal​(java.lang.String uName)
    • Method Detail

      • addPath

        public boolean addPath​(@Nonnull
                               OPath path)
        Determine which list the Path belongs to and add it to that list.
        Parameters:
        path - OPath to add
        Returns:
        false if Path does not have a matching block for this Portal
      • removePath

        public void removePath​(@Nonnull
                               OPath path)
        Remove an OPath from this Portal. Checks both the _fromBlock list as the _toBlock list.
        Parameters:
        path - the OPath to remove
      • setName

        @CheckForNull
        public java.lang.String setName​(@CheckForNull
                                        java.lang.String newName)
        Set userName of this Portal. Checks if name is available.
        Parameters:
        newName - name for path
        Returns:
        return error message, null if name change is OK
      • getName

        public java.lang.String getName()
      • setToBlock

        public boolean setToBlock​(@CheckForNull
                                  OBlock block,
                                  boolean changePaths)
        Set this portal's toBlock. Remove this portal from old toBlock, if any. Add this portal in the new toBlock's list of portals.
        Parameters:
        block - to be the new toBlock
        changePaths - if true, set block in paths. If false, verify that all toPaths are contained in the block.
        Returns:
        false if paths are not in the block
      • setFromBlock

        public boolean setFromBlock​(@CheckForNull
                                    OBlock block,
                                    boolean changePaths)
        Set this portal's fromBlock. Remove this portal from old fromBlock, if any. Add this portal in the new toBlock's list of portals.
        Parameters:
        block - to be the new fromBlock
        changePaths - if true, set block in paths. If false, verify that all toPaths are contained in the block.
        Returns:
        false if paths are not in the block
      • setProtectSignal

        public boolean setProtectSignal​(@CheckForNull
                                        NamedBean signal,
                                        float length,
                                        @CheckForNull
                                        OBlock protectedBlock)
        Set a signal to protect an OBlock. Warrants look ahead for speed changes and change the train speed accordingly.
        Parameters:
        signal - either a SignalMast or a SignalHead. Set to null to remove (previous) signal from Portal
        length - offset length in millimeters. This is additional entrance space for the block. This distance added to or subtracted from the calculation of the ramp distance when a warrant must slow the train in response to the aspect or appearance of the signal.
        protectedBlock - OBlock the signal protects
        Returns:
        true if signal is set
      • getSignalProtectingBlock

        @CheckForNull
        public NamedBean getSignalProtectingBlock​(@Nonnull
                                                  OBlock block)
        Get the signal (either a SignalMast or a SignalHead) protecting an OBlock.
        Parameters:
        block - is the direction of entry, i.e. the protected block
        Returns:
        signal protecting block, if block is protected, otherwise null.
      • getPathsWithinBlock

        public java.util.List<OPathgetPathsWithinBlock​(@CheckForNull
                                                         OBlock block)
        Get the paths to the portal within the connected OBlock i.e. the paths in this (the param) block through the Portal.
        Parameters:
        block - OBlock
        Returns:
        null if portal does not connect to block
      • getOpposingBlock

        public OBlock getOpposingBlock​(@Nonnull
                                       OBlock block)
        Get the OBlock on the other side of the Portal from the given OBlock.
        Parameters:
        block - starting OBlock
        Returns:
        the opposite block
      • getPathsFromOpposingBlock

        public java.util.List<OPathgetPathsFromOpposingBlock​(@Nonnull
                                                               OBlock block)
        Get the paths from the portal in the next connected OBlock i.e. paths in the block on the other side of the portal from this (the param) block.
        Parameters:
        block - OBlock
        Returns:
        null if portal does not connect to block
      • setState

        public void setState​(int s)
      • setEntranceSpaceForBlock

        public void setEntranceSpaceForBlock​(@Nonnull
                                             OBlock block,
                                             float distance)
        Set the distance (plus or minus) in millimeters from the portal gap where the speed change indicated by the signal should be completed.
        Parameters:
        block - a protected OBlock
        distance - length in millimeters, called Offset in the OBlock Signal Table
      • getEntranceSpaceForBlock

        public float getEntranceSpaceForBlock​(@Nonnull
                                              OBlock block)
        Get the distance (plus or minus) in millimeters from the portal gap where the speed change indicated by the signal should be completed. Property is called Offset in the OBlock Signal Table.
        Parameters:
        block - a protected OBlock
        Returns:
        distance
      • getPermissibleSpeed

        public java.lang.String getPermissibleSpeed​(@Nonnull
                                                    OBlock block,
                                                    boolean entrance)
        Check signals, if any, for speed into/out of a given block. The signal that protects the "to" block is the signal facing the "from" Block, i.e. the "from" signal. (and vice-versa)
        Parameters:
        block - is the direction of entry, "from" block
        entrance - true for EntranceSpeed, false for ExitSpeed
        Returns:
        permissible speed, null if no signal
      • isValidPath

        public boolean isValidPath​(@Nonnull
                                   OPath path)
        Check if path connects to Portal.
        Parameters:
        path - OPath to test
        Returns:
        true if valid
      • isValid

        public boolean isValid()
        Check portal has both blocks and they are different blocks.
        Returns:
        true if valid
      • toString

        @Nonnull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object