Class ISBNValidator


  • public class ISBNValidator
    extends java.lang.Object
    A class for validating 10 digit ISBN codes. Based on this algorithm
    Since:
    Validator 1.2.0
    Version:
    $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String CHECK  
      private static java.lang.String GROUP  
      private static java.lang.String ISBN_PATTERN
      ISBN consists of 4 groups of numbers separated by either dashes (-) or spaces.
      private static java.lang.String PUBLISHER  
      private static java.lang.String SEP  
      private static java.lang.String TITLE  
    • Constructor Summary

      Constructors 
      Constructor Description
      ISBNValidator()
      Default Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String clean​(java.lang.String isbn)
      Removes all non-digit characters except for 'X' which is a valid ISBN character.
      private boolean isFormatted​(java.lang.String isbn)
      Returns true if the ISBN contains one of the separator characters space or dash.
      boolean isValid​(java.lang.String isbn)
      If the ISBN is formatted with space or dash separators its format is validated.
      private boolean isValidPattern​(java.lang.String isbn)
      Returns true if the ISBN is formatted properly.
      private int sum​(java.lang.String isbn)
      Returns the sum of the weighted ISBN characters.
      private int toInt​(char ch)
      Returns the numeric value represented by the character.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ISBN_PATTERN

        private static final java.lang.String ISBN_PATTERN
        ISBN consists of 4 groups of numbers separated by either dashes (-) or spaces. The first group is 1-5 characters, second 1-7, third 1-6, and fourth is 1 digit or an X.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ISBNValidator

        public ISBNValidator()
        Default Constructor.
    • Method Detail

      • isValid

        public boolean isValid​(java.lang.String isbn)
        If the ISBN is formatted with space or dash separators its format is validated. Then the digits in the number are weighted, summed, and divided by 11 according to the ISBN algorithm. If the result is zero, the ISBN is valid. This method accepts formatted or raw ISBN codes.
        Parameters:
        isbn - Candidate ISBN number to be validated. null is considered invalid.
        Returns:
        true if the string is a valid ISBN code.
      • sum

        private int sum​(java.lang.String isbn)
        Returns the sum of the weighted ISBN characters.
      • clean

        private java.lang.String clean​(java.lang.String isbn)
        Removes all non-digit characters except for 'X' which is a valid ISBN character.
      • toInt

        private int toInt​(char ch)
        Returns the numeric value represented by the character. If the character is not a digit but an 'X', 10 is returned.
      • isFormatted

        private boolean isFormatted​(java.lang.String isbn)
        Returns true if the ISBN contains one of the separator characters space or dash.
      • isValidPattern

        private boolean isValidPattern​(java.lang.String isbn)
        Returns true if the ISBN is formatted properly.