CPD Results
The following document contains the results of PMD's CPD 7.1.0.
Duplications
File |
Line |
org/apache/commons/validator/routines/CalendarValidator.java |
218 |
org/apache/commons/validator/routines/TimeValidator.java |
167 |
return compare(value, compare, Calendar.YEAR);
}
/**
* <p>Convert the parsed <code>Date</code> to a <code>Calendar</code>.</p>
*
* @param value The parsed <code>Date</code> object created.
* @param formatter The Format used to parse the value with.
* @return The parsed value converted to a <code>Calendar</code>.
*/
@Override
protected Object processParsedValue(final Object value, final Format formatter) {
return ((DateFormat) formatter).getCalendar();
}
/**
* <p>Validate/convert a <code>Calendar</code> using the default
* <code>Locale</code> and <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @return The parsed <code>Calendar</code> if valid or {@code null}
* if invalid.
*/
public Calendar validate(final String value) {
return (Calendar) parse(value, (String) null, (Locale) null, (TimeZone) null);
}
/**
* <p>Validate/convert a <code>Calendar</code> using the specified
* <code>Locale</code> and default <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param locale The locale to use for the date format, system default if null.
* @return The parsed <code>Calendar</code> if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final Locale locale) {
return (Calendar) parse(value, (String) null, locale, (TimeZone) null);
}
/**
* <p>Validate/convert a <code>Calendar</code> using the specified
* <code>Locale</code> and <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param locale The locale to use for the date format, system default if null.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed <code>Calendar</code> if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final Locale locale, final TimeZone timeZone) {
return (Calendar) parse(value, (String) null, locale, timeZone);
}
/**
* <p>Validate/convert a <code>Calendar</code> using the specified
* <i>pattern</i> and default <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against.
* @return The parsed <code>Calendar</code> if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern) {
return (Calendar) parse(value, pattern, (Locale) null, (TimeZone) null);
}
/**
* <p>Validate/convert a <code>Calendar</code> using the specified pattern
* and <code>Locale</code> and the default <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against, or the
* default for the <code>Locale</code> if {@code null}.
* @param locale The locale to use for the date format, system default if null.
* @return The parsed <code>Calendar</code> if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern, final Locale locale) {
return (Calendar) parse(value, pattern, locale, (TimeZone) null);
}
/**
* <p>Validate/convert a <code>Calendar</code> using the specified
* pattern, and <code>Locale</code> and <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against, or the
* default for the <code>Locale</code> if {@code null}.
* @param locale The locale to use for the date format, system default if null.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed <code>Calendar</code> if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern, final Locale locale, final TimeZone timeZone) {
return (Calendar) parse(value, pattern, locale, timeZone);
}
/**
* <p>Validate/convert a <code>Calendar</code> using the specified
* <i>pattern</i> and <code>TimeZone</code>.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed <code>Calendar</code> if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern, final TimeZone timeZone) {
return (Calendar) parse(value, pattern, (Locale) null, timeZone);
}
/**
* <p>Validate/convert a <code>Calendar</code> using the specified
* <code>TimeZone</code> and default <code>Locale</code>.
*
* @param value The value validation is being performed on.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed <code>Calendar</code> if valid or {@code null}
* if invalid.
*/
public Calendar validate(final String value, final TimeZone timeZone) {
return (Calendar) parse(value, (String) null, (Locale) null, timeZone);
}
} |
File |
Line |
org/apache/commons/validator/routines/checkdigit/CASNumberCheckDigit.java |
107 |
org/apache/commons/validator/routines/checkdigit/ECNumberCheckDigit.java |
90 |
}
/**
* {@inheritDoc}
*/
@Override
public String calculate(final String code) throws CheckDigitException {
if (GenericValidator.isBlankOrNull(code)) {
throw new CheckDigitException("Code is missing");
}
final int modulusResult = INSTANCE.calculateModulus(code, false);
return toCheckDigit(modulusResult);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isValid(final String code) {
if (GenericValidator.isBlankOrNull(code)) {
return false;
}
final Object cde = REGEX_VALIDATOR.validate(code);
if (!(cde instanceof String)) {
return false;
}
try {
final int modulusResult = INSTANCE.calculateModulus((String) cde, true);
return modulusResult == Character.getNumericValue(code.charAt(code.length() - 1));
} catch (final CheckDigitException ex) {
return false;
}
}
} |
File |
Line |
org/apache/commons/validator/routines/checkdigit/ISBN10CheckDigit.java |
54 |
org/apache/commons/validator/routines/checkdigit/ISSNCheckDigit.java |
59 |
public ISBN10CheckDigit() {
super(MODULUS_11);
}
/**
* <p>Convert an integer value to a character at a specified position.</p>
*
* <p>Value '10' for position 1 (check digit) converted to 'X'.</p>
*
* @param charValue The integer value of the character.
* @return The converted character.
* @throws CheckDigitException if an error occurs.
*/
@Override
protected String toCheckDigit(final int charValue)
throws CheckDigitException {
if (charValue == 10) { // CHECKSTYLE IGNORE MagicNumber
return "X";
}
return super.toCheckDigit(charValue);
}
/**
* <p>Convert a character at a specified position to an
* integer value.</p>
*
* <p>Character 'X' check digit converted to 10.</p>
*
* @param character The character to convert.
* @param leftPos The position of the character in the code, counting from left to right
* @param rightPos The position of the character in the code, counting from right to left
* @return The integer value of the character.
* @throws CheckDigitException if an error occurs.
*/
@Override
protected int toInt(final char character, final int leftPos, final int rightPos)
throws CheckDigitException {
if (rightPos == 1 && character == 'X') {
return 10; // CHECKSTYLE IGNORE MagicNumber
}
return super.toInt(character, leftPos, rightPos);
}
/**
* Calculates the <i>weighted</i> value of a character in the
* code at a specified position.
*
* <p>For ISBN-10 (from right to left) digits are weighted
* by their position.</p>
*
* @param charValue The numeric value of the character.
* @param leftPos The position of the character in the code, counting from left to right
* @param rightPos The positionof the character in the code, counting from right to left
* @return The weighted value of the character.
*/
@Override
protected int weightedValue(final int charValue, final int leftPos, final int rightPos) { |
File |
Line |
org/apache/commons/validator/GenericTypeValidator.java |
69 |
org/apache/commons/validator/GenericTypeValidator.java |
342 |
org/apache/commons/validator/GenericTypeValidator.java |
394 |
org/apache/commons/validator/GenericTypeValidator.java |
446 |
Byte result = null;
if (value != null) {
NumberFormat formatter = null;
if (locale != null) {
formatter = NumberFormat.getNumberInstance(locale);
} else {
formatter = NumberFormat.getNumberInstance(Locale.getDefault());
}
formatter.setParseIntegerOnly(true);
final ParsePosition pos = new ParsePosition(0);
final Number num = formatter.parse(value, pos);
// If there was no error and we used the whole string
if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() &&
num.doubleValue() >= Byte.MIN_VALUE && |
|