You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2019/10/25 14:22:58 UTC
[uima-uimaj] branch master updated: [UIMA-6136] fix hashcode and
equals for FsIndexComparatorImpl (#13)
This is an automated email from the ASF dual-hosted git repository.
schor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
The following commit(s) were added to refs/heads/master by this push:
new 2b87fc8 [UIMA-6136] fix hashcode and equals for FsIndexComparatorImpl (#13)
2b87fc8 is described below
commit 2b87fc87865e94f33a7fc1fcc169cf49c4f85b91
Author: mischor <ms...@schor.com>
AuthorDate: Fri Oct 25 10:22:50 2019 -0400
[UIMA-6136] fix hashcode and equals for FsIndexComparatorImpl (#13)
* [UIMA-6136] fix hashcode and equals for FsIndexComparatorImpl
* [UIMA-6136] add test case
---
.../uima/cas/impl/FSIndexComparatorImpl.java | 42 ++++++++++++++++++----
.../uima/cas/impl/LinearTypeOrderBuilderImpl.java | 2 +-
.../impl/AnalysisEngine_implTest.java | 25 +++++++++++++
3 files changed, 62 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.
diff --git a/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java b/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
index 2c004cc..cda3ba3 100644
--- a/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
+++ b/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
@@ -26,11 +26,13 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -87,6 +89,7 @@ import org.apache.uima.resource.metadata.impl.TypePriorities_impl;
import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
import org.apache.uima.test.junit_extension.FileCompare;
import org.apache.uima.test.junit_extension.JUnitExtension;
+import org.apache.uima.util.CasCreationUtils;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.Level;
import org.apache.uima.util.Settings;
@@ -431,6 +434,28 @@ public class AnalysisEngine_implTest extends TestCase {
}
}
+ // test for UIMA-6136 Commented out because it generates 2000 lines of output and takes about 5 seconds to run
+// public void testLargeTS() throws Exception {
+// TypeSystemDescription tsd = new TypeSystemDescription_impl();
+//
+// for (int i = 0; i < 500; i++) {
+// TypeDescription type = tsd.addType("Type_" + i, "", CAS.TYPE_NAME_ANNOTATION);
+// for (int f = 0; f < 10; f++) {
+// type.addFeature("Feature_" + f, "", CAS.TYPE_NAME_STRING);
+// }
+// }
+//
+// List<CAS> cas_s = new ArrayList<>();
+// for (int i = 0; i < 2000; i++) {
+// long start = System.currentTimeMillis();
+// cas_s.add(CasCreationUtils.createCas(tsd, null, null));
+// long duration = System.currentTimeMillis() - start;
+// System.out.printf("%d - %d%n", i, duration);
+// }
+//
+// }
+
+
public void testProcess() throws Exception {
try {
// test simple primitive TextAnalysisEngine (using TestAnnotator class)