You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2015/12/24 01:23:50 UTC
svn commit: r1721587 - in
/uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util:
CasUtil.java FSCollectionFactory.java
Author: rec
Date: Thu Dec 24 00:23:50 2015
New Revision: 1721587
URL: http://svn.apache.org/viewvc?rev=1721587&view=rev
Log:
[UIMA-4520] Use snapshot iterators in uimaFIT select methods
- Use withSnapshotIterators() where possible and where the iterator is exposed
- where an iterator is used internally and the results are e.g. copied to a list, we shouldn't need to use snapshots
- where subiterator is used or when getting all indexed FSes, there is no API to use snapshot iterators
Modified:
uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java
Modified: uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
URL: http://svn.apache.org/viewvc/uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java?rev=1721587&r1=1721586&r2=1721587&view=diff
==============================================================================
--- uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java (original)
+++ uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java Thu Dec 24 00:23:50 2015
@@ -92,7 +92,7 @@ public final class CasUtil {
*/
@SuppressWarnings("unchecked")
public static <T extends AnnotationFS> Iterator<T> iterator(CAS cas, Type type) {
- return ((AnnotationIndex<T>) cas.getAnnotationIndex(type)).iterator();
+ return ((AnnotationIndex<T>) cas.getAnnotationIndex(type)).withSnapshotIterators().iterator();
}
/**
@@ -275,6 +275,8 @@ public final class CasUtil {
*/
public static List<AnnotationFS> selectAt(final CAS aCas, final Type aType, int aBegin, int aEnd) {
List<AnnotationFS> list = new ArrayList<AnnotationFS>();
+
+ // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> it = aCas.getAnnotationIndex(aType).iterator();
// Skip annotations whose start is before the start parameter.
@@ -388,6 +390,8 @@ public final class CasUtil {
int end = right.getBegin();
List<AnnotationFS> list = new ArrayList<AnnotationFS>();
+
+ // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> it = cas.getAnnotationIndex(type).iterator();
// Try to seek the insertion point.
@@ -495,6 +499,8 @@ public final class CasUtil {
int end = coveringAnnotation.getEnd();
List<AnnotationFS> list = new ArrayList<AnnotationFS>();
+
+ // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> it = cas.getAnnotationIndex(type).iterator();
// Try to seek the insertion point.
@@ -583,6 +589,8 @@ public final class CasUtil {
public static List<AnnotationFS> selectCovered(CAS cas, Type type, int begin, int end) {
List<AnnotationFS> list = new ArrayList<AnnotationFS>();
+
+ // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> it = cas.getAnnotationIndex(type).iterator();
// Skip annotations whose start is before the start parameter.
@@ -679,7 +687,10 @@ public final class CasUtil {
TypeSystem ts = cas.getTypeSystem();
List<AnnotationFS> list = new ArrayList<AnnotationFS>();
+
+ // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> iter = cas.getAnnotationIndex().iterator();
+
while (iter.hasNext()) {
AnnotationFS a = iter.next();
if ((a.getBegin() <= begin) && (a.getEnd() >= end)
@@ -792,6 +803,7 @@ public final class CasUtil {
if (!cas.getTypeSystem().subsumes(cas.getAnnotationType(), type)) {
throw new IllegalArgumentException("Type [" + type.getName() + "] is not an annotation type");
}
+ // withSnapshotIterators() not needed here since we return only one result
FSIterator<AnnotationFS> i = cas.getAnnotationIndex(type).iterator();
int n = index;
i.moveToFirst();
@@ -962,6 +974,7 @@ public final class CasUtil {
List<AnnotationFS> precedingAnnotations = new LinkedList<AnnotationFS>();
// Seek annotation in index
+ // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> itr = cas.getAnnotationIndex(type).iterator();
itr.moveTo(annotation);
@@ -1013,6 +1026,7 @@ public final class CasUtil {
}
// Seek annotation in index
+ // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
FSIterator<AnnotationFS> itr = cas.getAnnotationIndex(type).iterator();
itr.moveTo(annotation);
Modified: uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java
URL: http://svn.apache.org/viewvc/uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java?rev=1721587&r1=1721586&r2=1721587&view=diff
==============================================================================
--- uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java (original)
+++ uima/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/util/FSCollectionFactory.java Thu Dec 24 00:23:50 2015
@@ -818,7 +818,7 @@ public abstract class FSCollectionFactor
@Override
public Iterator<T> iterator() {
- return index.iterator();
+ return index.withSnapshotIterators().iterator();
}
@Override