本文整理汇总了Java中org.apache.commons.validator.routines.checkdigit.CheckDigit类的典型用法代码示例。如果您正苦于以下问题:Java CheckDigit类的具体用法?Java CheckDigit怎么用?Java CheckDigit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CheckDigit类属于org.apache.commons.validator.routines.checkdigit包,在下文中一共展示了CheckDigit类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCheckDigit
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Test Check Digit.
*/
public void testCheckDigit() {
CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
String invalidEAN = "9781930110992";
String validEAN = "9781930110991";
// Test no CheckDigit (i.e. null)
assertNull("No CheckDigit", validator.getCheckDigit());
assertEquals("No CheckDigit invalid", invalidEAN, validator.validate(invalidEAN));
assertEquals("No CheckDigit valid", validEAN, validator.validate(validEAN));
assertEquals("No CheckDigit (is) invalid", true, validator.isValid(invalidEAN));
assertEquals("No CheckDigit (is) valid", true, validator.isValid(validEAN));
// Use the EAN-13 check digit routine
validator = new CodeValidator((String)null, -1, EAN13CheckDigit.EAN13_CHECK_DIGIT);
assertNotNull("EAN CheckDigit", validator.getCheckDigit());
assertEquals("EAN CheckDigit invalid", null, validator.validate(invalidEAN));
assertEquals("EAN CheckDigit valid", validEAN, validator.validate(validEAN));
assertEquals("EAN CheckDigit (is) invalid", false, validator.isValid(invalidEAN));
assertEquals("EAN CheckDigit (is) valid", true, validator.isValid(validEAN));
assertEquals("EAN CheckDigit ex", null, validator.validate("978193011099X"));
}
示例2: CodeValidator
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Construct a code validator with a specified regular
* expression, minimum/maximum length and {@link CheckDigit} validation.
* The RegexValidator validator is created to be case-sensitive
*
* @param regex The regular expression
* @param minLength The minimum length of the code
* @param maxLength The maximum length of the code
* @param checkdigit The check digit validation routine
*/
public CodeValidator(String regex, int minLength, int maxLength,
CheckDigit checkdigit) {
if (regex != null && regex.length() > 0) {
this.regexValidator = new RegexValidator(regex);
} else {
this.regexValidator = null;
}
this.minLength = minLength;
this.maxLength = maxLength;
this.checkdigit = checkdigit;
}
示例3: testNoInput
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Test Regular Expression.
*/
public void testNoInput() {
CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
assertEquals("Null", null, validator.validate(null));
assertEquals("Zero Length", null, validator.validate(""));
assertEquals("Spaces", null, validator.validate(" "));
assertEquals("Trimmed", "A", validator.validate(" A "));
}
示例4: testIsValidISSNConvert
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Test isValid() ISSN codes and convert them
*/
public void testIsValidISSNConvert() {
CheckDigit ean13cd = EAN13CheckDigit.EAN13_CHECK_DIGIT;
Random r = new Random();
for(String f : validFormat) {
String suffix = String.format("%02d", r.nextInt(100));
String ean13 = VALIDATOR.convertToEAN13(f, suffix);
assertTrue(ean13, ean13cd.isValid(ean13));
}
// internet samples
assertEquals("9771144875007", VALIDATOR.convertToEAN13("1144-875X", "00"));
assertEquals("9770264359008", VALIDATOR.convertToEAN13("0264-3596", "00"));
assertEquals("9771234567003", VALIDATOR.convertToEAN13("1234-5679", "00"));
}
示例5: CodeValidator
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Construct a code validator with a specified regular
* expression, minimum/maximum length and {@link CheckDigit} validation.
*
* @param regex The regular expression validator
* @param minLength The minimum length of the code
* @param maxLength The maximum length of the code
* @param checkdigit The check digit validation routine
*/
public CodeValidator(String regex, int minLength, int maxLength, CheckDigit checkdigit) {
if (regex != null && regex.length() > 0) {
this.regexValidator = new RegexValidator(regex);
} else {
this.regexValidator = null;
}
this.minLength = minLength;
this.maxLength = maxLength;
this.checkdigit = checkdigit;
}
示例6: testLength
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Test the minimum/maximum length
*/
public void testLength() {
CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
String length_10 = "1234567890";
String length_11 = "12345678901";
String length_12 = "123456789012";
String length_20 = "12345678901234567890";
String length_21 = "123456789012345678901";
String length_22 = "1234567890123456789012";
assertEquals("No min", -1, validator.getMinLength());
assertEquals("No max", -1, validator.getMaxLength());
assertEquals("No Length 10", length_10, validator.validate(length_10));
assertEquals("No Length 11", length_11, validator.validate(length_11));
assertEquals("No Length 12", length_12, validator.validate(length_12));
assertEquals("No Length 20", length_20, validator.validate(length_20));
assertEquals("No Length 21", length_21, validator.validate(length_21));
assertEquals("No Length 22", length_22, validator.validate(length_22));
validator = new CodeValidator((String)null, 11, -1, (CheckDigit)null);
assertEquals("Min 11 - min", 11, validator.getMinLength());
assertEquals("Min 11 - max", -1, validator.getMaxLength());
assertEquals("Min 11 - 10", null, validator.validate(length_10));
assertEquals("Min 11 - 11", length_11, validator.validate(length_11));
assertEquals("Min 11 - 12", length_12, validator.validate(length_12));
assertEquals("Min 11 - 20", length_20, validator.validate(length_20));
assertEquals("Min 11 - 21", length_21, validator.validate(length_21));
assertEquals("Min 11 - 22", length_22, validator.validate(length_22));
validator = new CodeValidator((String)null, -1, 21, (CheckDigit)null);
assertEquals("Max 21 - min", -1, validator.getMinLength());
assertEquals("Max 21 - max", 21, validator.getMaxLength());
assertEquals("Max 21 - 10", length_10, validator.validate(length_10));
assertEquals("Max 21 - 11", length_11, validator.validate(length_11));
assertEquals("Max 21 - 12", length_12, validator.validate(length_12));
assertEquals("Max 21 - 20", length_20, validator.validate(length_20));
assertEquals("Max 21 - 21", length_21, validator.validate(length_21));
assertEquals("Max 21 - 22", null, validator.validate(length_22));
validator = new CodeValidator((String)null, 11, 21, (CheckDigit)null);
assertEquals("Min 11 / Max 21 - min", 11, validator.getMinLength());
assertEquals("Min 11 / Max 21 - max", 21, validator.getMaxLength());
assertEquals("Min 11 / Max 21 - 10", null, validator.validate(length_10));
assertEquals("Min 11 / Max 21 - 11", length_11, validator.validate(length_11));
assertEquals("Min 11 / Max 21 - 12", length_12, validator.validate(length_12));
assertEquals("Min 11 / Max 21 - 20", length_20, validator.validate(length_20));
assertEquals("Min 11 / Max 21 - 21", length_21, validator.validate(length_21));
assertEquals("Min 11 / Max 21 - 22", null, validator.validate(length_22));
validator = new CodeValidator((String)null, 11, 11, (CheckDigit)null);
assertEquals("Exact 11 - min", 11, validator.getMinLength());
assertEquals("Exact 11 - max", 11, validator.getMaxLength());
assertEquals("Exact 11 - 10", null, validator.validate(length_10));
assertEquals("Exact 11 - 11", length_11, validator.validate(length_11));
assertEquals("Exact 11 - 12", null, validator.validate(length_12));
}
示例7: testRegex
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Test Regular Expression.
*/
public void testRegex() {
CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
String value2 = "12";
String value3 = "123";
String value4 = "1234";
String value5 = "12345";
String invalid = "12a4";
// No Regular Expression
assertNull("No Regex", validator.getRegexValidator());
assertEquals("No Regex 2", value2, validator.validate(value2));
assertEquals("No Regex 3", value3, validator.validate(value3));
assertEquals("No Regex 4", value4, validator.validate(value4));
assertEquals("No Regex 5", value5, validator.validate(value5));
assertEquals("No Regex invalid", invalid, validator.validate(invalid));
// Regular Expression
String regex = "^([0-9]{3,4})$";
validator = new CodeValidator(regex, -1, -1, (CheckDigit)null);
assertNotNull("No Regex", validator.getRegexValidator());
assertEquals("Regex 2", null, validator.validate(value2));
assertEquals("Regex 3", value3, validator.validate(value3));
assertEquals("Regex 4", value4, validator.validate(value4));
assertEquals("Regex 5", null, validator.validate(value5));
assertEquals("Regex invalid", null, validator.validate(invalid));
// Reformatted
regex = "^([0-9]{3})(?:[-\\s])([0-9]{3})$";
validator = new CodeValidator(new RegexValidator(regex), 6, (CheckDigit)null);
assertEquals("Reformat 123-456", "123456", validator.validate("123-456"));
assertEquals("Reformat 123 456", "123456", validator.validate("123 456"));
assertEquals("Reformat 123456", null, validator.validate("123456"));
assertEquals("Reformat 123.456", null, validator.validate("123.456"));
regex = "^(?:([0-9]{3})(?:[-\\s])([0-9]{3}))|([0-9]{6})$";
validator = new CodeValidator(new RegexValidator(regex), 6, (CheckDigit)null);
assertEquals("Reformat 2 Regex", "RegexValidator{" + regex + "}", validator.getRegexValidator().toString());
assertEquals("Reformat 2 123-456", "123456", validator.validate("123-456"));
assertEquals("Reformat 2 123 456", "123456", validator.validate("123 456"));
assertEquals("Reformat 2 123456", "123456", validator.validate("123456"));
}
示例8: testValidator294_1
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
public void testValidator294_1() {
CodeValidator validator = new CodeValidator((String)null, 0, -1, (CheckDigit)null);
assertEquals("Null", null, validator.validate(null));
validator = new CodeValidator((String)null, -1, 0, (CheckDigit)null);
assertEquals("Null", null, validator.validate(null));
}
示例9: testValidator294_2
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
public void testValidator294_2() {
CodeValidator validator = new CodeValidator((String)null, -1, 0, (CheckDigit)null);
assertEquals("Null", null, validator.validate(null));
}
示例10: getCheckDigit
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Return the check digit validation routine.
* <p>
* <b>N.B.</b> Optional, if not set no Check Digit
* validation will be performed on the code.
*
* @return The check digit validation routine
*/
public CheckDigit getCheckDigit() {
return checkdigit;
}
示例11: getCheckDigit
import org.apache.commons.validator.routines.checkdigit.CheckDigit; //导入依赖的package包/类
/**
* Return the check digit validation routine.
* <p>
* <b>N.B.</b> Optional, if not set no Check Digit validation will be performed on the code.
*
* @return The check digit validation routine
*/
public CheckDigit getCheckDigit() {
return checkdigit;
}