Class SerialAddress


  • public class SerialAddress
    extends java.lang.Object
    Utility Class supporting parsing and testing of Maple addresses.

    One address format is supported: Ktxxxx where:

    • K is (user configurable) system prefix for Maple
    • t is the type code: 'T' for turnouts, 'S' for sensors, and 'L' for lights
    • xxxx is a bit number of the input or output bit (001-9999)
    Note: with Maple, all panels (nodes) have the same address space, so there is no node number in the address.
    • Constructor Summary

      Constructors 
      Constructor Description
      SerialAddress()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getBitFromSystemName​(java.lang.String systemName, java.lang.String prefix)
      Public static method to parse a Maple system name and return the bit number.
      static java.lang.String getUserNameFromSystemName​(java.lang.String systemName, java.lang.String prefix)
      Public static method to get the user name for a valid system name.
      static java.lang.String isInputBitFree​(int bitNum, java.lang.String prefix)
      Public static method to test if an input bit is free for assignment.
      static java.lang.String isOutputBitFree​(int bitNum, java.lang.String prefix)
      Public static method to test if an output bit is free for assignment.
      static java.lang.String makeSystemName​(java.lang.String type, int bitNum, java.lang.String prefix)
      Public static method to construct a system name from type character and bit number.
      static java.lang.String normalizeSystemName​(java.lang.String systemName, java.lang.String prefix)
      Public static method to normalize a system name.
      static java.lang.String validateSystemNameFormat​(java.lang.String name, Manager<?> manager, java.util.Locale locale)
      Validate the system name.
      static boolean validSystemNameConfig​(java.lang.String systemName, char type, MapleSystemConnectionMemo memo)
      Public static method to validate system name for configuration.
      static Manager.NameValidity validSystemNameFormat​(java.lang.String systemName, char type, java.lang.String prefix)
      Public static method to validate system name format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getBitFromSystemName

        public static int getBitFromSystemName​(java.lang.String systemName,
                                               java.lang.String prefix)
        Public static method to parse a Maple system name and return the bit number.

        Notes: Bits are numbered from 1.

        Parameters:
        systemName - system name.
        prefix - system prefix.
        Returns:
        the bit number, return 0 if an error is found
      • validateSystemNameFormat

        public static java.lang.String validateSystemNameFormat​(java.lang.String name,
                                                                Manager<?> manager,
                                                                java.util.Locale locale)
                                                         throws java.lang.IllegalArgumentException
        Validate the system name.
        Parameters:
        name - the name to validate
        manager - the manager requesting validation
        locale - the locale for user messages
        Returns:
        the name; unchanged
        Throws:
        java.lang.IllegalArgumentException - if name is not valid
        See Also:
        Manager.validateSystemNameFormat(java.lang.String, java.util.Locale)
      • validSystemNameFormat

        public static Manager.NameValidity validSystemNameFormat​(@Nonnull
                                                                 java.lang.String systemName,
                                                                 char type,
                                                                 java.lang.String prefix)
        Public static method to validate system name format.
        Parameters:
        systemName - system name to validate.
        type - bean type, ie S for Sensor, T for Turnout.
        prefix - system prefix.
        Returns:
        'true' if system name has a valid format, else returns 'false'
      • validSystemNameConfig

        public static boolean validSystemNameConfig​(java.lang.String systemName,
                                                    char type,
                                                    MapleSystemConnectionMemo memo)
        Public static method to validate system name for configuration.
        Parameters:
        systemName - system name to validate.
        type - bean type, ie S for Sensor, T for Turnout.
        memo - system connection.
        Returns:
        'true' if system name has a valid meaning in current configuration, else returns 'false'
      • normalizeSystemName

        public static java.lang.String normalizeSystemName​(java.lang.String systemName,
                                                           java.lang.String prefix)
        Public static method to normalize a system name.

        This routine is used to ensure that each system name is uniquely linked to a bit, by removing extra zeros inserted by the user. It's not applied to sensors (whick might be addressed using the KS3:5 format.

        Parameters:
        systemName - systemname to normalize.
        prefix - system prefix.
        Returns:
        if the supplied system name does not have a valid format, an empty string is returned. If the address in the system name is not within the legal maximum range for the type of item (L, T, or S), an empty string is returned. Otherwise a normalized name is returned in the same format as the input name.
      • makeSystemName

        public static java.lang.String makeSystemName​(java.lang.String type,
                                                      int bitNum,
                                                      java.lang.String prefix)
        Public static method to construct a system name from type character and bit number.

        This routine returns a system name in the KLxxxx, KTxxxx, or KSxxxx format. The returned name is normalized.

        Parameters:
        type - bean type, ie S Sensor, T Turnout.
        bitNum - bit number.
        prefix - system prefix.
        Returns:
        "" (null string) if the supplied type character is not valid, or the bit number is out of the 1 - 9000 range, and an error message is logged.
      • isOutputBitFree

        public static java.lang.String isOutputBitFree​(int bitNum,
                                                       java.lang.String prefix)
        Public static method to test if an output bit is free for assignment.
        Parameters:
        bitNum - bit number.
        prefix - system prefix.
        Returns:
        "" (null string) if the specified output bit is free for assignment, else returns the system name of the conflicting assignment. Test is not performed if the node address or bit number are valid.
      • isInputBitFree

        public static java.lang.String isInputBitFree​(int bitNum,
                                                      java.lang.String prefix)
        Public static method to test if an input bit is free for assignment.
        Parameters:
        bitNum - bit number.
        prefix - system prefix.
        Returns:
        "" (empty string) if the specified input bit is free for assignment, else returns the system name of the conflicting assignment. Test is not performed if the node address is illegal or bit number is valid.
      • getUserNameFromSystemName

        public static java.lang.String getUserNameFromSystemName​(java.lang.String systemName,
                                                                 java.lang.String prefix)
        Public static method to get the user name for a valid system name.
        Parameters:
        systemName - system name.
        prefix - system prefix.
        Returns:
        "" (empty string) if the system name is not valid or does not exist