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 2017/07/20 14:41:08 UTC
svn commit: r1802495 [1/2] -
/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/
Author: schor
Date: Thu Jul 20 14:41:08 2017
New Revision: 1802495
URL: http://svn.apache.org/viewvc?rev=1802495&view=rev
Log:
[UIMA-5504] clean up iterators/indexes
Added:
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_multiple_indexes.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator_empty.java
Removed:
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSListIteratorImpl.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_list.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_unordered.java
Modified:
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorImplBase.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FilteredIterator.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag_pear.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_singletype.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_ordered.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java Thu Jul 20 14:41:08 2017
@@ -20,7 +20,6 @@
package org.apache.uima.cas.impl;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
@@ -30,7 +29,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Vector;
import java.util.function.Consumer;
import java.util.stream.Stream;
@@ -171,7 +169,7 @@ public class FSIndexRepositoryImpl imple
/**
* lazily created comparator using the built-in annotation index
*/
- private Comparator<TOP> annotationFsComparator = null;
+ private Comparator<TOP> annotationFsComparatorWithoutId = null;
private Comparator<TOP> annotationFsComparatorWithId = null;
@@ -752,7 +750,7 @@ public class FSIndexRepositoryImpl imple
switch (indexingStrategy) {
case FSIndex.SET_INDEX:
- ind = new FsIndex_set_sorted<T>(this.cas, type, indexingStrategy, comparatorForIndexSpecs, false); // false = is set
+ ind = new FsIndex_set_sorted<T>(this.cas, type, indexingStrategy, comparatorForIndexSpecs); // false = is set
break;
// case FSIndex.FLAT_INDEX:
@@ -766,7 +764,7 @@ public class FSIndexRepositoryImpl imple
default:
// SORTED_INDEX is the default. We don't throw any errors, if the code is unknown, we just create a sorted index.
- ind = new FsIndex_set_sorted<T>(this.cas, type, FSIndex.SORTED_INDEX, comparatorForIndexSpecs, true); // true = is sorted
+ ind = new FsIndex_set_sorted<T>(this.cas, type, FSIndex.SORTED_INDEX, comparatorForIndexSpecs); // true = is sorted
break;
}
@@ -1787,8 +1785,8 @@ public class FSIndexRepositoryImpl imple
// return this.sii.annotationComparator;
// }
- Comparator<TOP> getAnnotationFsComparator() {
- Comparator<TOP> r = this.sii.annotationFsComparator;
+ public Comparator<TOP> getAnnotationFsComparatorWithoutId() {
+ Comparator<TOP> r = this.sii.annotationFsComparatorWithoutId;
// lazy creation
if (null != r) {
return r;
@@ -1811,7 +1809,7 @@ public class FSIndexRepositoryImpl imple
final LinearTypeOrder lto = getDefaultTypeOrder(); // used as constant in comparator
if (lto.isEmptyTypeOrder()) {
- return this.sii.annotationFsComparator = (fsx1, fsx2) -> {
+ return this.sii.annotationFsComparatorWithoutId = (fsx1, fsx2) -> {
if (fsx1 == fsx2) return 0;
Annotation fs1 = (Annotation) fsx1;
Annotation fs2 = (Annotation) fsx2;
@@ -1819,7 +1817,7 @@ public class FSIndexRepositoryImpl imple
};
} else {
- return this.sii.annotationFsComparator = (fsx1, fsx2) -> {
+ return this.sii.annotationFsComparatorWithoutId = (fsx1, fsx2) -> {
if (fsx1 == fsx2) return 0;
Annotation fs1 = (Annotation) fsx1;
Annotation fs2 = (Annotation) fsx2;
@@ -1876,4 +1874,8 @@ public class FSIndexRepositoryImpl imple
public TypeSystemImpl getTypeSystemImpl() {
return sii.tsi;
}
+
+ public CASImpl getCasImpl() {
+ return cas;
+ }
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorImplBase.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorImplBase.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorImplBase.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorImplBase.java Thu Jul 20 14:41:08 2017
@@ -29,7 +29,7 @@ import org.apache.uima.cas.text.Annotati
* by java.util.Iterator.
* Users writing their own iterator implementations may extend this class
*/
-public abstract class FSIteratorImplBase<T extends FeatureStructure> implements FSIterator<T> {
+public abstract class FSIteratorImplBase<T extends FeatureStructure> implements LowLevelIterator<T> {
// Jira UIMA-464: add annotation comparator to be able to use Collections.binarySearch() on
// annotation list.
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FilteredIterator.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FilteredIterator.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FilteredIterator.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FilteredIterator.java Thu Jul 20 14:41:08 2017
@@ -84,31 +84,16 @@ class FilteredIterator<T extends Feature
adjustForConstraintBackward();
}
- public void moveToNext() {
- this.it.moveToNext();
- adjustForConstraintForward();
- }
-
public void moveToNextNvc() {
this.it.moveToNextNvc();
adjustForConstraintForward();
}
- public void moveToPrevious() {
- this.it.moveToPrevious();
- adjustForConstraintBackward();
- }
-
public void moveToPreviousNvc() {
this.it.moveToPreviousNvc();
adjustForConstraintBackward();
}
- public T get() throws NoSuchElementException {
- // This may throw an exception.
- return this.it.get();
- }
-
public T getNvc() {
return this.it.getNvc();
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_annotation.java Thu Jul 20 14:41:08 2017
@@ -48,7 +48,7 @@ public class FsIndex_annotation <T exten
* @see org.apache.uima.cas.text.AnnotationIndex#iterator(boolean)
*/
@Override
- public FSIterator<T> iterator(boolean ambiguous) {
+ public LowLevelIterator<T> iterator(boolean ambiguous) {
if (ambiguous) {
return iterator();
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_iicp.java Thu Jul 20 14:41:08 2017
@@ -25,10 +25,10 @@ import java.util.Comparator;
import java.util.stream.Stream;
import org.apache.uima.cas.FSIndex;
-import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.admin.FSIndexComparator;
+import org.apache.uima.jcas.cas.TOP;
/**
* FsIndex_iicp (iicp)
@@ -373,15 +373,15 @@ class FsIndex_iicp<T extends FeatureStru
// }
// }
- <T2 extends FeatureStructure> FsIndex_singletype<T2> getNoSubtypeIndexForType(Type type) {
- createIndexIteratorCache();
- for (FsIndex_singletype<FeatureStructure> noSubtypeIndex : cachedSubFsLeafIndexes) {
- if (noSubtypeIndex.getType() == type) {
- return (FsIndex_singletype<T2>) noSubtypeIndex;
- }
- }
- return null;
- }
+// <T2 extends FeatureStructure> FsIndex_singletype<T2> getNoSubtypeIndexForType(Type type) {
+// createIndexIteratorCache();
+// for (FsIndex_singletype<FeatureStructure> noSubtypeIndex : cachedSubFsLeafIndexes) {
+// if (noSubtypeIndex.getType() == type) {
+// return (FsIndex_singletype<T2>) noSubtypeIndex;
+// }
+// }
+// return null;
+// }
FSIndexRepositoryImpl getFSIndexRepositoryImpl() {
return fsIndexRepositoryImpl;
@@ -409,6 +409,14 @@ class FsIndex_iicp<T extends FeatureStru
return fsIndex_singletype.getIndexingStrategy();
}
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIndex#getComparator()
+ */
+ @Override
+ public Comparator<TOP> getComparator() {
+ return fsIndex_singletype.comparatorWithoutID;
+ }
+
@Override
public FSIndexComparator getComparatorForIndexSpecs() {
return fsIndex_singletype.getComparatorForIndexSpecs();
@@ -456,22 +464,22 @@ class FsIndex_iicp<T extends FeatureStru
}
@Override
- public FSIterator<T> iterator() {
+ public LowLevelIterator<T> iterator() {
createIndexIteratorCache();
return (cachedSubFsLeafIndexes.length == 1)
- ? (FSIterator<T>) fsIndex_singletype.iterator()
+ ? (LowLevelIterator<T>) fsIndex_singletype.iterator()
: fsIndex_singletype.isSorted()
? new FsIterator_subtypes_ordered<T>(this)
- : new FsIterator_aggregation_common<T>(new FsIterator_subtypes_unordered<T>(this).allIterators, fsIndex_singletype);
+ : new FsIterator_aggregation_common<T>(this.getIterators(), this);
}
public LowLevelIterator<T> iteratorUnordered() {
createIndexIteratorCache();
return (cachedSubFsLeafIndexes.length == 1)
- ? (FsIterator_singletype<T>) fsIndex_singletype.iterator()
- : new FsIterator_aggregation_common<T>(new FsIterator_subtypes_unordered<T>(this).allIterators, fsIndex_singletype);
+ ? fsIndex_singletype.iterator()
+ : new FsIterator_aggregation_common<T>(getIterators(), this);
}
/**
@@ -529,6 +537,16 @@ class FsIndex_iicp<T extends FeatureStru
return Arrays.stream(cachedSubFsLeafIndexes).filter(idx -> idx.size() > 0);
}
+ LowLevelIterator<T>[] getIterators() {
+ createIndexIteratorCache();
+ LowLevelIterator<T>[] r = new LowLevelIterator[cachedSubFsLeafIndexes.length];
+ int i = 0;
+ for (FsIndex_singletype<FeatureStructure> idx : cachedSubFsLeafIndexes) {
+ r[i++] = (LowLevelIterator<T>) idx.iterator();
+ }
+ return r;
+ }
+
// /* (non-Javadoc)
// * @see org.apache.uima.cas.FSIndex#select()
// */
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_set_sorted.java Thu Jul 20 14:41:08 2017
@@ -48,7 +48,7 @@ import org.apache.uima.jcas.tcas.Annotat
*
* @param <T> the Java class type for this index
*/
-public class FsIndex_set_sorted<T extends FeatureStructure> extends FsIndex_singletype<T> {
+final public class FsIndex_set_sorted<T extends FeatureStructure> extends FsIndex_singletype<T> {
// /**
// * This impl of sorted set interface allows using the bulk add operation implemented in Java's
@@ -58,33 +58,14 @@ public class FsIndex_set_sorted<T extend
// The index, a NavigableSet.
final private OrderedFsSet_array<T> indexedFSs;
-
- final private Comparator<TOP> comparatorWithID;
- final private Comparator<TOP> comparatorWithoutID;
-
// only an optimization used for select.covering for AnnotationIndexes
private int maxAnnotSpan = -1;
- public final boolean isAnnotIdx;
- FsIndex_set_sorted(CASImpl cas, Type type, int indexType, FSIndexComparator comparatorForIndexSpecs, boolean useSorted) {
+ FsIndex_set_sorted(CASImpl cas, Type type, int indexType, FSIndexComparator comparatorForIndexSpecs) {
super(cas, type, indexType, comparatorForIndexSpecs);
- FSIndexRepositoryImpl ir = this.casImpl.indexRepository;
+
- if (ir.isAnnotationIndex(comparatorForIndexSpecs, indexType)) {
- comparatorWithID = ir.getAnnotationFsComparatorWithId();
- comparatorWithoutID = ir.getAnnotationFsComparatorWithoutId();
- isAnnotIdx = true;
- } else {
- isAnnotIdx = false;
- comparatorWithoutID = (o1, o2) -> compare(o1, o2);
- comparatorWithID = useSorted
- ? (o1, o2) -> {
- final int c = compare(o1, o2);
- // augment normal comparator with one that compares IDs if everything else equal
- return (c == 0) ? (Integer.compare(o1._id(), o2._id())) : c;}
- : comparatorWithoutID;
- }
this.indexedFSs = new OrderedFsSet_array<T>(comparatorWithID, comparatorWithoutID);
}
@@ -237,8 +218,10 @@ public class FsIndex_set_sorted<T extend
}
@Override
- public FsIterator_set_sorted2<T> iterator() {
+ public LowLevelIterator<T> iterator() {
CopyOnWriteIndexPart cow_wrapper = getNonNullCow();
+ // if index is empty, return never-the-less a real iterator,
+ // not an empty one, because it may become non-empty
return casImpl.inPearContext()
// ? new FsIterator_set_sorted_pear<>(this, type, this)
// : new FsIterator_set_sorted <>(this, type, this);
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_singletype.java Thu Jul 20 14:41:08 2017
@@ -59,12 +59,16 @@ public abstract class FsIndex_singletype
// A reference to the low-level CAS.
final protected CASImpl casImpl;
-
/**
* comparator for an index, passed in as an argument to the constructor
*/
- final private FSIndexComparatorImpl comparatorForIndexSpecs;
+ final protected FSIndexComparatorImpl comparatorForIndexSpecs;
+
+ final protected Comparator<TOP> comparatorWithID;
+ final protected Comparator<TOP> comparatorWithoutID;
+ public final boolean isAnnotIdx;
+
/*********** Info about Index Comparator (not used for bag ***********
* Index into these arrays is the key number (indexes can have multiple keys)
**********************************************************************/
@@ -101,19 +105,19 @@ public abstract class FsIndex_singletype
"(" + kind + ")[" + type.getShortName() + "]";
}
- // never called
- // declared private to block external calls
- @SuppressWarnings("unused")
- private FsIndex_singletype() {
- this.indexType = 0; // must do because it's final
- this.casImpl = null;
- this.type = null;
- this.typeCode = 0;
- comparatorForIndexSpecs = null;
- keys = null;
- keyTypeCodes = null;
- isReverse = null;
- }
+// // never called
+// // declared private to block external calls
+// @SuppressWarnings("unused")
+// private FsIndex_singletype() {
+// this.indexType = 0; // must do because it's final
+// this.casImpl = null;
+// this.type = null;
+// this.typeCode = 0;
+// comparatorForIndexSpecs = null;
+// keys = null;
+// keyTypeCodes = null;
+// isReverse = null;
+// }
/**
* Constructor for FsIndex_singletype.
@@ -122,7 +126,10 @@ public abstract class FsIndex_singletype
* @param indexType -
* @param comparatorForIndexSpecs -
*/
- protected FsIndex_singletype(CASImpl cas, Type type, int indexType, FSIndexComparator comparatorForIndexSpecs) {
+ protected FsIndex_singletype(CASImpl cas,
+ Type type,
+ int indexType,
+ FSIndexComparator comparatorForIndexSpecs) {
super();
this.indexType = indexType;
this.casImpl = cas;
@@ -139,6 +146,9 @@ public abstract class FsIndex_singletype
this.isReverse = new boolean[nKeys];
if (!this.comparatorForIndexSpecs.isValid()) {
+ isAnnotIdx = false;
+ comparatorWithID = null;
+ comparatorWithoutID = null;
return;
}
@@ -153,6 +163,23 @@ public abstract class FsIndex_singletype
}
isReverse[i] = this.comparatorForIndexSpecs.getKeyComparator(i) == FSIndexComparator.REVERSE_STANDARD_COMPARE;
}
+
+ FSIndexRepositoryImpl ir = this.casImpl.indexRepository;
+ if (ir.isAnnotationIndex(comparatorForIndexSpecs, indexType)) {
+ comparatorWithID = ir.getAnnotationFsComparatorWithId();
+ comparatorWithoutID = ir.getAnnotationFsComparatorWithoutId();
+ isAnnotIdx = true;
+ } else {
+ isAnnotIdx = false;
+ comparatorWithoutID = (o1, o2) -> compare(o1, o2);
+ comparatorWithID = (indexType == FSIndex.SORTED_INDEX)
+ ? (o1, o2) -> {
+ final int c = compare(o1, o2);
+ // augment normal comparator with one that compares IDs if everything else equal
+ return (c == 0) ? (Integer.compare(o1._id(), o2._id())) : c;}
+ : comparatorWithoutID;
+ }
+
}
/**
@@ -182,25 +209,21 @@ public abstract class FsIndex_singletype
*/
abstract boolean deleteFS(T fs);
- /**
- * Common part of iterator creation
- */
- protected CopyOnWriteIndexPart setupIteratorCopyOnWrite() {
- CopyOnWriteIndexPart cow_index_part = getCopyOnWriteIndexPart();
- if (null == wr_cow || null == wr_cow.get()) {
- cow_index_part = createCopyOnWriteIndexPart();
- wr_cow = new WeakReference<>(cow_index_part);
- }
- return cow_index_part;
- }
-
@Override
public LowLevelIterator<T> iterator(FeatureStructure initialPositionFs) {
LowLevelIterator<T> fsIt = iterator();
fsIt.moveTo(initialPositionFs);
return fsIt;
}
-
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIndex#getComparator()
+ */
+ @Override
+ public Comparator<TOP> getComparator() {
+ return comparatorWithoutID;
+ }
+
@Override
public FSIndexComparator getComparatorForIndexSpecs() {
return this.comparatorForIndexSpecs;
@@ -458,5 +481,16 @@ public abstract class FsIndex_singletype
// casImpl.indexRepository.isUsedChanged = true;
}
+///**
+//* Common part of iterator creation
+//*/
+//protected CopyOnWriteIndexPart setupIteratorCopyOnWrite() {
+// CopyOnWriteIndexPart cow_index_part = getCopyOnWriteIndexPart();
+// if (null == wr_cow || null == wr_cow.get()) {
+// cow_index_part = createCopyOnWriteIndexPart();
+// wr_cow = new WeakReference<>(cow_index_part);
+// }
+// return cow_index_part;
+//}
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIndex_snapshot.java Thu Jul 20 14:41:08 2017
@@ -66,7 +66,7 @@ public class FsIndex_snapshot <T extends
* @see org.apache.uima.cas.FSIndex#iterator()
*/
@Override
- public FSIterator<T> iterator() {
+ public LowLevelIterator<T> iterator() {
return new FsIterator_subtypes_snapshot<T>(new FsIndex_flat<T>(wrapped));
}
@@ -116,6 +116,14 @@ public class FsIndex_snapshot <T extends
return wrapped.getCasImpl();
}
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIndex#getComparator()
+ */
+ @Override
+ public Comparator<TOP> getComparator() {
+ return wrapped.getComparator();
+ }
+
@Override
public FSIndexComparator getComparatorForIndexSpecs() {
return wrapped.getComparatorForIndexSpecs();
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_aggregation_common.java Thu Jul 20 14:41:08 2017
@@ -20,6 +20,7 @@
package org.apache.uima.cas.impl;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
@@ -27,145 +28,85 @@ import org.apache.uima.cas.FSIndex;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
+import org.apache.uima.internal.util.Misc;
+import org.apache.uima.jcas.cas.TOP;
/**
* Aggregate several FS iterators. Simply iterates over one after the other
* without any sorting or merging.
* Used by getAllIndexedFS and FsIterator_subtypes_unordered
+ * underlying iterators could be any (bag, set, or ordered
+ * underlying iterators could be complex (unambiguous annotation, filtered,...)
*
* The iterators can be for single types or for types with subtypes.
* Exception: if the ll_index is accessed, it is presumed to be of type FsIndex_subtypes.
- *
- * Doesn't do concurrent mod checking - that's done if wanted by the individual iterators
- * being aggregated over.
- * This results in allowing a few concurrent modifications, when crossing from one iterator to another
- * in moveToNext/Previous (because those get translated to move to first/last, which reset concurrent modification)
*/
-class FsIterator_aggregation_common<T extends FeatureStructure>
- implements LowLevelIterator<T> {
-
- final private LowLevelIterator<T>[] allIterators; // not just for single-type iterators
- private LowLevelIterator<T>[] nonEmptyIterators;
- private FSIterator<T>[] emptyIterators;
-
- private int lastValidIndex;
-
+class FsIterator_aggregation_common<T extends FeatureStructure> extends FsIterator_multiple_indexes<T> {
+
final private FSIndex<T> index; // not used here, but returned via the ll_getIndex api.
FsIterator_aggregation_common(LowLevelIterator<T>[] iterators, FSIndex<T> index) {
- this.allIterators = iterators;
- // can't see the reason for needing to copy the iterators
- // There's a separate call copy() to do that if needed
-// for (int i = iterators.length - 1; i >=0; i--) {
-// this.allIterators[i] = iterators[i].copy();
-// }
-
- separateIntoEmptyAndNonEmptyIterators();
-
+ super(iterators);
this.index = index;
- moveToStart();
- }
-
- private void separateIntoEmptyAndNonEmptyIterators() {
- List<LowLevelIterator<T>> nonEmptyOnes = new ArrayList<>();
- List<LowLevelIterator<T>> emptyOnes = new ArrayList<>();
- for (LowLevelIterator<T> it : allIterators) {
- if (it.ll_indexSize() == 0) {
- emptyOnes.add(it);
- } else {
- nonEmptyOnes.add(it);
- }
- }
- nonEmptyIterators = nonEmptyOnes.toArray(new LowLevelIterator[nonEmptyOnes.size()]);
- emptyIterators = emptyOnes.toArray(new LowLevelIterator[emptyOnes.size()]);
+ moveToFirstNoReinit();
}
- public T get() throws NoSuchElementException {
- if (!isValid()) {
- throw new NoSuchElementException();
- }
- return nonEmptyIterators[lastValidIndex].get();
- }
-
- public T getNvc() {
- return nonEmptyIterators[lastValidIndex].getNvc();
- }
-
- public boolean isValid() {
- return lastValidIndex >= 0 &&
- lastValidIndex < nonEmptyIterators.length &&
- nonEmptyIterators[lastValidIndex].isValid();
- }
-
- public void moveTo(FeatureStructure fs) {
- if (firstChangedEmptyIterator() >= 0) {
- separateIntoEmptyAndNonEmptyIterators();
- }
- // don't need to check isIndexesHaveBeenUpdated because
- // individual aggregated iterators will do that
-
- for (int i = 0, nbrIt = nonEmptyIterators.length; i < nbrIt; i++) {
- FSIterator<T> it = nonEmptyIterators[i];
- if (((LowLevelIterator<T>)it).ll_getIndex().contains(fs)) {
- lastValidIndex = i;
- it.moveTo(fs);
+ /** copy constructor */
+ FsIterator_aggregation_common(FsIterator_aggregation_common v) {
+ super(v);
+ this.index = v.index;
+ }
+
+
+ /**
+ * MoveTo for this kind of iterator
+ * Happens for set or sorted indexes being operated without rattling
+ *
+ */
+ public void moveToNoReinit(FeatureStructure fs) {
+ lastValidIteratorIndex = -1;
+ LowLevelIndex<T> idx = ll_getIndex();
+ Comparator<TOP> comparatorWithoutId = idx.getComparator();
+ int i = -1;
+ for (LowLevelIterator<T> it : nonEmptyIterators) {
+ i++;
+ it.moveTo(fs);
+ if (it.isValid() && 0 == comparatorWithoutId.compare((TOP)it.getNvc(), (TOP) fs)) {
+ lastValidIteratorIndex = i;
return;
}
}
- moveToStart(); // default if not found
- }
-
- public void moveToFirst() {
- if (firstChangedEmptyIterator() >= 0) {
- separateIntoEmptyAndNonEmptyIterators();
- }
- // don't need to check isIndexesHaveBeenUpdated because
- // individual aggregated iterators will do that
-
- moveToStart();
}
- private void moveToStart() {
- for (int i = 0, nbrIt = nonEmptyIterators.length; i < nbrIt; i++) {
- FSIterator<T> it = nonEmptyIterators[i];
- it.moveToFirst();
+ /** moves to the first non-empty iterator at its start position */
+ public void moveToFirstNoReinit() {
+ lastValidIteratorIndex = -1; // no valid index
+ int i = -1;
+ for (LowLevelIterator<T> it : nonEmptyIterators) {
+ i++;
+ it.moveToFirstNoReinit();
if (it.isValid()) {
- lastValidIndex = i;
+ lastValidIteratorIndex = i;
return;
}
- }
- lastValidIndex = -1; // no valid index
-
+ }
}
- public void moveToLast() {
- if (firstChangedEmptyIterator() >= 0) {
- separateIntoEmptyAndNonEmptyIterators();
- }
- // don't need to check isIndexesHaveBeenUpdated because
- // individual aggregated iterators will do that
-
+ public void moveToLastNoReinit() {
+ lastValidIteratorIndex = -1; // no valid index
for (int i = nonEmptyIterators.length -1; i >= 0; i--) {
- FSIterator<T> it = nonEmptyIterators[i];
- it.moveToLast();
+ LowLevelIterator<T> it = nonEmptyIterators[i];
+ it.moveToLastNoReinit();
if (it.isValid()) {
- lastValidIndex = i;
+ lastValidIteratorIndex = i;
return;
}
}
- lastValidIndex = -1; // no valid index
+ lastValidIteratorIndex = -1; // no valid index
}
- public void moveToNext() {
- // No point in going anywhere if iterator is not valid.
- if (!isValid()) {
- return;
- }
- moveToNextNvc();
- }
-
public void moveToNextNvc() {
- FSIterator<T> it = nonEmptyIterators[lastValidIndex];
+ FSIterator<T> it = nonEmptyIterators[lastValidIteratorIndex];
it.moveToNextNvc();
if (it.isValid()) {
@@ -173,44 +114,36 @@ class FsIterator_aggregation_common<T ex
}
final int nbrIt = nonEmptyIterators.length;
- for (int i = lastValidIndex + 1; i < nbrIt; i++) {
+ for (int i = lastValidIteratorIndex + 1; i < nbrIt; i++) {
it = nonEmptyIterators[i];
it.moveToFirst();
if (it.isValid()) {
- lastValidIndex = i;
+ lastValidIteratorIndex = i;
return;
}
}
- lastValidIndex = nonEmptyIterators.length; // invalid position
- }
-
- public void moveToPrevious() {
- // No point in going anywhere if iterator is not valid.
- if (!isValid()) {
- return;
- }
- moveToPreviousNvc();
+ lastValidIteratorIndex = nonEmptyIterators.length; // invalid position
}
@Override
public void moveToPreviousNvc() {
- LowLevelIterator<T> it = nonEmptyIterators[lastValidIndex];
+ LowLevelIterator<T> it = nonEmptyIterators[lastValidIteratorIndex];
it.moveToPreviousNvc();
if (it.isValid()) {
return;
}
- for (int i = lastValidIndex - 1; i >= 0; i--) {
+ for (int i = lastValidIteratorIndex - 1; i >= 0; i--) {
it = nonEmptyIterators[i];
it.moveToLastNoReinit();
if (it.isValid()) {
- lastValidIndex = i;
+ lastValidIteratorIndex = i;
return;
}
}
- lastValidIndex = -1; // invalid position
+ lastValidIteratorIndex = -1; // invalid position
}
public int ll_indexSize() {
@@ -224,53 +157,35 @@ class FsIterator_aggregation_common<T ex
public int ll_maxAnnotSpan() {
- int span = -1;
- for (int i = nonEmptyIterators.length - 1; i >= 0; i--) {
- FSIterator<T> it = nonEmptyIterators[i];
- int x = ((LowLevelIterator<T>)it).ll_maxAnnotSpan();
- if (x > span) {
- span = x;
- }
- }
- return (span == -1) ? Integer.MAX_VALUE : span;
+ throw Misc.internalError(); // should never be called, because this operation isn't useful
+ // in unordered indexes
+// int span = -1;
+// for (int i = nonEmptyIterators.length - 1; i >= 0; i--) {
+// FSIterator<T> it = nonEmptyIterators[i];
+// int x = ((LowLevelIterator<T>)it).ll_maxAnnotSpan();
+// if (x > span) {
+// span = x;
+// }
+// }
+// return (span == -1) ? Integer.MAX_VALUE : span;
};
- /* (non-Javadoc)
- * @see org.apache.uima.cas.FSIterator#copy()
- */
- @Override
- public FSIterator<T> copy() {
- int size = allIterators.length;
-// allIterators.clone(); // measurement shows clone on arrays has high overhead
- final LowLevelIterator<T>[] ai = new LowLevelIterator[size];
- for (int i = 0; i < ai.length; i++) {
- ai[i] = (LowLevelIterator<T>) allIterators[i].copy();
- }
-
- FsIterator_aggregation_common<T> it = new FsIterator_aggregation_common<T>(ai, index);
-
- if (!isValid()) {
- it.moveToFirst();
- it.moveToPrevious(); // make it also invalid
- } else {
- T targetFs = get();
- it.moveTo(targetFs); // moves to left-most match
- while (targetFs != it.get()) {
- it.moveToNext();
- }
- }
- return it;
- }
-
-
@Override
public LowLevelIndex<T> ll_getIndex() {
return (LowLevelIndex<T>)
((index != null)
? index
- : ((LowLevelIterator)allIterators[0]).ll_getIndex());
+ : ((LowLevelIterator<T>)allIterators[0]).ll_getIndex());
}
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#copy()
+ */
+ @Override
+ public FsIterator_aggregation_common<T> copy() {
+ return new FsIterator_aggregation_common<>(this);
+ }
+
@Override
public String toString() {
// Type type = this.ll_getIndex().getType();
@@ -306,50 +221,4 @@ class FsIterator_aggregation_common<T ex
return sb.toString();
}
- /* (non-Javadoc)
- * @see org.apache.uima.cas.impl.LowLevelIterator#isIndexesHaveBeenUpdated()
- */
- @Override
- public boolean isIndexesHaveBeenUpdated() {
- for (FSIterator<T> it : allIterators) {
- if (((LowLevelIterator)it).isIndexesHaveBeenUpdated()) {
- return true;
- }
- }
- return false;
- }
-
- private int firstChangedEmptyIterator() {
- for (int i = 0; i < emptyIterators.length; i++) {
- FSIterator<T> it = emptyIterators[i];
- if (((LowLevelIterator<?>)it).isIndexesHaveBeenUpdated()) {
- return i;
- }
- }
- return -1;
- }
-
- @Override
- public boolean maybeReinitIterator() {
- return false; // not used
- }
-
- @Override
- public void moveToFirstNoReinit() {
- // not supported
- moveToFirst();
- }
-
- @Override
- public void moveToLastNoReinit() {
- // not supported
- moveToLast();
- }
-
- @Override
- public void moveToNoReinit(FeatureStructure fs) {
- // not supported
- moveTo(fs);
- }
-
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_backwards.java Thu Jul 20 14:41:08 2017
@@ -58,48 +58,33 @@ class FsIterator_backwards<T extends Fea
}
@Override
- public T get() throws NoSuchElementException {
- return it.get();
- }
-
- @Override
public T getNvc() {
return it.getNvc();
}
@Override
- public void moveToNext() {
- it.moveToPrevious();
- }
-
- @Override
public void moveToNextNvc() {
it.moveToPreviousNvc();
}
@Override
- public void moveToPrevious() {
- it.moveToNext();
- }
-
- @Override
public void moveToPreviousNvc() {
it.moveToNextNvc();
}
@Override
- public void moveToFirst() {
- it.moveToLast();
+ public void moveToFirstNoReinit() {
+ it.moveToLastNoReinit();
}
@Override
- public void moveToLast() {
- it.moveToFirst();
+ public void moveToLastNoReinit() {
+ it.moveToFirstNoReinit();
}
@Override
- public void moveTo(FeatureStructure fs) {
- it.moveTo(fs); // moves to left most of equal, or one greater
+ public void moveToNoReinit(FeatureStructure fs) {
+ it.moveToNoReinit(fs); // moves to left most of equal, or one greater
LowLevelIndex<T> lli = ll_getIndex();
if (isValid()) {
if (lli.compare(get(), fs) == 0) {
@@ -113,7 +98,7 @@ class FsIterator_backwards<T extends Fea
if (isValid()) {
it.moveToPreviousNvc();
} else {
- it.moveToLast();
+ it.moveToLastNoReinit();
}
} else {
// is valid, but not equal - went to wrong side
@@ -121,7 +106,7 @@ class FsIterator_backwards<T extends Fea
}
} else {
// moved to one past the end. Backwards: would be at the (backwards) first position
- it.moveToLast();
+ it.moveToLastNoReinit();
}
}
@@ -138,4 +123,9 @@ class FsIterator_backwards<T extends Fea
return it.isIndexesHaveBeenUpdated();
}
+ @Override
+ public boolean maybeReinitIterator() {
+ return it.maybeReinitIterator();
+ }
+
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag.java Thu Jul 20 14:41:08 2017
@@ -27,19 +27,29 @@ import org.apache.uima.jcas.cas.TOP;
class FsIterator_bag<T extends FeatureStructure> extends FsIterator_singletype<T> {
- private CopyOnWriteObjHashSet<TOP> bag;
+ protected CopyOnWriteObjHashSet<TOP> bag;
+ final protected FsIndex_bag<T> fsBagIndex; // just an optimization, is == to fsLeafIndexImpl from super class, allows dispatch w/o casting
private int position = -1;
private boolean isGoingForward = true;
- final protected FsIndex_bag<T> fsBagIndex; // just an optimization, is == to fsLeafIndexImpl from super class, allows dispatch w/o casting
- FsIterator_bag(FsIndex_bag<T> fsBagIndex, TypeImpl ti) {
+ FsIterator_bag(FsIndex_bag<T> fsBagIndex, TypeImpl ti, CopyOnWriteIndexPart cow_wrapper) {
super(ti, null); // null: null comparator for bags
this.fsBagIndex = fsBagIndex; // need for copy()
+ bag = (CopyOnWriteObjHashSet<TOP>) cow_wrapper;
moveToFirst();
}
+
+ public boolean maybeReinitIterator() {
+ if (!bag.isOriginal()) {
+ bag = (CopyOnWriteObjHashSet<TOP>) fsBagIndex.getNonNullCow();
+ return true;
+ }
+ return false;
+ }
+
/* (non-Javadoc)
* @see org.apache.uima.cas.FSIterator#isValid()
@@ -49,18 +59,6 @@ class FsIterator_bag<T extends FeatureSt
return (position >= 0) && (position < bag.getCapacity());
}
- /* (non-Javadoc)
- * @see org.apache.uima.cas.FSIterator#get()
- */
- @Override
- public T get() {
-// checkConcurrentModification();
- if (isValid()) {
- return (T) bag.get(position);
- }
- throw new NoSuchElementException();
- }
-
@Override
public T getNvc() {
// checkConcurrentModification();
@@ -71,36 +69,22 @@ class FsIterator_bag<T extends FeatureSt
* @see org.apache.uima.cas.FSIterator#moveToFirst()
*/
@Override
- public void moveToFirst() {
- bag = (CopyOnWriteObjHashSet<TOP>) fsBagIndex.getNonNullCow();
- resetConcurrentModification();
+ public void moveToFirstNoReinit() {
+// resetConcurrentModification();
isGoingForward = true;
position = (bag.size() == 0) ? -1 : bag.moveToNextFilled(0);
}
-
+
/* (non-Javadoc)
* @see org.apache.uima.cas.FSIterator#moveToLast()
* If empty, make position -1 (invalid)
*/
@Override
- public void moveToLast() {
- bag = (CopyOnWriteObjHashSet<TOP>) fsBagIndex.getNonNullCow();
- resetConcurrentModification();
+ public void moveToLastNoReinit() {
+// resetConcurrentModification();
isGoingForward = false;
position = (bag.size() == 0) ? -1 : bag.moveToPreviousFilled(bag.getCapacity() -1);
}
-
- /* (non-Javadoc)
- * @see org.apache.uima.cas.FSIterator#moveToNext()
- */
- @Override
- public void moveToNext() {
-// checkConcurrentModification();
- if (isValid()) {
- isGoingForward = true;
- position = bag.moveToNextFilled(++position);
- }
- }
@Override
public void moveToNextNvc() {
@@ -109,19 +93,6 @@ class FsIterator_bag<T extends FeatureSt
position = bag.moveToNextFilled(++position);
}
-
- /* (non-Javadoc)
- * @see org.apache.uima.cas.FSIterator#moveToPrevious()
- */
- @Override
- public void moveToPrevious() {
-// checkConcurrentModification();
- if (isValid()) {
- isGoingForward = false;
- position = bag.moveToPreviousFilled(--position);
- }
- }
-
@Override
public void moveToPreviousNvc() {
// checkConcurrentModification();
@@ -133,18 +104,17 @@ class FsIterator_bag<T extends FeatureSt
* @see org.apache.uima.cas.FSIterator#moveTo(org.apache.uima.cas.FeatureStructure)
*/
@Override
- public void moveTo(FeatureStructure fs) {
- bag = (CopyOnWriteObjHashSet<TOP>) fsBagIndex.getNonNullCow();
- resetConcurrentModification();
+ public void moveToNoReinit(FeatureStructure fs) {
+// resetConcurrentModification();
position = bag.moveTo(fs);
}
-
+
/* (non-Javadoc)
* @see org.apache.uima.cas.FSIterator#copy()
*/
@Override
public FsIterator_bag<T> copy() {
- FsIterator_bag<T> copy = new FsIterator_bag<T>(this.fsBagIndex, this.ti);
+ FsIterator_bag<T> copy = new FsIterator_bag<T>(this.fsBagIndex, this.ti, bag);
copyCommonSetup(copy);
return copy;
}
@@ -175,13 +145,13 @@ class FsIterator_bag<T extends FeatureSt
return fsBagIndex;
}
- /* (non-Javadoc)
- * @see org.apache.uima.cas.impl.FsIterator_singletype#getModificationCountFromIndex()
- */
- @Override
- protected int getModificationCountFromIndex() {
- return bag.getModificationCount();
- }
+// /* (non-Javadoc)
+// * @see org.apache.uima.cas.impl.FsIterator_singletype#getModificationCountFromIndex()
+// */
+// @Override
+// protected int getModificationCountFromIndex() {
+// return bag.getModificationCount();
+// }
/* (non-Javadoc)
* @see org.apache.uima.cas.impl.LowLevelIterator#isIndexesHaveBeenUpdated()
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag_pear.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag_pear.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag_pear.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_bag_pear.java Thu Jul 20 14:41:08 2017
@@ -31,23 +31,18 @@ import org.apache.uima.cas.FeatureStruct
*/
class FsIterator_bag_pear<T extends FeatureStructure> extends FsIterator_bag<T> {
- FsIterator_bag_pear(FsIndex_bag<T> fsBagIndex, TypeImpl ti) {
- super(fsBagIndex, ti);
+ FsIterator_bag_pear(FsIndex_bag<T> fsBagIndex, TypeImpl ti, CopyOnWriteIndexPart cow_wrapper) {
+ super(fsBagIndex, ti, cow_wrapper);
}
@Override
- public T get() {
- return CASImpl.pearConvert(super.get());
- }
-
- @Override
public T getNvc() {
return CASImpl.pearConvert(super.getNvc());
}
@Override
public FsIterator_bag_pear<T> copy() {
- FsIterator_bag_pear<T> copy = new FsIterator_bag_pear<T>(this.fsBagIndex, this.ti);
+ FsIterator_bag_pear<T> copy = new FsIterator_bag_pear<T>(this.fsBagIndex, this.ti, this.bag );
copyCommonSetup(copy);
return copy;
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_limited.java Thu Jul 20 14:41:08 2017
@@ -46,52 +46,35 @@ class FsIterator_limited<T extends Featu
}
}
- public T get() throws NoSuchElementException {
- maybeMakeInvalid();
- T r = iterator.get();
- count++;
- return r;
- }
-
public T getNvc() {
maybeMakeInvalid();
- T r = iterator.getNvc();
+ T r = iterator.get(); // not getNvc because of above line
count++;
return r;
}
- public void moveToNext() {
- maybeMakeInvalid();
- iterator.moveToNext();
- }
-
public void moveToNextNvc() {
maybeMakeInvalid();
- iterator.moveToNextNvc();
- }
-
- public void moveToPrevious() {
- maybeMakeInvalid();
- iterator.moveToPrevious();
+ iterator.moveToNext(); // not getNvc because of above line
}
public void moveToPreviousNvc() {
maybeMakeInvalid();
- iterator.moveToPreviousNvc();
+ iterator.moveToPrevious(); // not getNvc because of above line
}
- public void moveToFirst() {
- iterator.moveToFirst();
+ public void moveToFirstNoReinit() {
+ iterator.moveToFirstNoReinit();
maybeMakeInvalid();
}
- public void moveToLast() {
- iterator.moveToLast();
+ public void moveToLastNoReinit() {
+ iterator.moveToLastNoReinit();
maybeMakeInvalid();
}
- public void moveTo(FeatureStructure fs) {
- iterator.moveTo(fs);
+ public void moveToNoReinit(FeatureStructure fs) {
+ iterator.moveToNoReinit(fs);
maybeMakeInvalid();
}
@@ -127,4 +110,9 @@ class FsIterator_limited<T extends Featu
return iterator.isIndexesHaveBeenUpdated();
}
+ @Override
+ public boolean maybeReinitIterator() {
+ return iterator.maybeReinitIterator();
+ }
+
}
Added: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_multiple_indexes.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_multiple_indexes.java?rev=1802495&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_multiple_indexes.java (added)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_multiple_indexes.java Thu Jul 20 14:41:08 2017
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.cas.impl;
+
+import java.util.ArrayList;
+import java.util.NoSuchElementException;
+
+import org.apache.uima.cas.FeatureStructure;
+
+/**
+ * Common code for both
+ * aggregation of indexes (e.g. select, iterating over multiple views)
+ * aggregation of indexes in type/subtype hierarchy
+ *
+ * Supports creating corresponding iterators just for the non-empty ones
+ * Supports reinit - evaluating when one or more formerly empty indexes is no longer empty, and recalculating the
+ * iterator set
+ * @param <T> the highest type returned by these iterators
+ */
+public abstract class FsIterator_multiple_indexes <T extends FeatureStructure> implements LowLevelIterator<T> {
+
+ // An array of iterators, one for each in the collection (e.g. subtypes, or views or ...)
+ // split among empty and non-empty.
+ protected LowLevelIterator<T>[] allIterators;
+ private LowLevelIterator<T>[] emptyIterators;
+ protected LowLevelIterator<T> [] nonEmptyIterators;
+
+ /** index into nonEmptyIterators, shows last valid one */
+ protected int lastValidIteratorIndex = -1;
+
+ public FsIterator_multiple_indexes(LowLevelIterator<T>[] iterators) {
+ this.allIterators = iterators;
+ separate_into_empty_indexes_and_non_empty_iterators();
+
+ }
+
+ /** copy constructor */
+ public FsIterator_multiple_indexes(FsIterator_multiple_indexes<T> v) {
+ allIterators = v.allIterators.clone();
+ int i = 0;
+ for (LowLevelIterator<T> it : allIterators) {
+ allIterators[i++] = (LowLevelIterator<T>) it.copy();
+ }
+ separate_into_empty_indexes_and_non_empty_iterators();
+ lastValidIteratorIndex = v.lastValidIteratorIndex;
+ }
+
+ /**
+ * Also resets all non-empty iterators to current values
+ */
+ protected void separate_into_empty_indexes_and_non_empty_iterators() {
+
+ ArrayList<LowLevelIterator<T>> emptyIteratorsAl = new ArrayList<>();
+ ArrayList<LowLevelIterator<T>> nonEmptyIteratorsAl = new ArrayList<>();
+
+ for (LowLevelIterator<T> it : allIterators) {
+ if (it.ll_indexSize() == 0) {
+ emptyIteratorsAl.add(it);
+ } else {
+ nonEmptyIteratorsAl.add(it);
+ }
+ }
+
+ emptyIterators = emptyIteratorsAl .toArray(new LowLevelIterator[emptyIteratorsAl .size()]);
+ nonEmptyIterators = nonEmptyIteratorsAl.toArray(new LowLevelIterator[nonEmptyIteratorsAl.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#isValid()
+ */
+ @Override
+ public boolean isValid() {
+ return lastValidIteratorIndex >= 0 &&
+ lastValidIteratorIndex < nonEmptyIterators.length &&
+ nonEmptyIterators[lastValidIteratorIndex].isValid();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#getNvc()
+ */
+ @Override
+ public T getNvc() {
+ return nonEmptyIterators[lastValidIteratorIndex].getNvc();
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#ll_indexSize()
+ */
+ @Override
+ public int ll_indexSize() {
+ int sz = 0;
+ for (LowLevelIterator<T> it : nonEmptyIterators) {
+ sz += it.ll_indexSize();
+ }
+ return sz;
+ }
+
+ @Override
+ public int ll_maxAnnotSpan() {
+ int span = -1;
+ for (LowLevelIterator<T> it : nonEmptyIterators) {
+ int s = it.ll_maxAnnotSpan();
+ if (s == Integer.MAX_VALUE) {
+ return s;
+ }
+ if (s > span) {
+ span = s;
+ }
+ }
+ return (span == -1) ? Integer.MAX_VALUE : span;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#isIndexesHaveBeenUpdated()
+ */
+ @Override
+ public boolean isIndexesHaveBeenUpdated() {
+ for (LowLevelIterator<T> it : nonEmptyIterators) {
+ if (it.isIndexesHaveBeenUpdated()) {
+ return true;
+ }
+ }
+
+ return empty_became_nonEmpty(); // slightly better than testing isIndexesHaveBeenUpdated
+ // because if it went from empty -> not empty -> empty,
+ // is not counted as having been updated for this purpose
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#maybeReinitIterator()
+ */
+ @Override
+ public boolean maybeReinitIterator() {
+ boolean empty_became_nonEmpty = empty_became_nonEmpty();
+ if (empty_became_nonEmpty) {
+ separate_into_empty_indexes_and_non_empty_iterators();
+ }
+
+ boolean any = false;
+ for (LowLevelIterator<T> it : nonEmptyIterators) {
+ any |= it.maybeReinitIterator(); // need to call on all, in order to reinit them if needed
+ }
+ return any;
+ }
+
+
+ private boolean empty_became_nonEmpty() {
+ for (LowLevelIterator<T> it : emptyIterators) {
+ if (it.ll_getIndex().size() > 0) { // don't test changed might have had insert then delete...
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Added: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java?rev=1802495&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java (added)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted2.java Thu Jul 20 14:41:08 2017
@@ -0,0 +1,328 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.cas.impl;
+
+import java.util.Comparator;
+import java.util.NoSuchElementException;
+
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.internal.util.CopyOnWriteOrderedFsSet_array;
+import org.apache.uima.internal.util.Misc;
+import org.apache.uima.internal.util.OrderedFsSet_array;
+import org.apache.uima.jcas.cas.TOP;
+
+/**
+ * NOTE: This is the version used for set/sorted iterators
+ * It is built directly on top of a CopyOnWrite wrapper for OrderedFsSet_array
+ * It uses the version of OrdereFsSet_array that has no embedded nulls
+ * @param <T> the type of FSs being returned from the iterator, supplied by the calling context
+ */
+class FsIterator_set_sorted2<T extends FeatureStructure> extends FsIterator_singletype<T> implements LowLevelIterator<T> {
+
+ // not final, because on moveToFirst/Last/FS, the semantics dictate that
+ // if the underlying index was updated, this should iterate over that.
+ protected CopyOnWriteOrderedFsSet_array ofsa; // orderedFsSet_array;
+
+ private int pos;
+
+ protected final FsIndex_set_sorted<T> ll_index;
+
+ private final Comparator<TOP> comparatorWithoutID;
+
+ public FsIterator_set_sorted2(FsIndex_set_sorted<T> ll_index, CopyOnWriteIndexPart cow_wrapper) {
+ super((TypeImpl)ll_index.getType(),
+ ((CopyOnWriteOrderedFsSet_array)cow_wrapper).comparatorWithoutID);
+ this.comparatorWithoutID = ((CopyOnWriteOrderedFsSet_array)cow_wrapper).comparatorWithoutID;
+
+ this.ll_index = ll_index;
+ ofsa = (CopyOnWriteOrderedFsSet_array) cow_wrapper;
+ pos = ofsa.a_firstUsedslot;
+// incrToSkipOverNulls();
+// if (MEASURE) {
+// int s = ofsa.a_nextFreeslot - ofsa.a_firstUsedslot;
+// iterPctEmptySkip[(s - ofsa.size()) * 10 / s] ++;
+// }
+ }
+
+ public boolean maybeReinitIterator() {
+ if (!ofsa.isOriginal()) {
+ // can't share this copy with other iterators - they may have not done a moveToFirst, etc.
+ // and need to continue with the previous view
+ ofsa = (CopyOnWriteOrderedFsSet_array) ll_index.getNonNullCow();
+ return true;
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#isValid()
+ */
+ @Override
+ public boolean isValid() {
+ return pos >= ofsa.a_firstUsedslot && pos < ofsa.a_nextFreeslot;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#getNvc()
+ */
+ @Override
+ public T getNvc() {
+ return (T) ofsa.a[pos];
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#moveToNextNvc()
+ */
+ @Override
+ public void moveToNextNvc() {
+ pos++;
+// incrToSkipOverNulls();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#moveToPreviousNvc()
+ */
+ @Override
+ public void moveToPreviousNvc() {
+ pos--;
+// decrToSkipOverNulls();
+ }
+
+ // Internal use
+ public void moveToFirstNoReinit() {
+ pos = ofsa.a_firstUsedslot;
+ }
+
+ // Internal use
+ public void moveToLastNoReinit() {
+ pos = ofsa.a_nextFreeslot - 1;
+ }
+
+ // Internal use
+ public void moveToNoReinit(FeatureStructure fs) {
+ pos = ofsa.getOfsa().findWithoutID((TOP) fs);
+
+ if (pos < 0) {
+ pos = (-pos) -1; // insertion point, one above
+ return;
+ }
+
+ int savedPos = pos;
+
+ // pos is the equal-with-id item
+
+ moveToPreviousNvc();
+ if (isValid()) {
+ if (0 == comparatorWithoutID.compare((TOP)get(), (TOP) fs)) {
+ moveToLeftMost(fs);
+ } else {
+ // did not compare equal, so previous was the right position
+ pos = savedPos;
+ }
+ } else {
+ // went one before start, restore to start
+ pos = savedPos;
+ }
+ return;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#copy()
+ */
+ @Override
+ public FsIterator_singletype<T> copy() {
+ FsIterator_set_sorted2<T> r = new FsIterator_set_sorted2<>(ll_index, ofsa);
+ r.pos = pos;
+ return r;
+ }
+
+// /* (non-Javadoc)
+// * @see org.apache.uima.cas.FSIterator#getType()
+// */
+// @Override
+// public Type getType() {
+// // TODO Auto-generated method stub
+// return LowLevelIterator.super.getType();
+// }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#ll_indexSize()
+ */
+ @Override
+ public int ll_indexSize() {
+ return ofsa.size();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#ll_getIndex()
+ */
+ @Override
+ public LowLevelIndex<T> ll_getIndex() {
+ return ll_index;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#ll_maxAnnotSpan()
+ */
+ @Override
+ public int ll_maxAnnotSpan() {
+ FsIndex_set_sorted<T> ss_idx = (FsIndex_set_sorted<T>)ll_index;
+ return ss_idx.isAnnotIdx
+ ? ss_idx.ll_maxAnnotSpan()
+ : Integer.MAX_VALUE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#isIndexesHaveBeenUpdated()
+ * This is local to this class because it references the ofsa
+ */
+ @Override
+ public boolean isIndexesHaveBeenUpdated() {
+ return ofsa != ll_index.getCopyOnWriteIndexPart();
+ }
+
+// private void incrToSkipOverNulls() {
+// while (pos < ofsa.a_nextFreeslot) {
+// if (ofsa.a[pos] != null) {
+// break;
+// }
+// pos ++;
+// }
+// }
+//
+// private void decrToSkipOverNulls() {
+// while (pos >= ofsa.a_firstUsedslot) {
+// if (ofsa.a[pos] != null) {
+// break;
+// }
+// pos --;
+// }
+// }
+
+ /**
+ * Starting at a position where the item is equal to fs
+ * using the compare without id,
+ * move to the leftmost one
+ *
+ * search opportunistically, starting at 1 before, 2, 4, 8, 16, etc.
+ * then doing binary search in the opposite dir
+ *
+ * These methods are in this class because they manipulate "pos"
+ * @param fs -
+ */
+ private void moveToLeftMost(FeatureStructure fs) {
+
+ // adjust to move to left-most equal item
+ boolean comparedEqual = false;
+ int origPos = pos;
+ int span = 1;
+ while (isValid()) {
+ int upperValidPos = pos;
+ pos = origPos - span;
+ pos = Math.max(-1, pos);
+// decrToSkipOverNulls();
+ if (!isValid()) {
+ moveToLeftMostUp(fs, upperValidPos);
+ return;
+ }
+ comparedEqual = (0 == comparatorWithoutID.compare((TOP)get(), (TOP) fs));
+ if (!comparedEqual) {
+ moveToLeftMostUp(fs, upperValidPos);
+ return;
+ }
+ span = span << 1;
+ }
+ }
+
+ /**
+ * Must be possible to leave the pos == to upperValidPos.
+ * Starts searching from next above current pos
+ * @param fs
+ * @param upperValidPos
+ */
+ private void moveToLeftMostUp(FeatureStructure fs, int upperValidPos) {
+ if (pos < ofsa.a_firstUsedslot) {
+ moveToFirst();
+ } else {
+ moveToNext();
+ }
+ // binary search between pos (inclusive) and upperValidPos (exclusive)
+ if (!isValid()) {
+ Misc.internalError();
+ }
+ if (pos == upperValidPos) {
+ return;
+ }
+ pos = ofsa.getOfsa().binarySearchLeftMostEqual((TOP) fs, pos, upperValidPos);
+ }
+
+// @Override
+// protected int getModificationCountFromIndex() {
+// return ofsa.getModificationCount();
+// }
+
+// /**
+// * Never returns an index to a "null" (deleted) item.
+// * If all items are LT key, returns - size - 1
+// * @param fs the key
+// * @return the lowest position whose item is equal to or greater than fs;
+// * if not equal, the item's position is returned as -insertionPoint - 1.
+// * If the key is greater than all elements, return -size - 1).
+// */
+// private int find(TOP fs) {
+// return ofsa.getOfsa().find(fs);
+// }
+
+ /**
+ * @param fs - the fs to search for
+ * @param start the index representing the lower bound (inclusive) to search for
+ * @param end the index representing the upper bound (exclusive) to search for
+ * @return - the index of the leftmost equal (without id) item
+ */
+ private int binarySearchLeftMostEqual(final TOP fs, int start, int end) {
+
+// assert start >= 0;
+// assert start < end;
+
+ int lower = start, upper = end;
+ for (;;) {
+
+ int mid = (lower + upper) >>> 1; // overflow aware
+ TOP item = ofsa.a[mid];
+ int pos = mid;
+
+ int c = comparatorWithoutID.compare(item, fs);
+ if (c == 0) {
+ upper = pos; // upper is exclusive
+ if (upper == lower) {
+ return upper;
+ }
+ } else { // item is less than fs; search upwards
+ lower = pos + 1; // lower is inclusive
+ if (lower == upper) {
+ return upper;
+ }
+ }
+ }
+ }
+
+
+}
+
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_set_sorted_pear.java Thu Jul 20 14:41:08 2017
@@ -19,28 +19,20 @@
package org.apache.uima.cas.impl;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.NavigableSet;
-import java.util.NoSuchElementException;
-
import org.apache.uima.cas.FeatureStructure;
-import org.apache.uima.internal.util.OrderedFsSet_array;
-import org.apache.uima.jcas.cas.TOP;
/**
* @param <T> the type of FSs being returned from the iterator, supplied by the calling context
*/
-class FsIterator_set_sorted_pear<T extends FeatureStructure> extends FsIterator_set_sorted<T> {
-
- FsIterator_set_sorted_pear(FsIndex_set_sorted<T> fsSetSortIndex, TypeImpl ti, Comparator<FeatureStructure> comp) {
- super(fsSetSortIndex, ti, comp);
- }
-
- @Override
- public T get() {
- return CASImpl.pearConvert(super.get());
+class FsIterator_set_sorted_pear<T extends FeatureStructure> extends FsIterator_set_sorted2<T> {
+
+ FsIterator_set_sorted_pear(FsIndex_set_sorted<T> ll_index, CopyOnWriteIndexPart cow_wrapper) {
+ super(ll_index, cow_wrapper);
}
+
+// FsIterator_set_sorted_pear createInstance(OrderedFsSet_array orderedFsSet_array, LowLevelIndex ll_index) {
+// orderedFsSet_array.new LL_Iterator(ll_index);
+// }
@Override
public T getNvc() {
@@ -49,6 +41,6 @@ class FsIterator_set_sorted_pear<T exten
@Override
public FsIterator_set_sorted_pear<T> copy() {
- return new FsIterator_set_sorted_pear<T>(this.fsSetSortIndex, ti, this.comparator);
+ return new FsIterator_set_sorted_pear<T>(ll_index, ofsa);
}
}
\ No newline at end of file
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_singletype.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_singletype.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_singletype.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_singletype.java Thu Jul 20 14:41:08 2017
@@ -20,17 +20,16 @@
package org.apache.uima.cas.impl;
import java.util.Comparator;
-import java.util.ConcurrentModificationException;
-import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
+import org.apache.uima.jcas.cas.TOP;
public abstract class FsIterator_singletype<T extends FeatureStructure>
implements LowLevelIterator<T>,
Comparable<FsIterator_singletype<T>> {
- private int modificationSnapshot; // to catch illegal modifications
+// private int modificationSnapshot; // to catch illegal modifications
// /**
// * This is a ref to the shared value in the FSIndexRepositoryImpl
@@ -46,9 +45,9 @@ public abstract class FsIterator_singlet
* an instance of T and some other template type which can be a supertype of T, as long as
* the keys are defined in both.
*/
- final protected Comparator<FeatureStructure> comparator;
+ final protected Comparator<TOP> comparator;
- public FsIterator_singletype(TypeImpl ti, Comparator<FeatureStructure> comparator){
+ public FsIterator_singletype(TypeImpl ti, Comparator<TOP> comparator){
this.comparator = comparator;
// this.detectIllegalIndexUpdates = detectConcurrentMods;
this.ti = ti;
@@ -56,7 +55,7 @@ public abstract class FsIterator_singlet
// subtypes do moveToFirst after they finish initialization
}
- protected abstract int getModificationCountFromIndex();
+// protected abstract int getModificationCountFromIndex();
// final protected <I extends FSIterator<T>> I checkConcurrentModification() {
// if (modificationSnapshot != getModificationCountFromIndex()) {
@@ -74,15 +73,15 @@ public abstract class FsIterator_singlet
}
}
- protected void resetConcurrentModification() {
- this.modificationSnapshot = // (null == this.detectIllegalIndexUpdates) ? 0 : this.detectIllegalIndexUpdates[typeCode];
- getModificationCountFromIndex();
- }
+// protected void resetConcurrentModification() {
+// this.modificationSnapshot = // (null == this.detectIllegalIndexUpdates) ? 0 : this.detectIllegalIndexUpdates[typeCode];
+// getModificationCountFromIndex();
+// }
@Override
public int compareTo(FsIterator_singletype<T> o) {
if (comparator != null) {
- return comparator.compare(this.get(), o.get());
+ return comparator.compare((TOP)this.get(), (TOP)o.get());
}
return Integer.compare(this.get()._id(), o.get()._id());
}
@@ -95,8 +94,8 @@ public abstract class FsIterator_singlet
Type type = ti;
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()).append(":").append(System.identityHashCode(this));
sb.append(" over Type: ").append(type.getName()).append(":").append(ti.getCode());
- sb.append(", size: ").append(this.ll_indexSize());
+ sb.append(", index size: ").append(this.ll_indexSize());
return sb.toString();
- }
-
+ }
+
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_ordered.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_ordered.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_ordered.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_ordered.java Thu Jul 20 14:41:08 2017
@@ -37,7 +37,7 @@ import org.apache.uima.jcas.cas.TOP;
* @param <T> result type
*/
public class FsIterator_subtypes_ordered<T extends FeatureStructure>
- extends FsIterator_subtypes_list<T> {
+ extends FsIterator_multiple_indexes<T> {
/**
* The number of elements to keep in order before the binary heap starts. This section helps the
@@ -50,14 +50,20 @@ public class FsIterator_subtypes_ordered
private boolean wentForward = true;
+ /** for sorted, this is with ID, otherwise, without */
final private Comparator<TOP> comparator;
+
+ // The IICP
+ final private FsIndex_iicp<T> iicp;
+
public FsIterator_subtypes_ordered(FsIndex_iicp<T> iicp) {
- super(iicp);
- this.comparator = (iicp.fsIndex_singletype instanceof FsIndex_set_sorted)
+ super(iicp.getIterators());
+ this.iicp = iicp;
+ this.comparator = (iicp.fsIndex_singletype.isSorted())
? ((FsIndex_set_sorted)iicp.fsIndex_singletype).getComparatorWithId()
: (Comparator) iicp.fsIndex_singletype;
- moveToStart();
+ moveToFirstNoReinit();
}
/**
@@ -65,24 +71,14 @@ public class FsIterator_subtypes_ordered
*/
@Override
- public void moveToFirst() {
- if (firstChangedEmptyIterator() >= 0) {
- this.nonEmptyIterators = initIterators();
- }
- // no need to call isIndexesHaveBeenUpdated because
- // there's no state in this iterator that needs updating.
- moveToStart();
- }
-
- private void moveToStart() {
-
+ public void moveToFirstNoReinit() {
int lvi = this.nonEmptyIterators.length - 1;
// Need to consider all iterators.
// Set all iterators to insertion point.
int i = 0;
while (i <= lvi) {
- final FsIterator_singletype<T> it = this.nonEmptyIterators[i];
- it.moveToFirst();
+ final LowLevelIterator<T> it = this.nonEmptyIterators[i];
+ it.moveToFirstNoReinit();
if (it.isValid()) {
heapify_up(it, i, 1);
++i;
@@ -96,14 +92,11 @@ public class FsIterator_subtypes_ordered
}
// configured to continue with forward iterations
this.wentForward = true;
- this.lastValidIndex = lvi;
+ this.lastValidIteratorIndex = lvi;
}
@Override
- public void moveToLast() {
- if (firstChangedEmptyIterator() >= 0) {
- this.nonEmptyIterators = initIterators();
- }
+ public void moveToLastNoReinit() {
// no need to call isIndexesHaveBeenUpdated because
// there's no state in this iterator that needs updating.
@@ -112,9 +105,9 @@ public class FsIterator_subtypes_ordered
// Set all iterators to insertion point.
int i = 0;
while (i <= lvi) {
- final FsIterator_singletype<T> it = this.nonEmptyIterators[i];
- it.resetConcurrentModification();
- it.moveToLast();
+ final LowLevelIterator<T> it = this.nonEmptyIterators[i];
+// it.resetConcurrentModification();
+ it.moveToLastNoReinit();
if (it.isValid()) {
heapify_up(it, i, -1);
++i;
@@ -128,28 +121,12 @@ public class FsIterator_subtypes_ordered
}
// configured to continue with backward iterations
this.wentForward = false;
- this.lastValidIndex = lvi;
- }
-
- @Override
- public void moveToNext() {
- if (!isValid()) {
- return;
- }
-
- final FsIterator_singletype<T> it0 = nonEmptyIterators[0]/*.checkConcurrentModification()*/;
-
- if (this.wentForward) {
- it0.moveToNextNvc();
- heapify_down(it0, 1);
- } else {
- moveToNextCmn(it0);
- }
+ this.lastValidIteratorIndex = lvi;
}
@Override
public void moveToNextNvc() {
- final FsIterator_singletype<T> it0 = nonEmptyIterators[0]/*.checkConcurrentModification()*/;
+ final LowLevelIterator<T> it0 = nonEmptyIterators[0]/*.checkConcurrentModification()*/;
if (this.wentForward) {
it0.moveToNextNvc();
@@ -163,7 +140,7 @@ public class FsIterator_subtypes_ordered
*
* @param it0 guaranteed to be a valid iterator by callers
*/
- private void moveToNextCmn(final FsIterator_singletype<T> it0) {
+ private void moveToNextCmn(final LowLevelIterator<T> it0) {
// We need to increment everything.
int lvi = this.nonEmptyIterators.length - 1;
int i = 1;
@@ -171,16 +148,16 @@ public class FsIterator_subtypes_ordered
// Any iterator other than the current one needs to be
// incremented until it's pointing at something that's
// greater than the current element.
- final FsIterator_singletype<T> it = nonEmptyIterators[i]/*.checkConcurrentModification()*/;
+ final LowLevelIterator<T> it = nonEmptyIterators[i]/*.checkConcurrentModification()*/;
// If the iterator we're considering is not valid, we
// set it to the first element. This should be it for this iterator...
if (!it.isValid()) {
- it.moveToFirst();
+ it.moveToFirstNoReinit();
}
// Increment the iterator while it is valid and pointing
// at something smaller than the current element.
while (it.isValid() && is_before(it, it0, 1)) {
- it.moveToNext();
+ it.moveToNextNvc();
}
// find placement
@@ -196,7 +173,7 @@ public class FsIterator_subtypes_ordered
}
}
- this.lastValidIndex = lvi;
+ this.lastValidIteratorIndex = lvi;
this.wentForward = true;
it0.moveToNext();
@@ -205,17 +182,8 @@ public class FsIterator_subtypes_ordered
}
@Override
- public void moveToPrevious() {
- if (!isValid()) {
- return;
- }
-
- moveToPreviousNvc();
- }
-
- @Override
public void moveToPreviousNvc() {
- final FsIterator_singletype<T> it0 = nonEmptyIterators[0]/*.checkConcurrentModification()*/;
+ final LowLevelIterator<T> it0 = nonEmptyIterators[0]/*.checkConcurrentModification()*/;
if (!this.wentForward) {
it0.moveToPreviousNvc();
// this also takes care of invalid iterators
@@ -228,11 +196,11 @@ public class FsIterator_subtypes_ordered
// Any iterator other than the current one needs to be
// decremented until it's pointing at something that's
// smaller than the current element.
- final FsIterator_singletype<T> it = nonEmptyIterators[i]/*.checkConcurrentModification()*/;
+ final LowLevelIterator<T> it = nonEmptyIterators[i]/*.checkConcurrentModification()*/;
// If the iterator we're considering is not valid, we
// set it to the last element. This should be it for this iterator...
if (!it.isValid()) {
- it.moveToLast();
+ it.moveToLastNoReinit();
}
// Decrement the iterator while it is valid and pointing
// at something greater than the current element.
@@ -253,7 +221,7 @@ public class FsIterator_subtypes_ordered
}
}
- this.lastValidIndex = lvi;
+ this.lastValidIteratorIndex = lvi;
this.wentForward = false;
it0.moveToPrevious();
@@ -272,7 +240,7 @@ public class FsIterator_subtypes_ordered
* Direction of movement, 1 for forward, -1 for backward
* @return true if the left iterator needs to be used before the right one.
*/
- private boolean is_before(FsIterator_singletype<T> l, FsIterator_singletype<T> r,
+ private boolean is_before(LowLevelIterator<T> l, LowLevelIterator<T> r,
int dir) {
// // debug
@@ -292,8 +260,7 @@ public class FsIterator_subtypes_ordered
// If two FSs are identical wrt the comparator of the index,
// we still need to be able to distinguish them to be able to have a
// well-defined sequence. In that case, we arbitrarily order FSs by
- // their
- // addresses. We need to do this in order to be able to ensure that a
+ // their ids. We need to do this in order to be able to ensure that a
// reverse iterator produces the reverse order of the forward iterator.
if (d == 0) {
d = fsLeft._id() - fsRight._id();
@@ -302,16 +269,17 @@ public class FsIterator_subtypes_ordered
}
/**
- * Move the idx'th element up in the heap until it finds its proper position.
+ * Move the idx'th iterator element up in the heap until it finds its proper position.
+ * Up means previous iterators are before it
*
* @param it
* indexes[idx], guaranteed to be "valid"
* @param idx
- * Element to move
+ * Element to move, nonEmptyIterators[i] == it
* @param dir
* Direction of iterator movement, 1 for forward, -1 for backward
*/
- private void heapify_up(FsIterator_singletype<T> it, int idx, int dir) {
+ private void heapify_up(LowLevelIterator<T> it, int idx, int dir) {
// FSIndexFlat<? extends FeatureStructure> flatIndexInfo = iicp.flatIndex;
// if (null != flatIndexInfo) {
// flatIndexInfo.incrementReorderingCount();
@@ -349,23 +317,23 @@ public class FsIterator_subtypes_ordered
* @param dir
* Direction of iterator movement, 1 for forward, -1 for backward
*/
- private void heapify_down(FsIterator_singletype<T> it, int dir) {
+ private void heapify_down(LowLevelIterator<T> it, int dir) {
// FSIndexFlat<? extends FeatureStructure> flatIndexInfo = iicp.flatIndex;
// if (null != flatIndexInfo) {
// flatIndexInfo.incrementReorderingCount();
// }
if (!it.isValid()) {
- // if at the end of the iteration, the lastValidIndex is this one (e.g., is 0)
- // and this operation is a noop, but sets the lastValidIndex to -1, indicating the iterator is invalid
- final FsIterator_singletype<T> itl = this.nonEmptyIterators[this.lastValidIndex]/*.checkConcurrentModification()*/;
- this.nonEmptyIterators[this.lastValidIndex] = it;
+ // if at the end of the iteration, the lastValidIteratorIndex is this one (e.g., is 0)
+ // and this operation is a noop, but sets the lastValidIteratorIndex to -1, indicating the iterator is invalid
+ final LowLevelIterator<T> itl = this.nonEmptyIterators[this.lastValidIteratorIndex]/*.checkConcurrentModification()*/;
+ this.nonEmptyIterators[this.lastValidIteratorIndex] = it;
this.nonEmptyIterators[0] = itl;
- --this.lastValidIndex;
+ --this.lastValidIteratorIndex;
it = itl;
}
- final int num = this.lastValidIndex;
+ final int num = this.lastValidIteratorIndex;
if ((num < 1) || !is_before(this.nonEmptyIterators[1]/*.checkConcurrentModification()*/, it, dir)) {
return;
}
@@ -415,18 +383,7 @@ public class FsIterator_subtypes_ordered
*/
@Override
public boolean isValid() {
- return lastValidIndex >= 0;
- }
-
- /* (non-Javadoc)
- * @see org.apache.uima.cas.FSIterator#get()
- */
- @Override
- public T get() throws NoSuchElementException {
- if (!isValid()) {
- throw new NoSuchElementException();
- }
- return getNvc();
+ return lastValidIteratorIndex >= 0;
}
/* (non-Javadoc)
@@ -441,10 +398,7 @@ public class FsIterator_subtypes_ordered
* @see org.apache.uima.cas.FSIterator#moveTo(org.apache.uima.cas.FeatureStructure)
*/
@Override
- public void moveTo(FeatureStructure fs) {
- if (firstChangedEmptyIterator() >= 0) {
- this.nonEmptyIterators = initIterators();
- }
+ public void moveToNoReinit(FeatureStructure fs) {
// no need to call isIndexesHaveBeenUpdated because
// there's no state in this iterator that needs updating.
@@ -453,8 +407,8 @@ public class FsIterator_subtypes_ordered
// Set all iterators to insertion point.
int i = 0;
while (i <= lvi) {
- final FsIterator_singletype<T> it = this.nonEmptyIterators[i];
- it.moveTo(fs);
+ final LowLevelIterator<T> it = this.nonEmptyIterators[i];
+ it.moveToNoReinit(fs);
if (it.isValid()) {
heapify_up(it, i, 1);
++i;
@@ -468,7 +422,7 @@ public class FsIterator_subtypes_ordered
}
// configured to continue with forward iterations
this.wentForward = true;
- this.lastValidIndex = lvi;
+ this.lastValidIteratorIndex = lvi;
}
/* (non-Javadoc)
@@ -481,7 +435,7 @@ public class FsIterator_subtypes_ordered
it.moveToPrevious(); // mark new one also invalid
} else {
T posFs = get();
- it.moveTo(posFs); // moves to left-most position
+ it.moveToNoReinit(posFs); // moves to left-most position
while(it.get() != posFs) {
it.moveToNext();
}
@@ -489,7 +443,9 @@ public class FsIterator_subtypes_ordered
return it;
}
-
-
+ @Override
+ public LowLevelIndex<T> ll_getIndex() {
+ return iicp;
+ }
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FsIterator_subtypes_snapshot.java Thu Jul 20 14:41:08 2017
@@ -108,7 +108,7 @@ public class FsIterator_subtypes_snapsho
* @see org.apache.uima.cas.FSIterator#moveToFirst()
*/
@Override
- public void moveToFirst() {
+ public void moveToFirstNoReinit() {
pos = 0;
}
@@ -116,7 +116,7 @@ public class FsIterator_subtypes_snapsho
* @see org.apache.uima.cas.FSIterator#moveToLast()
*/
@Override
- public void moveToLast() {
+ public void moveToLastNoReinit() {
pos = snapshot.length - 1;
}
@@ -124,7 +124,7 @@ public class FsIterator_subtypes_snapsho
* @see org.apache.uima.cas.FSIterator#moveTo(org.apache.uima.cas.FeatureStructure)
*/
@Override
- public void moveTo(FeatureStructure fs) {
+ public void moveToNoReinit(FeatureStructure fs) {
if (is_unordered) {
int i = 0;
while ((i < snapshot.length) && compare(snapshot[i], fs) < 0) {
@@ -198,4 +198,9 @@ public class FsIterator_subtypes_snapsho
return false;
}
+ @Override
+ public boolean maybeReinitIterator() {
+ return false;
+ }
+
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIndex.java Thu Jul 20 14:41:08 2017
@@ -19,12 +19,15 @@
package org.apache.uima.cas.impl;
+import java.util.Comparator;
+
import org.apache.uima.cas.FSIndex;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.SelectFSs;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.admin.FSIndexComparator;
import org.apache.uima.internal.util.IntPointerIterator;
+import org.apache.uima.jcas.cas.TOP;
/**
* Low-level FS index object. Use to obtain low-level iterators.
@@ -65,9 +68,21 @@ public interface LowLevelIndex<T extends
CASImpl getCasImpl();
// incorporated from FSIndexImpl
-
+ /**
+ * This is **NOT** a comparator for Feature Structures, but rather
+ * something that compares two comparator specifications
+ * @return -
+ */
FSIndexComparator getComparatorForIndexSpecs();
+ /**
+ *
+ * @return a comparator used by this index to compare Feature Structures
+ * For sets, the equal is used to determine set membership
+ * For sorted, the comparator is the sort order (this comparator is without the ID)
+ */
+ Comparator<TOP> getComparator();
+
default void flush() { // probably not needed, but left for backwards compatibility 4/2015
throw new UnsupportedOperationException();
}