Skip to content

Commit

Permalink
Merge pull request #1394 from veraPDF/feature_hash
Browse files Browse the repository at this point in the history
Update FeatureTreeNode hashCode
  • Loading branch information
MaximPlusov authored and Git User committed Dec 12, 2023
1 parent 9f69fb8 commit a61761e
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public FeatureTreeNode addChild(FeatureTreeNode node) throws FeatureParsingExcep
* @param value
* value
* @throws FeatureParsingException
* occurs when value adds to the node with childrens or if the
* occurs when value adds to the node with children or if the
* object is a metadata node and the value is not a hex string
*/
public void setValue(String value) throws FeatureParsingException {
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 children. Node name " + this.name + '.');
}
}

Expand Down Expand Up @@ -170,7 +170,11 @@ public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.attributes == null) ? 0 : this.attributes.hashCode());
result = prime * result + ((this.children == null) ? 0 : this.children.hashCode());
int childrenHashCode = 0;
for (FeatureTreeNode child : this.children) {
childrenHashCode += child.hashCode();
}
result = prime * result + childrenHashCode;
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
result = prime * result + (this.isMetadataNode ? 1 : 0);
Expand Down Expand Up @@ -215,6 +219,6 @@ public String toString() {

private static boolean isChildrenMatch(FeatureTreeNode aThis, FeatureTreeNode other) {
return aThis.children == other.children || (aThis.children.size() == other.children.size() &&
new HashSet<>(aThis.children).containsAll(other.children));
aThis.children.containsAll(other.children));
}
}

0 comments on commit a61761e

Please sign in to comment.