diff --git a/core/src/main/java/org/verapdf/ReleaseDetails.java b/core/src/main/java/org/verapdf/ReleaseDetails.java index b617d4ff8..8b3b70d27 100644 --- a/core/src/main/java/org/verapdf/ReleaseDetails.java +++ b/core/src/main/java/org/verapdf/ReleaseDetails.java @@ -27,12 +27,7 @@ import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Set; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -117,29 +112,23 @@ public int hashCode() { */ @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ReleaseDetails other = (ReleaseDetails) obj; - if (this.buildDate == null) { - if (other.buildDate != null) - return false; - } else if (!this.buildDate.equals(other.buildDate)) + if (!Objects.equals(this.buildDate, other.buildDate)) { return false; - if (this.id == null) { - if (other.id != null) - return false; - } else if (!this.id.equals(other.id)) - return false; - if (this.version == null) { - if (other.version != null) - return false; - } else if (!this.version.equals(other.version)) + } + if (!Objects.equals(this.id, other.id)) { return false; - return true; + } + return Objects.equals(this.version, other.version); } /** diff --git a/core/src/main/java/org/verapdf/component/ComponentDetailsImpl.java b/core/src/main/java/org/verapdf/component/ComponentDetailsImpl.java index 2e88bf127..61531bcab 100644 --- a/core/src/main/java/org/verapdf/component/ComponentDetailsImpl.java +++ b/core/src/main/java/org/verapdf/component/ComponentDetailsImpl.java @@ -24,6 +24,7 @@ package org.verapdf.component; import java.net.URI; +import java.util.Objects; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; @@ -140,42 +141,19 @@ public boolean equals(Object obj) { return false; } ComponentDetailsImpl other = (ComponentDetailsImpl) obj; - if (this.description == null) { - if (other.description != null) { - return false; - } - } else if (!this.description.equals(other.description)) { + if (!Objects.equals(this.description, other.description)) { return false; } - if (this.id == null) { - if (other.id != null) { - return false; - } - } else if (!this.id.equals(other.id)) { + if (!Objects.equals(this.id, other.id)) { return false; } - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { + if (!Objects.equals(this.name, other.name)) { return false; } - if (this.provider == null) { - if (other.provider != null) { - return false; - } - } else if (!this.provider.equals(other.provider)) { + if (!Objects.equals(this.provider, other.provider)) { return false; } - if (this.version == null) { - if (other.version != null) { - return false; - } - } else if (!this.version.equals(other.version)) { - return false; - } - return true; + return Objects.equals(this.version, other.version); } static ComponentDetails defaultInstance() { diff --git a/core/src/main/java/org/verapdf/core/MapBackedDirectory.java b/core/src/main/java/org/verapdf/core/MapBackedDirectory.java index d080b937d..e7b86f800 100644 --- a/core/src/main/java/org/verapdf/core/MapBackedDirectory.java +++ b/core/src/main/java/org/verapdf/core/MapBackedDirectory.java @@ -113,16 +113,9 @@ public boolean equals(Object obj) { return false; @SuppressWarnings("unchecked") Directory other = (Directory) obj; - if (this.getItems() == null) { - if (other.getItems() != null) - return false; - } else if (!this.getItems().equals(other.getItems())) + if (!Objects.equals(this.getItems(), other.getItems())) { return false; - if (this.getKeys() == null) { - if (other.getKeys() != null) - return false; - } else if (!this.getKeys().equals(other.getKeys())) - return false; - return true; + } + return Objects.equals(this.getKeys(), other.getKeys()); } } diff --git a/core/src/main/java/org/verapdf/core/utils/VersioningMapper.java b/core/src/main/java/org/verapdf/core/utils/VersioningMapper.java index 0be0f97ba..22bd8649a 100644 --- a/core/src/main/java/org/verapdf/core/utils/VersioningMapper.java +++ b/core/src/main/java/org/verapdf/core/utils/VersioningMapper.java @@ -101,15 +101,14 @@ static VersioningMapper newInstance(final FileOutputMapper mapper) { static String verStart(final File orig) { final String origName = orig.getName(); - final String verStart = (origName.lastIndexOf(".") < 1) ? origName + verPrefixOpen //$NON-NLS-1$ - : origName.substring(0, origName.lastIndexOf(".")) + verPrefixOpen; //$NON-NLS-1$ + final String verStart = (origName.lastIndexOf('.') < 1 ? origName : origName.substring(0, origName.lastIndexOf('.'))) + verPrefixOpen; //$NON-NLS-1$ return verStart; } static String verEnd(final File orig) { final String origName = orig.getName(); - final String verEnd = (origName.lastIndexOf(".") < 1) ? verPrefixClose //$NON-NLS-1$ - : verPrefixClose + origName.substring(origName.lastIndexOf(".")); //$NON-NLS-1$ + final String verEnd = (origName.lastIndexOf('.') < 1) ? verPrefixClose //$NON-NLS-1$ + : verPrefixClose + origName.substring(origName.lastIndexOf('.')); //$NON-NLS-1$ return verEnd; } diff --git a/core/src/main/java/org/verapdf/features/FeatureExtractorConfigImpl.java b/core/src/main/java/org/verapdf/features/FeatureExtractorConfigImpl.java index 768f1968b..31e073c1f 100644 --- a/core/src/main/java/org/verapdf/features/FeatureExtractorConfigImpl.java +++ b/core/src/main/java/org/verapdf/features/FeatureExtractorConfigImpl.java @@ -21,6 +21,7 @@ package org.verapdf.features; import java.util.EnumSet; +import java.util.Objects; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; @@ -90,12 +91,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; FeatureExtractorConfigImpl other = (FeatureExtractorConfigImpl) obj; - if (this.enabledFeatures == null) { - if (other.enabledFeatures != null) - return false; - } else if (!this.enabledFeatures.equals(other.enabledFeatures)) - return false; - return true; + return Objects.equals(this.enabledFeatures, other.enabledFeatures); } static class Adapter extends XmlAdapter { diff --git a/core/src/main/java/org/verapdf/features/tools/FeatureTreeNode.java b/core/src/main/java/org/verapdf/features/tools/FeatureTreeNode.java index 17364c646..2560c62ef 100644 --- a/core/src/main/java/org/verapdf/features/tools/FeatureTreeNode.java +++ b/core/src/main/java/org/verapdf/features/tools/FeatureTreeNode.java @@ -100,13 +100,13 @@ public FeatureTreeNode addChild(FeatureTreeNode node) throws FeatureParsingExcep throw new IllegalArgumentException("Arg node cannot be null."); if (this.isMetadataNode) { throw new FeatureParsingException("You can not add a child for metadata nodes. Node name " + this.name - + ", value: " + this.value + "."); + + ", value: " + this.value + '.'); } if (this.value == null) { this.children.add(node); } else { throw new FeatureParsingException("You can not add a child for nodes with defined values. Node name " - + this.name + ", value: " + this.value + "."); + + this.name + ", value: " + this.value + '.'); } return node; } @@ -129,7 +129,7 @@ public void setValue(String value) throws FeatureParsingException { this.value = value; } else { throw new FeatureParsingException( - "You can not add value for nodes with childrens. Node name " + this.name + "."); + "You can not add value for nodes with childrens. Node name " + this.name + '.'); } } @@ -179,38 +179,29 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } FeatureTreeNode other = (FeatureTreeNode) obj; if (this.isMetadataNode != other.isMetadataNode) { return false; - } else if (this.attributes == null) { - if (other.attributes != null) - return false; - } else if (!this.attributes.equals(other.attributes)) + } + if (!Objects.equals(this.attributes, other.attributes)) { return false; - if (this.children == null) { - if (other.children != null) - return false; - } else if (!isChildrenMatch(this, other)) + } + if (!isChildrenMatch(this, other)) { return false; - if (this.name == null) { - if (other.name != null) - return false; - } else if (!this.name.equals(other.name)) + } + if (!Objects.equals(this.name, other.name)) { return false; - if (this.value == null) { - if (other.value != null) - return false; - } else { - if (!this.value.equals(other.value)) - return false; } - return true; + return Objects.equals(this.value, other.value); } /** @@ -219,10 +210,11 @@ public boolean equals(Object obj) { @Override public String toString() { return "FeatureTreeNode [name=" + this.name + ", value=" + this.value + ", isMetadataNode=" - + this.isMetadataNode + ", " + ", attributes=" + this.attributes + "]"; + + this.isMetadataNode + ", " + ", attributes=" + this.attributes + ']'; } private static boolean isChildrenMatch(FeatureTreeNode aThis, FeatureTreeNode other) { - return Objects.equals(aThis.children, other.children); + return aThis.children == other.children || (aThis.children.size() == other.children.size() && + new HashSet<>(aThis.children).containsAll(other.children)); } } diff --git a/core/src/main/java/org/verapdf/metadata/fixer/FixerConfigImpl.java b/core/src/main/java/org/verapdf/metadata/fixer/FixerConfigImpl.java index 7f806ebb7..dad70696c 100644 --- a/core/src/main/java/org/verapdf/metadata/fixer/FixerConfigImpl.java +++ b/core/src/main/java/org/verapdf/metadata/fixer/FixerConfigImpl.java @@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.Objects; /** * @author Evgeniy Muravitskiy @@ -77,14 +78,7 @@ public boolean equals(Object obj) { return false; } FixerConfigImpl other = (FixerConfigImpl) obj; - if (this.fixesPrefix == null) { - if (other.fixesPrefix != null) { - return false; - } - } else if (!this.fixesPrefix.equals(other.fixesPrefix)) { - return false; - } - return true; + return Objects.equals(this.fixesPrefix, other.fixesPrefix); } /** diff --git a/core/src/main/java/org/verapdf/pdfa/results/LocationImpl.java b/core/src/main/java/org/verapdf/pdfa/results/LocationImpl.java index 537d0f8ec..580f8640b 100644 --- a/core/src/main/java/org/verapdf/pdfa/results/LocationImpl.java +++ b/core/src/main/java/org/verapdf/pdfa/results/LocationImpl.java @@ -23,6 +23,7 @@ */ package org.verapdf.pdfa.results; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -100,17 +101,10 @@ public final boolean equals(Object obj) { if (!(obj instanceof Location)) return false; Location other = (Location) obj; - if (this.context == null) { - if (other.getContext() != null) - return false; - } else if (!this.context.equals(other.getContext())) + if (!Objects.equals(this.getContext(), other.getContext())) { return false; - if (this.level == null) { - if (other.getLevel() != null) - return false; - } else if (!this.level.equals(other.getLevel())) - return false; - return true; + } + return Objects.equals(this.getLevel(), other.getLevel()); } /** diff --git a/core/src/main/java/org/verapdf/pdfa/results/TestAssertionImpl.java b/core/src/main/java/org/verapdf/pdfa/results/TestAssertionImpl.java index 26ce71863..f72283e69 100644 --- a/core/src/main/java/org/verapdf/pdfa/results/TestAssertionImpl.java +++ b/core/src/main/java/org/verapdf/pdfa/results/TestAssertionImpl.java @@ -33,6 +33,7 @@ import org.verapdf.pdfa.validation.profiles.RuleId; import java.util.List; +import java.util.Objects; /** * @author Carl Wilson @@ -167,34 +168,21 @@ public boolean equals(Object obj) { if (!(obj instanceof TestAssertion)) return false; TestAssertion other = (TestAssertion) obj; - if (this.location == null) { - if (other.getLocation() != null) - return false; - } else if (!this.location.equals(other.getLocation())) + if (!Objects.equals(this.location, other.getLocation())) { return false; - if (this.message == null) { - if (other.getMessage() != null) - return false; - } else if (!this.message.equals(other.getMessage())) + } + if (!Objects.equals(this.message, other.getMessage())) { return false; - if (this.ruleId == null) { - if (other.getRuleId() != null) - return false; - } else if (!this.ruleId.equals(other.getRuleId())) + } + if (!Objects.equals(this.ruleId, other.getRuleId())) { return false; + } if (this.status != other.getStatus()) return false; - if (this.locationContext == null) { - if (other.getLocationContext() != null) - return false; - } else if (!this.locationContext.equals(other.getLocationContext())) + if (!Objects.equals(this.getLocationContext(), other.getLocationContext())) { return false; - if (this.errorMessage == null) { - if (other.getErrorMessage() != null) - return false; - } else if (!this.errorMessage.equals(other.getErrorMessage())) - return false; - return true; + } + return Objects.equals(this.getErrorMessage(), other.getErrorMessage()); } /** diff --git a/core/src/main/java/org/verapdf/pdfa/validation/profiles/ProfileDetailsImpl.java b/core/src/main/java/org/verapdf/pdfa/validation/profiles/ProfileDetailsImpl.java index b3683af46..d919e6e42 100644 --- a/core/src/main/java/org/verapdf/pdfa/validation/profiles/ProfileDetailsImpl.java +++ b/core/src/main/java/org/verapdf/pdfa/validation/profiles/ProfileDetailsImpl.java @@ -24,6 +24,7 @@ package org.verapdf.pdfa.validation.profiles; import java.util.Date; +import java.util.Objects; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; @@ -120,27 +121,16 @@ public boolean equals(Object obj) { if (!(obj instanceof ProfileDetails)) return false; ProfileDetails other = (ProfileDetails) obj; - if (this.created == null) { - if (other.getDateCreated() != null) - return false; - } else if (!this.created.equals(other.getDateCreated())) + if (!Objects.equals(this.getDateCreated(), other.getDateCreated())) { return false; - if (this.creator == null) { - if (other.getCreator() != null) - return false; - } else if (!this.creator.equals(other.getCreator())) - return false; - if (this.description == null) { - if (other.getDescription() != null) - return false; - } else if (!this.description.equals(other.getDescription())) + } + if (!Objects.equals(this.getCreator(), other.getCreator())) { return false; - if (this.name == null) { - if (other.getName() != null) - return false; - } else if (!this.name.equals(other.getName())) + } + if (!Objects.equals(this.getDescription(), other.getDescription())) { return false; - return true; + } + return Objects.equals(this.getName(), other.getName()); } /** diff --git a/core/src/main/java/org/verapdf/pdfa/validation/profiles/ReferenceImpl.java b/core/src/main/java/org/verapdf/pdfa/validation/profiles/ReferenceImpl.java index dc369b917..60b03e702 100644 --- a/core/src/main/java/org/verapdf/pdfa/validation/profiles/ReferenceImpl.java +++ b/core/src/main/java/org/verapdf/pdfa/validation/profiles/ReferenceImpl.java @@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.Objects; /** * JAXB serialisable implementation of {@link Reference} with safe methods for @@ -102,17 +103,10 @@ public final boolean equals(Object obj) { if (!(obj instanceof Reference)) return false; Reference other = (Reference) obj; - if (this.clause == null) { - if (other.getClause() != null) - return false; - } else if (!this.clause.equals(other.getClause())) + if (!Objects.equals(this.getClause(), other.getClause())) { return false; - if (this.specification == null) { - if (other.getSpecification() != null) - return false; - } else if (!this.specification.equals(other.getSpecification())) - return false; - return true; + } + return Objects.equals(this.getSpecification(), other.getSpecification()); } /* diff --git a/core/src/main/java/org/verapdf/pdfa/validation/profiles/ValidationProfileImpl.java b/core/src/main/java/org/verapdf/pdfa/validation/profiles/ValidationProfileImpl.java index 07a130837..bfaa51f6e 100644 --- a/core/src/main/java/org/verapdf/pdfa/validation/profiles/ValidationProfileImpl.java +++ b/core/src/main/java/org/verapdf/pdfa/validation/profiles/ValidationProfileImpl.java @@ -201,27 +201,16 @@ public boolean equals(Object obj) { ValidationProfile other = (ValidationProfile) obj; if (this.flavour != other.getPDFAFlavour()) return false; - if (this.hash == null) { - if (other.getHexSha1Digest() != null) - return false; - } else if (!this.hash.equals(other.getHexSha1Digest())) + if (!Objects.equals(this.getHexSha1Digest(), other.getHexSha1Digest())) { return false; - if (this.details == null) { - if (other.getDetails() != null) - return false; - } else if (!this.details.equals(other.getDetails())) - return false; - if (this.rules == null) { - if (other.getRules() != null) - return false; - } else if (!this.rules.equals(other.getRules())) + } + if (!Objects.equals(this.getDetails(), other.getDetails())) { return false; - if (this.variables == null) { - if (other.getVariables() != null) - return false; - } else if (!this.variables.equals(other.getVariables())) + } + if (!Objects.equals(this.getRules(), other.getRules())) { return false; - return true; + } + return Objects.equals(this.getVariables(), other.getVariables()); } /** diff --git a/core/src/main/java/org/verapdf/pdfa/validation/profiles/VariableImpl.java b/core/src/main/java/org/verapdf/pdfa/validation/profiles/VariableImpl.java index 04a91a9e4..f3d015328 100644 --- a/core/src/main/java/org/verapdf/pdfa/validation/profiles/VariableImpl.java +++ b/core/src/main/java/org/verapdf/pdfa/validation/profiles/VariableImpl.java @@ -27,6 +27,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.Objects; /** * JAXB serialisable implementation of {@link Variable} with safe methods for @@ -130,27 +131,16 @@ public final boolean equals(Object obj) { if (!(obj instanceof Variable)) return false; Variable other = (Variable) obj; - if (this.name == null) { - if (other.getName() != null) - return false; - } else if (!this.name.equals(other.getName())) + if (!Objects.equals(this.getName(), other.getName())) { return false; - if (this.value == null) { - if (other.getValue() != null) - return false; - } else if (!this.value.equals(other.getValue())) - return false; - if (this.defaultValue == null) { - if (other.getDefaultValue() != null) - return false; - } else if (!this.defaultValue.equals(other.getDefaultValue())) + } + if (!Objects.equals(this.getValue(), other.getValue())) { return false; - if (this.object == null) { - if (other.getObject() != null) - return false; - } else if (!this.object.equals(other.getObject())) + } + if (!Objects.equals(this.getDefaultValue(), other.getDefaultValue())) { return false; - return true; + } + return Objects.equals(this.getObject(), other.getObject()); } /* diff --git a/core/src/main/java/org/verapdf/processor/TaskResultImpl.java b/core/src/main/java/org/verapdf/processor/TaskResultImpl.java index b10ef1023..184dd228e 100644 --- a/core/src/main/java/org/verapdf/processor/TaskResultImpl.java +++ b/core/src/main/java/org/verapdf/processor/TaskResultImpl.java @@ -31,6 +31,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.Objects; /** * @author Carl Wilson @@ -150,18 +151,10 @@ public boolean equals(Object obj) { if (this.type != other.type) { return false; } - if (this.duration == null) { - if (other.duration != null) { - return false; - } - } else if (!this.duration.equals(other.duration)) { + if (!Objects.equals(this.duration, other.duration)) { return false; } - if (this.exception == null) { - if (other.exception != null) { - return false; - } - } else if (!this.exception.equals(other.exception)) { + if (!Objects.equals(this.exception, other.exception)) { return false; } if (this.isExecuted != other.isExecuted) { diff --git a/core/src/main/java/org/verapdf/processor/app/VeraAppConfigImpl.java b/core/src/main/java/org/verapdf/processor/app/VeraAppConfigImpl.java index e8ce077fa..5c321bbf2 100644 --- a/core/src/main/java/org/verapdf/processor/app/VeraAppConfigImpl.java +++ b/core/src/main/java/org/verapdf/processor/app/VeraAppConfigImpl.java @@ -157,11 +157,7 @@ public boolean equals(Object obj) { if (this.isVerbose != other.isVerbose) { return false; } - if (this.policyFile == null) { - if (other.policyFile != null) { - return false; - } - } else if (!this.policyFile.equals(other.policyFile)) { + if (!Objects.equals(this.policyFile, other.policyFile)) { return false; } if (this.type != other.type) { diff --git a/core/src/main/java/org/verapdf/processor/reports/multithread/writer/JsonReportWriter.java b/core/src/main/java/org/verapdf/processor/reports/multithread/writer/JsonReportWriter.java index fce959155..5a430e0d6 100644 --- a/core/src/main/java/org/verapdf/processor/reports/multithread/writer/JsonReportWriter.java +++ b/core/src/main/java/org/verapdf/processor/reports/multithread/writer/JsonReportWriter.java @@ -26,11 +26,13 @@ public void write(ResultStructure result) { deleteTemp(result); } + @Override public void startDocument() { outputStreamWriter.write("{\"reports\":["); isFirstReport = true; } + @Override public void endDocument() { outputStreamWriter.write("]}"); }