Package com.s24.gs1

Class GtinNormalizer


  • public class GtinNormalizer
    extends Object
    Removes non-digit characters from a GTIN and adds leading zeros to GTINs according to the specified target length.

    To have unified GTIN values, you can use this normalizer. It precedes a GTIN with zeros. Due to the checksum calculation mechanism this won't affect the validity of a GTIN. Any non-digit characters will be removed.

    • Constructor Detail

      • GtinNormalizer

        public GtinNormalizer​(int targetLength)
        Creates a new GTIN normalizer.
        Parameters:
        targetLength - A valid GTIN length to normalize GTINs
        Throws:
        IllegalArgumentException - If the target length is not a allowed GTIN format length
    • Method Detail

      • normalize

        public String normalize​(CharSequence gtin)
        Adds leading zeros to a GTIN value.
        Parameters:
        gtin - The GTIN to normalize. Must not be null or empty.
        Returns:
        The GTIN padded to the given target length and
        Throws:
        IllegalArgumentException - If the input was null or empty