org.apache.commons.validator.routines.checkdigit
Class VerhoeffCheckDigit

java.lang.Object
  extended by org.apache.commons.validator.routines.checkdigit.VerhoeffCheckDigit
All Implemented Interfaces:
java.io.Serializable, CheckDigit

public final class VerhoeffCheckDigit
extends java.lang.Object
implements CheckDigit, java.io.Serializable

Verhoeff (Dihedral) Check Digit calculation/validation.

Check digit calculation for numeric codes using a Dihedral Group of order 10.

See Wikipedia - Verhoeff algorithm for more details.

Since:
Validator 1.4
Version:
$Revision: 493905 $ $Date: 2007-01-08 03:11:38 +0100 (Mo, 08. Jan 2007) $
See Also:
Serialized Form

Field Summary
private static int[][] D_TABLE
          D - multiplication table
static CheckDigit INSTANCE
          Singleton Verhoeff Check Digit instance
private static int[] INV_TABLE
          inv: inverse table
private static int[][] P_TABLE
          P - permutation table
 
Constructor Summary
VerhoeffCheckDigit()
           
 
Method Summary
 java.lang.String calculate(java.lang.String code)
          Calculate a Verhoeff Check Digit for a code.
private  int calculateChecksum(java.lang.String code, boolean includesCheckDigit)
          Calculate the checksum.
 boolean isValid(java.lang.String code)
          Validate the Verhoeff Check Digit for a code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final CheckDigit INSTANCE
Singleton Verhoeff Check Digit instance


D_TABLE

private static final int[][] D_TABLE
D - multiplication table


P_TABLE

private static final int[][] P_TABLE
P - permutation table


INV_TABLE

private static final int[] INV_TABLE
inv: inverse table

Constructor Detail

VerhoeffCheckDigit

public VerhoeffCheckDigit()
Method Detail

isValid

public boolean isValid(java.lang.String code)
Validate the Verhoeff Check Digit for a code.

Specified by:
isValid in interface CheckDigit
Parameters:
code - The code to validate
Returns:
true if the check digit is valid, otherwise false

calculate

public java.lang.String calculate(java.lang.String code)
                           throws CheckDigitException
Calculate a Verhoeff Check Digit for a code.

Specified by:
calculate in interface CheckDigit
Parameters:
code - The code to calculate the Check Digit for
Returns:
The calculated Check Digit
Throws:
CheckDigitException - if an error occurs calculating the check digit for the specified code

calculateChecksum

private int calculateChecksum(java.lang.String code,
                              boolean includesCheckDigit)
                       throws CheckDigitException
Calculate the checksum.

Parameters:
code - The code to calculate the checksum for.
includesCheckDigit - Whether the code includes the Check Digit or not.
Returns:
The checksum value
Throws:
CheckDigitException - if the code contains an invalid character (i.e. not numeric)


Copyright (c) 2001-2004 Apache Software Foundation