Package jmri.util

Class CvUtil


public class CvUtil
extends 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 Details

  • Method Details

    • expandCvList

      public static List<String> expandCvList​(String cvString)
      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]
      A list of CVs produced by expanding the string
      an empty list if nothing to expand.
    • addCvDescription

      public static String addCvDescription​(String toolTip, String cvDescription, String mask)
      Optionally add CV numbers and bit numbers to tool tip text based on Roster Preferences setting.
      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.
      The original tool tip text plus (if the Roster Preferences allow) a parenthesized CV and bit mask description.
    • getMaskDescription

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