Class UVCIChecksumCalculator


  • public class UVCIChecksumCalculator
    extends Object
    A utility to calculate the checksum for UVCI:s according to the DCC schema wiki.
    Author:
    Martin Lindström (martin@idsec.se), Henrik Bengtsson (extern.henrik.bengtsson@digg.se), Henric Norlander (extern.henric.norlander@digg.se)
    • Field Detail

      • LUHN_MOD_N_CHARSET

        public static final String LUHN_MOD_N_CHARSET
        The character set for the Luhn mod N calculation.
        See Also:
        Constant Field Values
      • DELIMITER

        public static final char DELIMITER
        The delimiter character used to separate the UVCI from the checksum character.
        See Also:
        Constant Field Values
    • Method Detail

      • calculateChecksum

        public static char calculateChecksum​(String input)
        Calculates the control character for the supplied input. Note that the input must only contain characters from the LUHN_MOD_N_CHARSET.

        Implementation stolen from https://en.wikipedia.org/wiki/Luhn_mod_N_algorithm#Algorithm_in_Java.

        Parameters:
        input - the input
        Returns:
        the checksum control character
      • addChecksum

        public static String addChecksum​(String input)
        Given an UVCI, the method calculates a checksum character and returns the modified string (with a checksum appended).
        Parameters:
        input - the input
        Returns:
        the string with an appended checksum character
      • validateChecksum

        public static boolean validateChecksum​(String data)
        Given a string containing a checksum control character the method controls whether this is correct.

        If the supplied string doesn't contain a checksum control character false is returned.

        Parameters:
        data - the string to check
        Returns:
        if the present checksum control character is correct true is returned, otherwise false