From a61761ed53d3bfc125a90c5b1e7a51be9c0c09e3 Mon Sep 17 00:00:00 2001 From: MaximPlusov Date: Tue, 12 Dec 2023 14:17:36 +0300 Subject: [PATCH] Merge pull request #1394 from veraPDF/feature_hash Update FeatureTreeNode hashCode --- .../org/verapdf/features/tools/FeatureTreeNode.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 2560c62ef..0d9a2b8be 100644 --- a/core/src/main/java/org/verapdf/features/tools/FeatureTreeNode.java +++ b/core/src/main/java/org/verapdf/features/tools/FeatureTreeNode.java @@ -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 { @@ -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 + '.'); } } @@ -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); @@ -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)); } }