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 [2/2] -
/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator.java Thu Jul 20 14:41:08 2017
@@ -59,9 +59,8 @@ public interface LowLevelIterator<T exte
/**
- * Return the size of the underlying index.
- *
- * @return The size of the index.
+ * @return The size of the index. In case of copy-on-write, this returns the size of the
+ * index at the time the iterator was created.
*/
int ll_indexSize();
@@ -83,42 +82,63 @@ public interface LowLevelIterator<T exte
* This includes empty iterators becoming non-empty.
*/
boolean isIndexesHaveBeenUpdated();
+
+ /**
+ * Internal use
+ * @return true if the iterator was refreshed to match the current index
+ */
+ boolean maybeReinitIterator();
+
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#moveToFirst()
+ */
+ @Override
+ default void moveToFirst() {
+ maybeReinitIterator();
+ moveToFirstNoReinit();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#moveToLast()
+ */
+ @Override
+ default void moveToLast() {
+ maybeReinitIterator();
+ moveToLastNoReinit();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.FSIterator#moveTo(org.apache.uima.cas.FeatureStructure)
+ */
+ @Override
+ default void moveTo(FeatureStructure fs) {
+ maybeReinitIterator();
+ moveToNoReinit(fs);
+ }
+
+
+ /**
+ * Internal use
+ * same as moveToFirst, but won't reset to use current contents of index if index has changed
+ */
+ void moveToFirstNoReinit();
+
+ /**
+ * Internal use
+ * same as moveToFirst, but won't reset to use current contents of index if index has changed
+ */
+ void moveToLastNoReinit();
+
+ /**
+ * Internal use
+ * same as moveToFirst, but won't reset to use current contents of index if index has changed
+ */
+ void moveToNoReinit(FeatureStructure fs);
/**
* an empty iterator
*/
- static final LowLevelIterator<FeatureStructure> FS_ITERATOR_LOW_LEVEL_EMPTY = new LowLevelIterator<FeatureStructure> () {
- @Override
- public boolean isValid() { return false; }
- @Override
- public FeatureStructure get() throws NoSuchElementException { throw new NoSuchElementException(); }
- @Override
- public FeatureStructure getNvc() { throw new NoSuchElementException(); }
- @Override
- public void moveTo(int i) {}
- @Override
- public void moveToFirst() {}
- @Override
- public void moveToLast() {}
- @Override
- public LowLevelIterator<FeatureStructure> copy() { return this; }
- @Override
- public void moveToNext() {}
- @Override
- public void moveToNextNvc() {}
- @Override
- public void moveToPrevious() {}
- @Override
- public void moveToPreviousNvc() {}
- @Override
- public void moveTo(FeatureStructure fs) {}
- @Override
- public int ll_indexSize() { return 0; }
- @Override
- public int ll_maxAnnotSpan() { return Integer.MAX_VALUE; }
- @Override
- public LowLevelIndex<FeatureStructure> ll_getIndex() { return null; }
- @Override
- public boolean isIndexesHaveBeenUpdated() { return false; }
- };
+ static final LowLevelIterator<FeatureStructure> FS_ITERATOR_LOW_LEVEL_EMPTY =
+ new LowLevelIterator_empty();
}
Added: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator_empty.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator_empty.java?rev=1802495&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator_empty.java (added)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/LowLevelIterator_empty.java Thu Jul 20 14:41:08 2017
@@ -0,0 +1,70 @@
+/*
+ * 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.NoSuchElementException;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FeatureStructure;
+
+/**
+ * An empty Low-level FS iterator
+ */
+public class LowLevelIterator_empty<T extends FeatureStructure> implements LowLevelIterator<T> {
+
+ @Override
+ public boolean isValid() { return false; }
+ @Override
+ public T getNvc() { throw new NoSuchElementException(); }
+ @Override
+ public void moveTo(int i) {}
+ @Override
+ public void moveToFirst() {}
+ @Override
+ public void moveToLast() {}
+
+ @Override
+ public void moveToFirstNoReinit() {}
+ @Override
+ public void moveToLastNoReinit() {}
+ @Override
+ public void moveToNoReinit(FeatureStructure fs) {}
+
+ @Override
+ public LowLevelIterator_empty<T> copy() { return this; }
+ @Override
+ public void moveToNextNvc() {}
+ @Override
+ public void moveToPreviousNvc() {}
+ @Override
+ public void moveTo(FeatureStructure fs) {}
+ @Override
+ public int ll_indexSize() { return 0; }
+ @Override
+ public int ll_maxAnnotSpan() { return Integer.MAX_VALUE; }
+ @Override
+ public LowLevelIndex<T> ll_getIndex() { return null; }
+ @Override
+ public boolean isIndexesHaveBeenUpdated() { return false; }
+ @Override
+ public boolean maybeReinitIterator() {
+ return false;
+ }
+}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java Thu Jul 20 14:41:08 2017
@@ -591,9 +591,9 @@ public class SelectFSs_impl <T extends F
- private FSIterator<T>[] getPlainIteratorsForAllViews() {
+ private LowLevelIterator<T>[] getPlainIteratorsForAllViews() {
final int nbrViews = view.getNumberOfViews();
- FSIterator<T>[] ita = new FSIterator[nbrViews];
+ LowLevelIterator<T>[] ita = new LowLevelIterator[nbrViews];
for (int i = 1; i <= nbrViews; i++) {
CASImpl v = (i == 1) ? view.getInitialView() : (CASImpl) view.getView(i);
@@ -623,7 +623,7 @@ public class SelectFSs_impl <T extends F
}
- private FSIterator<T> plainFsIterator(FSIndex<T> idx, CASImpl v) {
+ private LowLevelIterator<T> plainFsIterator(FSIndex<T> idx, CASImpl v) {
if (null == idx) {
// no bounds, not ordered
// type could be null
@@ -641,22 +641,22 @@ public class SelectFSs_impl <T extends F
final boolean isIndexOrdered = idx.getIndexingStrategy() == FSIndex.SORTED_INDEX;
final boolean isAnnotationIndex = idx instanceof AnnotationIndex;
final AnnotationIndex ai = isAnnotationIndex ? (AnnotationIndex)idx: null;
- FSIterator<T> it;
+ LowLevelIterator<T> it;
if (boundsUse == BoundsUse.notBounded) {
if (!isIndexOrdered) {
- it = idx.iterator();
+ it = (LowLevelIterator<T>) idx.iterator();
} else {
// index is ordered but no bounds are being used - return plain fsIterator or maybe nonOverlapping version
it = (isAnnotationIndex && isNonOverlapping)
- ? ai.iterator(false)
+ ? (LowLevelIterator<T>) ai.iterator(false)
: (isUnordered && idx instanceof FsIndex_iicp)
? ((FsIndex_iicp<T>)idx).iteratorUnordered()
- : idx.iterator();
+ : (LowLevelIterator<T>) idx.iterator();
}
} else {
// bounds in use, index must be annotation index, is ordered
- it = (FSIterator<T>) new Subiterator<>(
- (FSIterator<AnnotationFS>)idx.iterator(),
+ it = new Subiterator(
+ (FSIterator<T>)idx.iterator(),
boundingFs,
!isNonOverlapping, // ambiguous
!isIncludeAnnotBeyondBounds, // strict
@@ -664,7 +664,7 @@ public class SelectFSs_impl <T extends F
isTypePriority,
isPositionUsesType,
isUseAnnotationEquals,
- v.indexRepository.getAnnotationFsComparator());
+ v.indexRepository.getAnnotationFsComparatorWithoutId());
}
it = isBackwards ? new FsIterator_backwards<>(it) : it;
@@ -674,7 +674,7 @@ public class SelectFSs_impl <T extends F
return it;
}
- private FSIterator<T> altSourceIterator() {
+ private LowLevelIterator<T> altSourceIterator() {
T[] filtered;
if (sourceFSList != null) {
List<T> filteredItems = new ArrayList<T>();
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java?rev=1802495&r1=1802494&r2=1802495&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java Thu Jul 20 14:41:08 2017
@@ -42,7 +42,7 @@ import org.apache.uima.jcas.tcas.Annotat
*
* The 2nd form is produced lazily when needed, and
* is made by a one-time forward traversal to compute unambiguous subsets and store them into a list.
- * - The 2nd form is needed only for unambiguous style if backwards or moveto(fs) operation.
+ * - The 2nd form is needed only for unambiguous style if backwards or moveTo(fs) operation.
*
* The 1st form uses the underlying iterator directly, and does skipping as needed, while iterating
* - going forward:
@@ -96,7 +96,7 @@ public class Subiterator<T extends Annot
private int pos = 0; // used for form 2
- private final FSIterator<Annotation> it;
+ private final LowLevelIterator<Annotation> it;
private final Annotation boundingAnnot; // the bounding annotation need not be a subtype of T
@@ -168,7 +168,7 @@ public class Subiterator<T extends Annot
boolean isSkipEquals,
Comparator<TOP> annotationComparator
) {
- this.it = (FSIterator<Annotation>) it;
+ this.it = (LowLevelIterator<Annotation>) it;
this.boundingAnnot = (Annotation) boundingAnnot;
this.isBounded = boundsUse != null && boundsUse != BoundsUse.notBounded;
this.boundsUse = (boundsUse == null) ? BoundsUse.notBounded : boundsUse;
@@ -245,7 +245,7 @@ public class Subiterator<T extends Annot
Annotation coveringStartPos,
Annotation coveringEndPos
) {
- this.it = it;
+ this.it = (LowLevelIterator<Annotation>) it;
this.boundingAnnot = boundingAnnot;
this.isBounded = boundsUse != null;
this.boundsUse = boundsUse;
@@ -286,7 +286,7 @@ public class Subiterator<T extends Annot
}
private void moveToExact(Annotation targetAnnotation) {
- it.moveTo(targetAnnotation); // move to left-most equal one
+ it.moveToNoReinit(targetAnnotation); // move to left-most equal one
boolean found = adjustForTypePriorityBoundingBegin(targetAnnotation._id);
if (!found)
while (it.isValid()) { // advance to the exact equal one
@@ -303,20 +303,20 @@ public class Subiterator<T extends Annot
private void moveToStart() {
switch (boundsUse) {
case notBounded:
- it.moveToFirst();
+ it.moveToFirstNoReinit();
break;
case sameBeginEnd:
- it.moveTo(boundingAnnot);
+ it.moveToNoReinit(boundingAnnot);
adjustForTypePriorityBoundingBegin(0);
skipOverBoundingAnnot(true);
maybeMakeItInvalidSameBeginEnd();
case coveredBy:
- it.moveTo(boundingAnnot);
+ it.moveToNoReinit(boundingAnnot);
adjustForTypePriorityBoundingBegin(0);
adjustForStrictOrCoveringAndBoundSkip(true); // forward
break;
case covering:
- it.moveTo(coveringStartPos); // sufficiently before the bounds
+ it.moveToNoReinit(coveringStartPos); // sufficiently before the bounds
adjustForTypePriorityBoundingBegin(0);
adjustForCoveringAndBoundSkip(true); // forward
break;
@@ -452,7 +452,7 @@ public class Subiterator<T extends Annot
*/
private void maybeMoveToPrevBounded() {
if (it.get()._id == startId) {
- it.moveToFirst(); // so next is invalid
+ it.moveToFirstNoReinit(); // so next is invalid
}
it.moveToPreviousNvc();
}
@@ -481,7 +481,7 @@ public class Subiterator<T extends Annot
}
it.moveToPrevious();
if (!it.isValid()) {
- it.moveToFirst(); // not moveToStart - called by moveToStart
+ it.moveToFirstNoReinit(); // not moveToStart - called by moveToStart
// Annotation f = it.getNvc();
// if (!isBeginEndTypeEqualToBound(it.getNvc())) {
// it.moveToPrevious(); // make invalid
@@ -549,25 +549,6 @@ public class Subiterator<T extends Annot
/*
* (non-Javadoc)
*
- * @see org.apache.uima.cas.FSIterator#get()
- */
- @Override
- public T get() throws NoSuchElementException {
- if (isListForm) {
- if ((this.pos >= 0) && (this.pos < this.list.size())) {
- return (T) this.list.get(this.pos);
- }
- } else {
- if (isValid()) {
- return (T)it.get();
- }
- }
- throw new NoSuchElementException();
- }
-
- /*
- * (non-Javadoc)
- *
* @see org.apache.uima.cas.FSIterator#getNvc()
*/
public T getNvc() {
@@ -577,17 +558,6 @@ public class Subiterator<T extends Annot
return (T)it.getNvc();
}
}
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.uima.cas.FSIterator#moveToNext()
- */
- @Override
- public void moveToNext() {
- if (!isValid()) return;
- moveToNextNvc();
- }
@Override
public void moveToNextNvc() {
@@ -637,19 +607,7 @@ public class Subiterator<T extends Annot
makeInvalid();
}
}
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.uima.cas.FSIterator#moveToPrevious()
- */
- public void moveToPrevious() {
- if (!isValid()) {
- return;
- }
- moveToPreviousNvc();
- }
-
+
@Override
public void moveToPreviousNvc() {
if (isListForm) {
@@ -698,15 +656,10 @@ public class Subiterator<T extends Annot
/*
* (non-Javadoc)
*
- * @see org.apache.uima.cas.FSIterator#moveToFirst()
+ * @see org.apache.uima.cas.FSIterator#moveToFirstNoReinit()
*/
@Override
- public void moveToFirst() {
- if (isIndexesHaveBeenUpdated()) {
- resetList();
- moveToStartSetEmptyAndId();
- return;
- }
+ public void moveToFirstNoReinit() {
if (isEmpty) {
return;
@@ -731,13 +684,13 @@ public class Subiterator<T extends Annot
/*
* This operation is relatively expensive one time for unambiguous
*
- * @see org.apache.uima.cas.FSIterator#moveToLast()
+ * @see org.apache.uima.cas.FSIterator#moveToLastNoReinit()
*/
@Override
- public void moveToLast() {
- if (isIndexesHaveBeenUpdated()) {
- moveToFirst(); // done to recompute is empty, reset list, recompute bounds, etc.
- }
+ public void moveToLastNoReinit() {
+// if (isIndexesHaveBeenUpdated()) {
+// moveToFirst(); // done to recompute is empty, reset list, recompute bounds, etc.
+// }
if (isEmpty) {
return;
@@ -785,7 +738,7 @@ public class Subiterator<T extends Annot
* @param goBackwards when true, continue to backup
*/
private void moveToJustPastBoundsAndBackup(int begin, int end, Predicate<Annotation> goBackwards) {
- it.moveTo(new Annotation(jcas, begin, end));
+ it.moveToNoReinit(new Annotation(jcas, begin, end));
if (it.isValid()) {
Annotation a = it.getNvc();
while (goBackwards.test(a)) {
@@ -802,7 +755,7 @@ public class Subiterator<T extends Annot
a = it.getNvc();
}
} else {
- it.moveToLast();
+ it.moveToLastNoReinit();
adjustForStrictOrCoveringAndBoundSkip(false);
}
}
@@ -837,13 +790,13 @@ public class Subiterator<T extends Annot
/*
* (non-Javadoc)
*
- * @see org.apache.uima.cas.FSIterator#moveTo(org.apache.uima.cas.FeatureStructure)
+ * @see org.apache.uima.cas.FSIterator#moveToNoReinit(org.apache.uima.cas.FeatureStructure)
*/
@Override
- public void moveTo(FeatureStructure fs) {
- if (isIndexesHaveBeenUpdated()) {
- moveToFirst(); // done to recompute is empty, reset list, recompute bounds, etc.
- }
+ public void moveToNoReinit(FeatureStructure fs) {
+// if (isIndexesHaveBeenUpdated()) {
+// moveToFirst(); // done to recompute is empty, reset list, recompute bounds, etc.
+// }
if (isEmpty) return;
@@ -878,7 +831,7 @@ public class Subiterator<T extends Annot
if (isValid()) {
moveToNext(); // backed up one to much
} else {
- moveToFirst();
+ moveToFirstNoReinit();
}
} else {
@@ -887,7 +840,7 @@ public class Subiterator<T extends Annot
// if no element is greater
pos = (-pos) - 1;
if (!isValid()) {
- moveToLast();
+ moveToLastNoReinit();
if (!isValid()) {
return;
}
@@ -896,7 +849,7 @@ public class Subiterator<T extends Annot
moveToPrevious();
}
if (!isValid()) {
- moveToFirst();
+ moveToFirstNoReinit();
return;
}
moveToNext(); // back up one
@@ -907,7 +860,7 @@ public class Subiterator<T extends Annot
// Always bounded (if unbounded, that's only when subiterator is being used to
// implement "unambiguous", and that mode requires the "list" form above.)
// can be one of 3 bounds: coveredBy, covering, and sameBeginEnd.
- it.moveTo(fs); // may move before, within, or after bounds
+ it.moveToNoReinit(fs); // may move before, within, or after bounds
adjustForTypePriorityBoundingBegin(0); // does nothing if using type priorities
adjustForStrictOrCoveringAndBoundSkip(true); // "covering" case adjustments
@@ -923,13 +876,13 @@ public class Subiterator<T extends Annot
makeInvalid();
} else if (isTypePriority && annotationComparator.compare(a, boundingAnnot) < 0) {
// with type priority, position is before bound.
- moveToFirst();
+ moveToFirstNoReinit();
} else { // is not type priority case - see if too low
final int b = a.getBegin();
final int e = a.getEnd();
if (b < boundBegin ||
( b == boundBegin && e > boundEnd)) {
- moveToFirst();
+ moveToFirstNoReinit();
} else if (isPositionUsesType &&
b == boundBegin &&
e == boundEnd &&
@@ -1000,7 +953,7 @@ public class Subiterator<T extends Annot
}
private void makeInvalid() {
- it.moveToFirst();
+ it.moveToFirstNoReinit();
it.moveToPrevious();
}
@@ -1013,6 +966,15 @@ public class Subiterator<T extends Annot
return ((LowLevelIterator<?>)it).isIndexesHaveBeenUpdated();
}
+ @Override
+ public boolean maybeReinitIterator() {
+ if (it.maybeReinitIterator()) {
+ resetList();
+ moveToStartSetEmptyAndId();
+ return true;
+ }
+ return false;
+ }
// // makes an extra copy of the items
// private void initAmbiguousSubiterator(AnnotationFS annot, final boolean strict) {
@@ -1021,7 +983,7 @@ public class Subiterator<T extends Annot
// if (annot == null) {
// it.moveToFirst();
// } else {
-// it.moveTo(annot); // to "earliest" equal, or if none are equal, to the one just later than annot
+// it.moveToNoReinit(annot); // to "earliest" equal, or if none are equal, to the one just later than annot
// }
//
// // This is a little silly, it skips 1 of possibly many indexed annotations if the earliest one is "equal"
@@ -1053,7 +1015,7 @@ public class Subiterator<T extends Annot
// private void initUnambiguousSubiterator(AnnotationFS annot, final boolean strict) {
// final int start = annot.getBegin();
// final int boundingEnd = annot.getEnd();
-// it.moveTo(annot);
+// it.moveToNoReinit(annot);
//
// if (it.isValid() && it.get().equals(annot)) {
// it.moveToNext();