Class SerialAddress


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

    Multiple address formats are supported:

    • Gtnnnxxx where: G is the (multichar) system connection prefix, t is the type code: 'T' for turnouts, 'S' for sensors, 'H' for signal heads and 'L' for lights; nnn is the node address (1-127); xxx is a bit number of the input or output bit (001-999)
    • Gtnnnxxx = (node address x 1000) + bit number.
      Examples: GT1002 (node address 1, bit 2), G1S1003 (node address 1, bit 3), GL11234 (node address 11, bit234)
    • Gtnnnaxxxx where: t is the type code, 'T' for turnouts, 'S' for sensors, 'H' for signal heads and 'L' for lights; nnn is the node address of the input or output bit (1-127); xxxx is a bit number of the input or output bit (1-2048); a is a subtype-specific letter:
      • 'B' for a bit number (e.g. GT12B3 is a shorter form of GT12003)
      • 'a' is for advanced serial occupancy sensors (only valid t = S)
      • 'm' is for advanced serial motion sensors (only valid t = S)
      • 'pattern' is for parallel sensors (only valid t = S)
      • 's' is for serial occupancy sensors (only valid t = S)
      Examples: GT1B2 (node address 1, bit 2), G1S1B3 (node address 1, bit 3), G22L11B234 (node address 11, bit 234)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.util.regex.Pattern allPattern  
      (package private) static java.lang.String allRegex
      Regular expression used to parse from any type of name.
      (package private) static java.util.regex.Pattern headPattern  
      (package private) static java.lang.String headRegex
      Regular expression used to parse SignalHead names.
      (package private) static java.util.regex.Pattern lightPattern  
      (package private) static java.lang.String lightRegex
      Regular expression used to parse Light names.
      (package private) static java.util.regex.Pattern sensorPattern  
      (package private) static java.lang.String sensorRegex
      Regular expression used to parse Sensor names.
      (package private) static java.util.regex.Pattern turnoutPattern  
      (package private) static java.lang.String turnoutRegex
      Regular expression used to parse Turnout names.
    • Constructor Summary

      Constructors 
      Constructor Description
      SerialAddress()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String convertSystemNameToAlternate​(java.lang.String systemName, java.lang.String prefix)
      Public static method to convert any format system name for the alternate format (nnBnn).
      (package private) static java.util.regex.Pattern getAllPattern()  
      static int getBitFromSystemName​(java.lang.String systemName, java.lang.String prefix)
      Public static method to parse a system name and return the bit number.
      (package private) static java.util.regex.Pattern getHeadPattern()  
      (package private) static java.util.regex.Pattern getLightPattern()  
      static int getNodeAddressFromSystemName​(java.lang.String systemName, java.lang.String prefix)
      Public static method to parse a system name to fetch the node number.
      static SerialNode getNodeFromSystemName​(java.lang.String systemName, SerialTrafficController tc)
      Public static method to parse a system name and return the Serial Node.
      (package private) static java.util.regex.Pattern getSensorPattern()  
      (package private) static java.util.regex.Pattern getTurnoutPattern()  
      static java.lang.String normalizeSystemName​(java.lang.String systemName, java.lang.String prefix)
      Public static method to normalize a system name
      (package private) static int typeOffset​(java.lang.String type)
      Parse for secondary letters.
      (package private) static java.lang.String validateSystemNameFormat​(java.lang.String name, Manager<?> manager, java.util.Locale locale)
      Validate a system name.
      static boolean validSystemNameConfig​(java.lang.String systemName, char type, SerialTrafficController tc)
      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
    • Field Detail

      • turnoutRegex

        static final java.lang.String turnoutRegex
        Regular expression used to parse Turnout names.

        Groups:

        • - System letter/prefix (not captured in regex)
        • 1 - Type letter
        • 2 - suffix, if of nnnAnnn form
        • 3 - node number in nnnAnnn form
        • 4 - address type in nnnAnnn form
        • 5 - bit number in nnnAnnn form
        • 6 - combined number in nnnnnn form
        See Also:
        Constant Field Values
      • turnoutPattern

        static volatile java.util.regex.Pattern turnoutPattern
      • lightRegex

        static final java.lang.String lightRegex
        Regular expression used to parse Light names.

        Groups:

        • - System letter/prefix (not captured in regex)
        • 1 - Type letter
        • 2 - suffix, if of nnnAnnn form
        • 3 - node number in nnnAnnn form
        • 4 - address type in nnnAnnn form
        • 5 - bit number in nnnAnnn form
        • 6 - combined number in nnnnnn form
        See Also:
        Constant Field Values
      • lightPattern

        static volatile java.util.regex.Pattern lightPattern
      • headRegex

        static final java.lang.String headRegex
        Regular expression used to parse SignalHead names.

        Groups:

        • - System letter/prefix (not captured in regex)
        • 1 - Type letter
        • 2 - suffix, if of nnnAnnn form
        • 3 - node number in nnnAnnn form
        • 4 - address type in nnnAnnn form
        • 5 - bit number in nnnAnnn form
        • 6 - combined number in nnnnnn form
        See Also:
        Constant Field Values
      • headPattern

        static volatile java.util.regex.Pattern headPattern
      • sensorRegex

        static final java.lang.String sensorRegex
        Regular expression used to parse Sensor names.

        Groups:

        • - System letter/prefix (not captured in regex)
        • 1 - Type letter
        • 2 - suffix, if of nnnAnnn form
        • 3 - node number in nnnAnnn form
        • 4 - address type in nnnAnnn form
        • 5 - bit number in nnnAnnn form
        • 6 - combined number in nnnnnn form
        See Also:
        Constant Field Values
      • sensorPattern

        static volatile java.util.regex.Pattern sensorPattern
      • allRegex

        static final java.lang.String allRegex
        Regular expression used to parse from any type of name.

        Groups:

        • - System letter/prefix (not captured in regex)
        • 1 - Type letter
        • 2 - suffix, if of nnnAnnn form
        • 3 - node number in nnnAnnn form
        • 4 - address type in nnnAnnn form
        • 5 - bit number in nnnAnnn form
        • 6 - combined number in nnnnnn form
        See Also:
        Constant Field Values
      • allPattern

        static volatile java.util.regex.Pattern allPattern
    • Method Detail

      • typeOffset

        static int typeOffset​(java.lang.String type)
        Parse for secondary letters.
        Parameters:
        type - Secondary letter from message
        Returns:
        offset for type letter, or -1 if none
      • getNodeFromSystemName

        public static SerialNode getNodeFromSystemName​(java.lang.String systemName,
                                                       SerialTrafficController tc)
        Public static method to parse a system name and return the Serial Node.
        Parameters:
        systemName - system name.
        tc - system connection traffic controller.
        Returns:
        'NULL' if illegal systemName format or if the node is not found
      • getBitFromSystemName

        public static int getBitFromSystemName​(java.lang.String systemName,
                                               java.lang.String prefix)
        Public static method to parse a system name and return the bit number. Notes: Bits are numbered from 1.
        Parameters:
        systemName - system name.
        prefix - unused.
        Returns:
        0 if an error is found
      • getNodeAddressFromSystemName

        public static int getNodeAddressFromSystemName​(java.lang.String systemName,
                                                       java.lang.String prefix)
        Public static method to parse a system name to fetch the node number.

        Note: Nodes are numbered from 1.

        Parameters:
        systemName - system name.
        prefix - unused.
        Returns:
        node number. If an error is found, returns -1
      • 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. Logging of handled cases no higher than WARN.
        Parameters:
        systemName - name to check
        type - expected device type letter
        prefix - system connection prefix from memo
        Returns:
        'true' if system name has a valid format, else returns 'false'
      • validSystemNameConfig

        public static boolean validSystemNameConfig​(java.lang.String systemName,
                                                    char type,
                                                    SerialTrafficController tc)
        Public static method to validate system name for configuration.
        Parameters:
        systemName - system name to validate.
        type - bean type, S, T or L.
        tc - system connection traffic controller.
        Returns:
        'true' if system name has a valid meaning in current configuration, else returns 'false'.
      • convertSystemNameToAlternate

        public static java.lang.String convertSystemNameToAlternate​(java.lang.String systemName,
                                                                    java.lang.String prefix)
        Public static method to convert any format system name for the alternate format (nnBnn).

        If the supplied system name does not have a valid format, or if there is no representation in the alternate naming scheme, an empty string is returned.

        Parameters:
        systemName - system name to convert.
        prefix - system prefix.
        Returns:
        alternate string.
      • 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 one bit, by removing extra zeros inserted by the user.

        If the supplied system name does not have a valid format, an empty string is returned. Otherwise a normalized name is returned in the same format as the input name.

        Parameters:
        systemName - system name to normalize.
        prefix - system prefix.
        Returns:
        normalized string.