CPD Results
The following document contains the results of PMD's CPD 7.3.0.
Duplications
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/number/AbstractNumberValidationRuleDomain.java | hibernate | 79 |
| uk/pallas/systems/typr/rest/entities/v1/validation/number/AbstractNumberValidationRuleDTO.java | rest | 84 |
result = super.equals(toCompare)
&& Objects.equals(this.getMaximumValue(), that.getMaximumValue())
&& Objects.equals(this.getMinimumValue(), that.getMinimumValue())
&& Objects.equals(this.getUnit(), that.getUnit());
} else {
result = false;
}
return result;
}
/**
* Generates a Unique hashcode for the field definition class.
*
* @return a valid integer representation of this object,
*/
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.getMaximumValue(), this.getMinimumValue(), this.getUnit());
}
/**
* Retrieves the maximum alue that the field definition allows.
*
* @return null is allowed (or a valid N value)
*/
public N getMaximumValue() {
return this.maximumValue;
}
/**
* Sets the maximum value (can be null) for the field definition to apply to the data field during validation.
*
* @param maximum the maximum possible value
*/
public void setMaximumValue(final N maximum) {
this.maximumValue = maximum;
}
/**
* Retrieves the minimum value that the field definition allows.
*
* @return null is allowed (or a valid N value)
*/
public N getMinimumValue() {
return minimumValue;
}
/**
* Sets the mainimum value (can be null) for the field definition to apply to the data field during validation.
*
* @param minimum the minimum possible valid value
*/
public void setMinimumValue(final N minimum) {
this.minimumValue = minimum;
}
/**
* This will compare the incoming object and see if it is a valid whole number and if the value is a valid
* number do we have a maximum or a minimum data range? If there is a upper or lower value (they can be null) then
* it tests the supplied object is less than/equal or greater than/equal as appropriate.
* <p>
* If validationOptional is set to true this will return true by default (no further checks).
*
* @param toTest to test is valid
* @return false if the object isn't a number or if it falls out the expected data range.
*/
public boolean isValid(final Object toTest) {
final Number value = this.getNumber(toTest);
return this.isValid(value);
}
/**
* This will compare the incoming object and see if it is a valid whole number and if the value is a valid
* number do we have a maximum or a minimum data range? If there is a upper or lower value (they can be null) then
* it tests the supplied object is less than/equal or greater than/equal as appropriate.
* <p>
* If validationOptional is set to true this will return true by default (no further checks).
*
* @param toTest to test is valid
* @return false if the object isn't a number or if it falls out the expected data range.
*/
public boolean isValid(final Number toTest) {
final boolean result;
if (null == toTest) {
// The field should be numerical, it isn't ergo ... not valid
result = false;
} else {
final boolean maxValComparison;
if (null == this.getMaximumValue()) {
maxValComparison = true;
} else {
maxValComparison = toTest.doubleValue() <= this.getMaximumValue().doubleValue();
}
final boolean minValComparison;
if (null == this.getMinimumValue()) {
minValComparison = true;
} else {
minValComparison = toTest.doubleValue() >= this.getMinimumValue().doubleValue();
}
result = maxValComparison && minValComparison;
}
return result;
}
/**
* Attempts to confirm the supplied value is a whole number and will return it is true.
*
* @param toConvert the object to test (if Number or a String holding a valid whole number.
* @return null .. or a valid Number.
*/
protected abstract N getNumber(Object toConvert);
public String getUnit() {
return this.unit;
}
public void setUnit(final String unitName) {
this.unit = null == unitName || unitName.isBlank() ? ValidationRuleConstants.NO_UNITS : unitName;
}
} | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/StringValidationRuleDomain.java | hibernate | 55 |
| uk/pallas/systems/typr/rest/entities/v1/validation/StringValidationRuleDTO.java | rest | 60 |
public StringValidationRuleDomain(final StringValidationRule data) {
this(null == data ? null : data.getDescription(), null == data ? null : data.getDetectRegex(),
null == data ? null : data.getExtractRegex());
}
/**
* Compares the supplied object to this one, it checks the supplied object is a FieldDefinition and then checks
* the definition applies validation, its name and description to see if they are matching objects.
*
* @param toCompare the object to compare (can be null or a child class, etc..)
* @return false if the name/validation and description fields in a field definition are
* different (or it isn't a field definition).
*/
@Override
public boolean equals(final Object toCompare) {
final boolean result;
if (this == toCompare) {
result = true;
} else if (toCompare instanceof StringValidationRule that) {
result = super.equals(toCompare)
&& Objects.equals(this.getDetectRegex(), that.getDetectRegex())
&& Objects.equals(this.getExtractRegex(), that.getExtractRegex());
} else {
result = false;
}
return result;
}
/**
* Generates a Unique hashcode for the field definition class.
*
* @return a valid integer representation of this object,
*/
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.getDetectRegex(), this.getExtractRegex());
}
/**
* The regular Expression to apply to a string defined by this field definition, to confirm a given string is valid.
*
* @return non null regular expression that can be used by Java Regex system.
*/
public String getDetectRegex() {
return this.detectRegex;
}
/**
* The regular Expression to apply to a string defined by this field definition, to confirm a given string is valid.
*
* @param validation a valid regular expression string.
*/
public void setDetectRegex(final String validation) {
this.detectRegex = validation;
}
/**
* The regular Expression to extract a matching regex string from a text block.
*
* @return non null regular expression that can be used by Java Regex system.
*/
public String getExtractRegex() {
return this.extractRegex;
}
/**
* Allows us to set the regular expression to extract the term from a text block.
*
* @param validation a valid regular expression string.
*/
public void setExtractRegex(final String validation) {
this.extractRegex = validation;
}
/**
* Is the supplied test object something that matches against our field definition regular expression?
* <p>
* If validation optional is set to true this will return true, if the supplied object is null, this will always
* return false. Otherwise this will call toString and then match the field definition regex tp confirm the object
* matches our desired value.
*
* @param toTest to test is valid
* @return false if the object fails the validation match.
*/
@Override
public boolean isValid(final Object toTest) {
final boolean result;
if (toTest instanceof String) {
// Use to string as it leaves things the most flexible in our regex comparison.
result = this.isValid((String) toTest);
} else {
result = false;
}
return result;
}
/**
* Is the supplied test object something that matches against our field definition regular expression?
* <p>
* If validation optional is set to true this will return true, if the supplied object is null, this will always
* return false. Otherwise it will call matches on the supplied string.
*
* @param toTest to test is valid
* @return false if the object fails the validation match.
*/
@Override
public boolean isValid(final String toTest) {
final boolean result;
if (null == toTest) {
result = false;
} else {
result = toTest.matches(this.getDetectRegex());
}
return result;
}
} | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/EnumValidationRuleDomain.java | hibernate | 46 |
| uk/pallas/systems/typr/rest/entities/v1/validation/EnumValidationRuleDTO.java | rest | 51 |
public EnumValidationRuleDomain(final EnumValidationRule data) {
this(null == data ? null : data.getDescription(), null == data ? null : data.getEnumerates());
}
/**
* Compares the supplied object to this one, it checks the supplied object is a FieldDefinition and then checks
* the definition applies validation, its name and description to see if they are matching objects.
*
* @param toCompare the object to compare (can be null or a child class, etc..)
* @return false if the name/validation and description fields in a field definition are
* different (or it isn't a field definition).
*/
@Override
public boolean equals(final Object toCompare) {
final boolean result;
if (this == toCompare) {
result = true;
} else if (toCompare instanceof EnumValidationRule that) {
result = super.equals(toCompare)
&& this.getEnumerates().containsAll(that.getEnumerates())
&& that.getEnumerates().containsAll(this.getEnumerates());
} else {
result = false;
}
return result;
}
/**
* Generates a Unique hashcode for the field definition class.
*
* @return a valid integer representation of this object,
*/
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.getEnumerates());
}
@Override
public Collection<String> getEnumerates() {
return new HashSet<>(this.enumerates);
}
@Override
public void setEnumerates(final Collection<String> enums) {
if (null == enums) {
this.enumerates.clear();
} else {
this.enumerates.clear();
this.enumerates.addAll(enums);
}
}
/**
* Is the supplied test object something that matches against our field definition regular expression?
* <p>
* If validation optional is set to true this will return true, if the supplied object is null, this will always
* return false. Otherwise this will call toString and then match the field definition regex tp confirm the object
* matches our desired value.
*
* @param toTest to test is valid
* @return false if the object fails the validation match.
*/
@Override
public boolean isValid(final Object toTest) {
final boolean result;
if (toTest instanceof String) {
// Use to string as it leaves things the most flexible in our regex comparison.
result = this.isValid((String) toTest);
} else {
result = false;
}
return result;
}
/**
* Is the supplied test object something that matches against our field definition regular expression?
* <p>
* If validation optional is set to true this will return true, if the supplied object is null, this will always
* return false. Otherwise it will call matches on the supplied string.
*
* @param toTest to test is valid
* @return false if the object fails the validation match.
*/
public boolean isValid(final String toTest) {
final boolean result;
if (null == toTest) {
result = false;
} else {
result = this.getEnumerates().contains(toTest);
}
return result;
}
} | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/TimeValidationRuleDomain.java | hibernate | 56 |
| uk/pallas/systems/typr/rest/entities/v1/validation/TimeValidationRuleDTO.java | rest | 51 |
public TimeValidationRuleDomain(final TimeValidationRule data) {
this(null == data ? null : data.getDescription(), null == data ? null : data.getTimePattern());
}
/**
* Compares the supplied object to this one, it checks the supplied object is a FieldDefinition and then checks
* the definition applies validation, its name and description to see if they are matching objects.
*
* @param toCompare the object to compare (can be null or a child class, etc..)
* @return false if the name/validation and description fields in a field definition are
* different (or it isn't a field definition).
*/
@Override
public boolean equals(final Object toCompare) {
final boolean result;
if (this == toCompare) {
result = true;
} else if (toCompare instanceof TimeValidationRule that) {
result = super.equals(toCompare)
&& Objects.equals(this.getTimePattern(), that.getTimePattern());
} else {
result = false;
}
return result;
}
/**
* Generates a Unique hashcode for the field definition class.
*
* @return a valid integer representation of this object,
*/
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.getTimePattern());
}
/**
* {@inheritDoc}
* @return representation of the time pattern held in the rule.
*/
@Override
public String getTimePattern() {
return this.timePattern;
}
/**
* {@inheritDoc}
* @param pattern A pattern using Java annotation.
*/
@Override
public void setTimePattern(final String pattern) {
if (null == pattern || pattern.isBlank()) {
this.timePattern = ValidationRuleConstants.ISO_8601_DATE;
} else {
this.timePattern = pattern;
}
}
/**
* Checks the incoming object is based on a string and can be converted into a date using the time pattern
* supplied with the object.
*
* @param toTest to test is valid
* @return false if the supplied object can't be converted.
*/
@Override
public boolean isValid(final Object toTest) {
final DateFormat formattter = new SimpleDateFormat(this.getTimePattern());
formattter.setLenient(false);
boolean result = false;
try {
if (toTest instanceof String dateString) {
result = null != formattter.parse(dateString);
}
} catch (final ParseException exception) {
LOGGER.error(
String.format("Unable to parse: %s to test for date with pattern: %s", toTest, this.getTimePattern()));
}
return result;
}
} | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/wrapper/CountryCodeRuleWrapperDomain.java | hibernate | 92 |
| uk/pallas/systems/typr/rest/entities/v1/validation/wrapper/CountryCodeRuleWrapperDTO.java | rest | 65 |
public CountryCodeRuleWrapperDomain(final String code, final ValidationRule validRule) {
this.countryCode = Objects.requireNonNullElse(code, ValidationRuleConstants.DEFAULT_COUNTRY_CODE);
this.setRule(validRule);
}
/**
* Compares the supplied object to this one, it checks the supplied object is a FieldDefinition and then checks
* the definition applies validation, its name and description to see if they are matching objects.
*
* @param toCompare the object to compare (can be null or a child class, etc..)
* @return false if the name/validation and description fields in a field definition are
* different (or it isn't a field definition).
*/
@Override
public boolean equals(final Object toCompare) {
final boolean result;
if (this == toCompare) {
result = true;
} else if (toCompare instanceof CountryCodeWrapper that) {
result = Objects.equals(this.getCountryCode(), that.getCountryCode())
&& Objects.equals(this.getRule(), that.getRule());
} else {
result = false;
}
return result;
}
/**
* Generates a Unique hashcode for the field definition class.
*
* @return a valid integer representation of this object,
*/
@Override
public int hashCode() {
return Objects.hash(this.getCountryCode(), this.getRule());
}
@Override
public String getCountryCode() {
return this.countryCode;
}
@Override
public void setCountryCode(final String code) {
this.countryCode = Objects.requireNonNullElse(code, ValidationRuleConstants.DEFAULT_COUNTRY_CODE);
}
/**
* Retrieves a hopefully detailed description of the field definition so we can understand what it is for and
* why it exists.
*
* @return a hopefull long valid string (null is possible).
*/
@Override
public String getDescription() {
final String result;
if (null == this.doubleRule) { | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/FieldDefinitionDomain.java | hibernate | 140 |
| uk/pallas/systems/typr/rest/entities/v1/FieldDefinitionDTO.java | rest | 106 |
this.timeRules = new HashSet<>();
this.setRules(rules);
}
/**
* Compares the supplied object to this one, it checks the supplied object is a FieldDefinition and then checks
* the definition applies validation, its name and description to see if they are matching objects.
*
* @param toCompare the object to compare (can be null or a child class, etc..)
* @return false if the name/validation and description fields in a field definition are
* different (or it isn't a field definition).
*/
@Override
public boolean equals(final Object toCompare) {
final boolean result;
if (this == toCompare) {
result = true;
} else if (toCompare instanceof FieldDefinition that) {
result = Objects.equals(this.getName(), that.getName())
&& Objects.equals(this.getAcronym(), that.getAcronym())
&& Objects.equals(this.getDescription(), that.getDescription())
&& this.getCategories().containsAll(that.getCategories())
&& that.getCategories().containsAll(this.getCategories()) | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/number/DoubleValidationRuleDomain.java | hibernate | 41 |
| uk/pallas/systems/typr/rest/entities/v1/validation/number/DoubleValidationRuleDTO.java | rest | 43 |
public DoubleValidationRuleDomain(final Double max, final Double min, final String detailedDescription,
final String unitName) {
super(max, min, detailedDescription, unitName);
}
/**
* Attempts to confirm the supplied value is a whole number and will return it is true.
*
* @param toConvert the object to test (if Number or a String holding a valid whole number.
* @return null .. or a valid Number.
*/
@Override
protected Double getNumber(final Object toConvert) {
Double result = null;
if (toConvert instanceof Number) {
result = ((Number) toConvert).doubleValue();
} else if (null != toConvert) {
try {
result = Double.parseDouble(toConvert.toString());
} catch (final NumberFormatException exception) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(String.format("getNumber - Unable to convert %s to Double", toConvert));
}
}
}
return result;
}
} | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/AbstractValidationRuleDomain.java | hibernate | 56 |
| uk/pallas/systems/typr/rest/entities/v1/validation/AbstractValidationRuleDTO.java | rest | 36 |
}
/**
* Retrieves a hopefully detailed description of the field definition so we can understand what it is for and
* why it exists.
*
* @return a hopefull long valid string (null is possible).
*/
@Override
public String getDescription() {
return this.description;
}
/**
* Sets the description to attach to this field definition.
*
* @param detailedDescription the description to attache (null is ok)
*/
@Override
public void setDescription(final String detailedDescription) {
this.description = detailedDescription;
}
/**
* Compares the supplied object to this one, it checks the supplied object is a FieldDefinition and then checks
* the definition applies validation, its name and description to see if they are matching objects.
*
* @param toCompare the object to compare (can be null or a child class, etc..)
* @return false if the name/validation and description fields in a field definition are
* different (or it isn't a field definition).
*/
@Override
public boolean equals(final Object toCompare) {
final boolean result;
if (this == toCompare) {
result = true;
} else if (toCompare instanceof ValidationRule that) {
result = Objects.equals(this.getDescription(), that.getDescription());
} else {
result = false;
}
return result;
}
/**
* Generates a Unique hashcode for the field definition class.
*
* @return a valid integer representation of this object,
*/
@Override
public int hashCode() {
return Objects.hash(this.getDescription());
}
} | ||
| File | Project | Line |
|---|---|---|
| uk/pallas/systems/typr/domain/entities/v1/validation/number/LongValidationRuleDomain.java | hibernate | 42 |
| uk/pallas/systems/typr/rest/entities/v1/validation/number/LongValidationRuleDTO.java | rest | 47 |
super(max, min, detailedDescription, unit);
}
/**
* Attempts to confirm the supplied value is a whole number and will return it is true.
*
* @param toConvert the object to test (if Number or a String holding a valid whole number.
* @return null .. or a valid Number.
*/
@Override
protected Long getNumber(final Object toConvert) {
Long result = null;
if (toConvert instanceof Number) {
result = ((Number) toConvert).longValue();
} else if (null != toConvert) {
try {
final Double value = Double.valueOf(toConvert.toString());
result = value.longValue();
} catch (final NumberFormatException exception) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(String.format("getNumber - Unable to convert %s to Double", toConvert));
}
}
}
return result;
}
} | ||