Skip to content

Commit

Permalink
Merge pull request #1393 from veraPDF/equals_methods
Browse files Browse the repository at this point in the history
Update equals methods
  • Loading branch information
MaximPlusov authored Dec 12, 2023
2 parents ed1285c + d0b9add commit 6372d8f
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 217 deletions.
35 changes: 12 additions & 23 deletions core/src/main/java/org/verapdf/ReleaseDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand Down
34 changes: 6 additions & 28 deletions core/src/main/java/org/verapdf/component/ComponentDetailsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 3 additions & 10 deletions core/src/main/java/org/verapdf/core/MapBackedDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,9 @@ public boolean equals(Object obj) {
return false;
@SuppressWarnings("unchecked")
Directory<K, V> other = (Directory<K, V>) 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FeatureExtractorConfigImpl, FeatureExtractorConfig> {
Expand Down
46 changes: 19 additions & 27 deletions core/src/main/java/org/verapdf/features/tools/FeatureTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 + '.');
}
}

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
14 changes: 4 additions & 10 deletions core/src/main/java/org/verapdf/pdfa/results/LocationImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.verapdf.pdfa.results;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -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());
}

/**
Expand Down
32 changes: 10 additions & 22 deletions core/src/main/java/org/verapdf/pdfa/results/TestAssertionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.verapdf.pdfa.validation.profiles.RuleId;

import java.util.List;
import java.util.Objects;

/**
* @author <a href="mailto:[email protected]">Carl Wilson</a>
Expand Down Expand Up @@ -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());
}

/**
Expand Down
Loading

0 comments on commit 6372d8f

Please sign in to comment.