Class VesselIMOCheckDigit

java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.VesselIMOCheckDigit
All Implemented Interfaces:
Serializable, CheckDigit

public final class VesselIMOCheckDigit extends ModulusCheckDigit
Modulus 10 Vessel IMO Number Check Digit calculation/validation.

IMO Numbers are a numeric codes. Check digit calculation is based on modulus 10 with digits being weighted based on their position (from right to left).
The check digit is found by taking the last digit times 2, the preceding digit times 3, the preceding digit times 4 etc., adding all these up and computing the sum modulo 10.
For example, the IMO number of KAVITA from Palau is IMO 9074729: the checksum 9 is calculated as (9×7) + (0×6) + (7×5) + (4×4) + (7×3) + (2×2) = 139; 139 mod 10 = 9.
Note that these do not validate the input for syntax. Such validation is performed by the VesselIMOValidator

Since:
1.9.0
See Also:
  • Field Details

    • MIN_LEN

      public static final int MIN_LEN
      The minimum length without dashes.

      IMO number consists of 7 numbers. Example: IMO 9074729

      See Also:
    • MAX_LEN

      public static final int MAX_LEN
      The maximum length
      See Also:
  • Method Details

    • getInstance

      public static CheckDigit getInstance()
      Gets the singleton instance of this validator.
      Returns:
      A singleton instance of the IMO Number validator.
    • weightedValue

      protected int weightedValue(int charValue, int leftPos, int rightPos)
      Calculates the weighted value of a character in the code at a specified position.

      CAS numbers are weighted in the following manner:

      
          right position: 1  2  3  4  5  6  7
                  weight: 2  3  4  5  6  7  8
       
      Specified by:
      weightedValue in class ModulusCheckDigit
      Parameters:
      charValue - The numeric value of the character.
      leftPos - The position of the character in the code, counting from left to right
      rightPos - The positionof the character in the code, counting from right to left
      Returns:
      The weighted value of the character.
    • calculate

      public String calculate(String code) throws CheckDigitException
      Calculate a modulus Check Digit for a code which does not yet have one.
      Specified by:
      calculate in interface CheckDigit
      Overrides:
      calculate in class ModulusCheckDigit
      Parameters:
      code - The code for which to calculate the Check Digit; the check digit should not be included
      Returns:
      The calculated Check Digit
      Throws:
      CheckDigitException - if an error occurs calculating the check digit
    • isValid

      public boolean isValid(String code)
      Validate a modulus check digit for a code.
      Specified by:
      isValid in interface CheckDigit
      Overrides:
      isValid in class ModulusCheckDigit
      Parameters:
      code - The code to validate
      Returns:
      true if the check digit is valid, otherwise false