Package jmri.util

Class CvUtil


  • public class CvUtil
    extends java.lang.Object
    Common utility methods for working with CVs

    We needed a place to refactor common CV-processing idioms in JMRI code, so this class was created. It's more of a library of procedures than a real class, as (so far) all of the operations have needed no state information.

    • Constructor Summary

      Constructors 
      Constructor Description
      CvUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String addCvDescription​(java.lang.String toolTip, java.lang.String cvDescription, java.lang.String mask)
      Optionally add CV numbers and bit numbers to tool tip text based on Roster Preferences setting.
      static java.util.List<java.lang.String> expandCvList​(java.lang.String cvString)  
      static java.lang.String getMaskDescription​(java.lang.String mask)
      Generate bit numbers from a bit mask if applicable.
      • Methods inherited from class java.lang.Object

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

    • Method Detail

      • expandCvList

        public static java.util.List<java.lang.String> expandCvList​(java.lang.String cvString)
        Parameters:
        cvString - a string that may contain one and only one instance one of the following expandable forms;
        (parentheses can be used to limit numeric boundaries and/or restrict the portions to be expanded):
        • A comma-separated list. Examples:
           "1,5,7" expands to [1, 5, 7]
           "16.3.25(1,2,5,7)" expands to [16.3.251, 16.3.252, 16.3.255, 16.3.257]
           
        • A hyphen-separated numeric range, in either direction. Examples:
           "16.3.25(1-7)" expands to [16.3.251, 16.3.252, 16.3.253, 16.3.254, 16.3.255, 16.3.256, 16.3.257]
           "16.3.2(53-48)" expands to [16.3.253, 16.3.252, 16.3.251, 16.3.250, 16.3.249, 16.3.248]
           "16.3(1-7).25" expands to [16.31.25, 16.32.25, 16.33.25, 16.34.25, 16.35.25, 16.36.25, 16.37.25]
           "98-103" expands to [98, 99, 100, 101, 102, 103]
           
        • A numeric starting value, followed by a colon and a count, in either direction. Examples:
           "25.3.250:4" expands to [25.3.250, 25.3.251, 25.3.252, 25.3.253]
           "25.3.250:-4" expands to [25.3.250, 25.3.249, 25.3.248, 25.3.247]
           
        Returns:
        A list of CVs produced by expanding the string
        or
        an empty list if nothing to expand.
      • addCvDescription

        public static java.lang.String addCvDescription​(java.lang.String toolTip,
                                                        java.lang.String cvDescription,
                                                        java.lang.String mask)
        Optionally add CV numbers and bit numbers to tool tip text based on Roster Preferences setting.
        Parameters:
        toolTip - The tool tip text. It can be plain text or HTML format.
        cvDescription - The CV description text.
        mask - The bit mask, a (list of) string containing only the characters 'V' & 'X', with 'V' signifying a used bit.
        Returns:
        The original tool tip text plus (if the Roster Preferences allow) a parenthesized CV and bit mask description.
      • getMaskDescription

        public static java.lang.String getMaskDescription​(java.lang.String mask)
        Generate bit numbers from a bit mask if applicable.
        Parameters:
        mask - A string containing only the characters 'V' & 'X', with 'V' signifying a used bit.
        Returns:
        A plain text description of the used bits. (For example, "bits 0-3,7" from the string "VXXXVVVV".) Empty String if not applicable