This is an automated email from the ASF dual-hosted git repository. schor pushed a commit to branch UIMA-6136 in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit b868d4c70c3eaeb5e5c17d1394e2eb9c37f19ce9 Author: Marshall Schor <m...@schor.com> AuthorDate: Wed Oct 23 16:37:19 2019 -0400 [UIMA-6136] fix hashcode and equals for FsIndexComparatorImpl --- .../uima/cas/impl/FSIndexComparatorImpl.java | 42 ++++++++++++++++++---- .../uima/cas/impl/LinearTypeOrderBuilderImpl.java | 2 +- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java index 372299a..ce4af69 100644 --- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java +++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java @@ -159,9 +159,29 @@ public class FSIndexComparatorImpl implements FSIndexComparator { return false; } for (int i = 0; i < max; i++) { - if (this.keySpecs .get(i) != comp.keySpecs .get(i) || - this.directions.get(i) != comp.directions.get(i)) { - return false; + Object keySpec1 = this.keySpecs.get(i); + Object keySpec2 = comp.keySpecs.get(i); + if (keySpec1 instanceof LinearTypeOrder) { + // equals compares the type codes in the ordered arrays for == + if ( ! (((LinearTypeOrder)keySpec1).equals((LinearTypeOrder)keySpec2)) ) { + return false; + } + } else { + FeatureImpl f1 = (FeatureImpl) keySpec1; + FeatureImpl f2 = (FeatureImpl) keySpec2; + boolean featimpl_match = f1.equals(f2) // this compares + // shortName, + // multiplerefs allowed + // highest defining type + // range type name + // also need to confirm offsets are the same + && f1.getOffset() == f2.getOffset() + && f1.getAdjustedOffset() == f2.getAdjustedOffset() + && this.directions.get(i) == comp.directions.get(i); + + if (! featimpl_match) { + return false; + } } } return true; @@ -174,9 +194,19 @@ public class FSIndexComparatorImpl implements FSIndexComparator { result = prime * result + ((this.type == null) ? 31 : type.hashCode()); final int max = this.getNumberOfKeys(); for (int i = 0; i < max; i++) { - Object o = this.keySpecs.get(i); // lto or feature - result = prime * result + o.hashCode(); - result = prime * result + this.directions.get(i); + Object o = this.keySpecs.get(i); // LinearTypeOrder or feature + if (o instanceof LinearTypeOrder) { + result = prime * result + ((LinearTypeOrderBuilderImpl.TotalTypeOrder)o).hashCode(); + } else { + FeatureImpl f = (FeatureImpl)o; + result = prime * result + f.hashCode(); // only shortName, + // multiplerefs allowed + // highest defining type + // range type name + result = prime * result + f.getOffset(); + result = prime * result + f.getAdjustedOffset(); + result = prime * result + this.directions.get(i); + } } return result; } diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/LinearTypeOrderBuilderImpl.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/LinearTypeOrderBuilderImpl.java index add29e4..c32fdcc 100644 --- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/LinearTypeOrderBuilderImpl.java +++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/LinearTypeOrderBuilderImpl.java @@ -50,7 +50,7 @@ public class LinearTypeOrderBuilderImpl implements LinearTypeOrderBuilder { * * */ - private static class TotalTypeOrder implements LinearTypeOrder { + public static class TotalTypeOrder implements LinearTypeOrder { // The explicit order. We keep this since we need to return it. It would // be awkward and inefficient to compute it from lt.