当前位置: 首页>>代码示例>>Java>>正文


Java CheckDigitException类代码示例

本文整理汇总了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);
            }
        }
 
开发者ID:seize-the-dave,项目名称:forgery,代码行数:19,代码来源:RandomCreditCardForger.java

示例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());
    }

}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-validator,代码行数:33,代码来源:ISBNValidator.java

示例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());
    }

}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-validator,代码行数:37,代码来源:ISSNValidator.java

示例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());
    }

}
 
开发者ID:FenixEdu,项目名称:bennu-renderers,代码行数:31,代码来源:ISBNValidator.java

示例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 ;	
	
}
 
开发者ID:jporras66,项目名称:cryptocard,代码行数:14,代码来源:CheckDigit.java

示例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));
    }
}
 
开发者ID:christophd,项目名称:citrus-simulator,代码行数:10,代码来源:BankService.java


注:本文中的org.apache.commons.validator.routines.checkdigit.CheckDigitException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。