org.apache.commons.validator
Class ISBNValidator
java.lang.Object
org.apache.commons.validator.ISBNValidator
public class ISBNValidator
extends java.lang.Object
A class for validating 10 digit ISBN codes.
Based on this
algorithm
$Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $private static String | CHECK
|
private static String | GROUP
|
private static String | ISBN_PATTERN - ISBN consists of 4 groups of numbers separated by either dashes (-)
or spaces.
|
private static String | PUBLISHER
|
private static String | SEP
|
private static String | TITLE
|
private String | clean(String isbn) - Removes all non-digit characters except for 'X' which is a valid ISBN
character.
|
private boolean | isFormatted(String isbn) - Returns true if the ISBN contains one of the separator characters space
or dash.
|
boolean | isValid(String isbn) - If the ISBN is formatted with space or dash separators its format is
validated.
|
private boolean | isValidPattern(String isbn) - Returns true if the ISBN is formatted properly.
|
private int | sum(String isbn) - Returns the sum of the weighted ISBN characters.
|
private int | toInt(char ch) - Returns the numeric value represented by the character.
|
CHECK
private static final String CHECK
GROUP
private static final String GROUP
ISBN_PATTERN
private static final 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.
PUBLISHER
private static final String PUBLISHER
SEP
private static final String SEP
TITLE
private static final String TITLE
ISBNValidator
public ISBNValidator()
Default Constructor.
clean
private String clean(String isbn)
Removes all non-digit characters except for 'X' which is a valid ISBN
character.
isFormatted
private boolean isFormatted(String isbn)
Returns true if the ISBN contains one of the separator characters space
or dash.
isValid
public boolean isValid(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.
isbn
- Candidate ISBN number to be validated. null
is
considered invalid.
- true if the string is a valid ISBN code.
isValidPattern
private boolean isValidPattern(String isbn)
Returns true if the ISBN is formatted properly.
sum
private int sum(String isbn)
Returns the sum of the weighted ISBN characters.
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.
Copyright (c) 2001-2004 Apache Software Foundation