本文整理汇总了Java中org.apache.commons.validator.routines.checkdigit.CheckDigitException类的典型用法代码示例。如果您正苦于以下问题:Java CheckDigitException类的具体用法?Java CheckDigitException怎么用?Java CheckDigitException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CheckDigitException类属于org.apache.commons.validator.routines.checkdigit包,在下文中一共展示了CheckDigitException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateRandomCreditCardNumber
import org.apache.commons.validator.routines.checkdigit.CheckDigitException; //导入依赖的package包/类
public String generateRandomCreditCardNumber() {
String issuerIdentificationNumber = randomIssuerIdentificationNumber();
String cardNumberWithoutCheckDigit =
format("%s%s",
issuerIdentificationNumber,
randomNumeric(length - issuerIdentificationNumber.length() - 1));
try {
String checkDigit = LuhnCheckDigit.LUHN_CHECK_DIGIT.calculate(cardNumberWithoutCheckDigit);
return format("%s%s", cardNumberWithoutCheckDigit, checkDigit);
} catch (CheckDigitException e) {
throw new RuntimeException(e);
}
}
示例2: convertToISBN13
import org.apache.commons.validator.routines.checkdigit.CheckDigitException; //导入依赖的package包/类
/**
* Convert an ISBN-10 code to an ISBN-13 code.
* <p>
* This method requires a valid ISBN-10 with NO formatting
* characters.
*
* @param isbn10 The ISBN-10 code to convert
* @return A converted ISBN-13 code or <code>null</code>
* if the ISBN-10 code is not valid
*/
public String convertToISBN13(String isbn10) {
if (isbn10 == null) {
return null;
}
String input = isbn10.trim();
if (input.length() != ISBN_10_LEN) {
throw new IllegalArgumentException("Invalid length " + input.length() + " for '" + input + "'");
}
// Calculate the new ISBN-13 code (drop the original checkdigit)
String isbn13 = "978" + input.substring(0, ISBN_10_LEN - 1);
try {
String checkDigit = isbn13Validator.getCheckDigit().calculate(isbn13);
isbn13 += checkDigit;
return isbn13;
} catch (CheckDigitException e) {
throw new IllegalArgumentException("Check digit error for '" + input + "' - " + e.getMessage());
}
}
示例3: convertToEAN13
import org.apache.commons.validator.routines.checkdigit.CheckDigitException; //导入依赖的package包/类
/**
* Convert an ISSN code to an EAN-13 code.
* <p>
* This method requires a valid ISSN code.
* It may contain a leading 'ISSN ' prefix,
* as the input is passed through the {@link #validate(String)}
* method.
*
* @param issn The ISSN code to convert
* @param suffix the two digit suffix, e.g. "00"
* @return A converted EAN-13 code or <code>null</code>
* if the input ISSN code is not valid
*/
public String convertToEAN13(String issn, String suffix) {
if (suffix == null || !suffix.matches("\\d\\d")) {
throw new IllegalArgumentException("Suffix must be two digits: '" + suffix + "'");
}
Object result = validate(issn);
if (result == null) {
return null;
}
// Calculate the new EAN-13 code
final String input = result.toString();
String ean13 = "977" + input.substring(0, input.length() -1) + suffix;
try {
String checkDigit = EAN13CheckDigit.EAN13_CHECK_DIGIT.calculate(ean13);
ean13 += checkDigit;
return ean13;
} catch (CheckDigitException e) { // Should not happen
throw new IllegalArgumentException("Check digit error for '" + ean13 + "' - " + e.getMessage());
}
}
示例4: convertToISBN13
import org.apache.commons.validator.routines.checkdigit.CheckDigitException; //导入依赖的package包/类
/**
* Convert an ISBN-10 code to an ISBN-13 code.
* <p>
* This method requires a valid ISBN-10 with NO formatting characters.
*
* @param isbn10 The ISBN-10 code to convert
* @return A converted ISBN-13 code or <code>null</code> if the ISBN-10 code is not valid
*/
public String convertToISBN13(String isbn10) {
if (isbn10 == null) {
return null;
}
String input = isbn10.trim();
if (input.length() != 10) {
throw new IllegalArgumentException("Invalid length " + input.length() + " for '" + input + "'");
}
// Calculate the new ISBN-13 code
String isbn13 = "978" + input.substring(0, 9);
try {
String checkDigit = isbn13Validator.getCheckDigit().calculate(isbn13);
isbn13 += checkDigit;
return isbn13;
} catch (CheckDigitException e) {
throw new IllegalArgumentException("Check digit error for '" + input + "' - " + e.getMessage());
}
}
示例5: calculate
import org.apache.commons.validator.routines.checkdigit.CheckDigitException; //导入依赖的package包/类
public static String calculate ( String panNUmber){
LuhnCheckDigit luhn = new LuhnCheckDigit();
String checkdigit;
try {
checkdigit = luhn.calculate( panNUmber );
} catch (CheckDigitException e) {
checkdigit = "CheckDigit.calculate : "+ e.getMessage() ;
System.out.println(checkdigit);
}
return checkdigit ;
}
示例6: calculateIban
import org.apache.commons.validator.routines.checkdigit.CheckDigitException; //导入依赖的package包/类
private String calculateIban(String bankCode, String accountNumber) {
try {
String ibanWithoutCheckCode = createIban("00", bankCode, accountNumber);
String checkSum = new IBANCheckDigit().calculate(ibanWithoutCheckCode);
return createIban(checkSum, bankCode, accountNumber);
} catch (CheckDigitException e) {
throw new SimulatorException(String.format("Error calculating IBAN [code:%s,account:%s]", bankCode, accountNumber));
}
}