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 13:25:05 UTC
svn commit: r1802482 - in
/uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl:
FSListIteratorImpl.java FsIterator_set_sorted.java FsIterator_subtypes.java
FsIterator_subtypes_list_unused.java
Author: schor
Date: Thu Jul 20 13:25:05 2017
New Revision: 1802482
URL: http://svn.apache.org/viewvc?rev=1802482&view=rev
Log:
[UIMA-5504] - update unused-saved for classes removed from cas.impl due to iterator refactor
Added:
uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FSListIteratorImpl.java
uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_set_sorted.java
uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes.java
uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes_list_unused.java
Added: uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FSListIteratorImpl.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FSListIteratorImpl.java?rev=1802482&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FSListIteratorImpl.java (added)
+++ uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FSListIteratorImpl.java Thu Jul 20 13:25:05 2017
@@ -0,0 +1,161 @@
+/*
+ * 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.ListIterator;
+import java.util.NoSuchElementException;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FeatureStructure;
+
+/**
+ * Class comment for FSListIteratorImpl.java goes here.
+ *
+ *
+ */
+class FSListIteratorImpl<T extends FeatureStructure> implements ListIterator<T> {
+
+ // Keep two pointers: one for the next element, and one for the previous
+ // one. The two pointers are always moved in lockstep. Watch for border
+ // conditions where only one of the pointers is valid.
+ private FSIterator<T> forward;
+
+ private FSIterator<T> back;
+
+ public FSListIteratorImpl(FSIterator<T> it) {
+ super();
+ this.forward = it;
+ this.back = it.copy();
+ it.moveToPrevious();
+ }
+
+ /**
+ * @see ListIterator#hasNext()
+ */
+ public boolean hasNext() {
+ return this.forward.isValid();
+ }
+
+ /**
+ * @see ListIterator#hasPrevious()
+ */
+ public boolean hasPrevious() {
+ return this.back.isValid();
+ }
+
+ /**
+ * Move the iterator so that the next call to {@link #previous() previous()} will return the first
+ * element in the index (for a non-empty index).
+ */
+ public void moveToEnd() {
+ // Move the back pointer to point at the last element.
+ this.back.moveToLast();
+ // Move the forward pointer past the end.
+ this.forward.moveToLast();
+ this.forward.moveToNext();
+ }
+
+ /**
+ * Move the iterator so that the next call to {@link #next() next()} will return the first element
+ * in the index (for a non-empty index).
+ */
+ public void moveToStart() {
+ // Move the forward pointer to the start.
+ this.forward.moveToFirst();
+ // Move the back pointer past the start.
+ this.back.moveToFirst();
+ this.back.moveToPrevious();
+ }
+
+ /**
+ * @see ListIterator#next()
+ */
+ public T next() throws NoSuchElementException {
+ // Throw exception if forward pointer is invalid.
+ if (!this.forward.isValid()) {
+ throw new NoSuchElementException();
+ }
+ // Move the forward pointer.
+ this.forward.moveToNext();
+ // Move the backward pointer. Need to check if it's valid.
+ if (this.back.isValid()) {
+ this.back.moveToNext();
+ } else {
+ // This is guaranteed to yield a valid pointer, since otherwise, the
+ // forward pointer couldn't have been valid.
+ this.back.moveToFirst();
+ }
+ // The back pointer is now pointing at the current forward element.
+ return this.back.get();
+ }
+
+ /**
+ * @see ListIterator#previous()
+ */
+ public T previous() throws NoSuchElementException {
+ // See comments for next().
+ if (!this.back.isValid()) {
+ throw new NoSuchElementException();
+ }
+ this.back.moveToPrevious();
+ if (this.forward.isValid()) {
+ this.forward.moveToPrevious();
+ } else {
+ this.forward.moveToLast();
+ }
+ return this.forward.get();
+ }
+
+ /**
+ * @see java.util.ListIterator#add(Object)
+ */
+ public void add(T o) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see java.util.ListIterator#nextIndex()
+ */
+ public int nextIndex() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see java.util.ListIterator#previousIndex()
+ */
+ public int previousIndex() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see java.util.ListIterator#set(T)
+ */
+ public void set(T o) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added: uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_set_sorted.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_set_sorted.java?rev=1802482&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_set_sorted.java (added)
+++ uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_set_sorted.java Thu Jul 20 13:25:05 2017
@@ -0,0 +1,264 @@
+/*
+ * 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.Iterator;
+import java.util.NavigableSet;
+import java.util.NoSuchElementException;
+
+import org.apache.uima.cas.FSIterator;
+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.jcas.cas.TOP;
+
+/**
+ * NOTE: This class is no longer used; instead, the callers which created instances of this class now
+ * create instances of OrderedFsSort_array.LL_iterator.
+ *
+ *
+ *
+ * @param <T> the type of FSs being returned from the iterator, supplied by the calling context
+ */
+class FsIterator_set_sorted<T extends FeatureStructure> extends FsIterator_singletype<T> {
+
+ // We use TOP instead of T because the
+ // signature of getting a "matching" element limits the type to the declared type, and
+ // in UIMA we can use, say an Annotation instance as a moveTo arg, for a navSet of some subtype of Annotation.
+ private NavigableSet<TOP> navSet; // == fsSortIndex.getNavigableSet()
+
+ final protected FsIndex_set_sorted<T> fsSetSortIndex; // for copy-on-write management, ll_getIndex, backwards compatibility
+
+ private T currentElement;
+
+ private boolean isGoingForward = true;
+
+ /**
+ * true if a next() set the the currentElement, and advanced position to next
+ *
+ * if true, then
+ * currentElement is the one that get should return, and position is already advanced
+ * if false, then
+ * get needs to do a next() to retrieve the now-currentElement, and advances position to next
+ */
+ private boolean isCurrentElementFromLastGet = false;
+
+ private Iterator<T> iterator; // changes according to direction, starting point, etc.
+
+ FsIterator_set_sorted(FsIndex_set_sorted<T> fsSetSortIndex, TypeImpl ti, Comparator<FeatureStructure> comp) {
+ super(ti, comp);
+ this.fsSetSortIndex = fsSetSortIndex;
+ moveToFirst();
+ Misc.internalError(); // class superseded
+ }
+
+ @Override
+ public boolean isValid() {return isCurrentElementFromLastGet ? true : iterator.hasNext();}
+
+ @Override
+ public void moveToFirst() {
+// fsSetSortIndex.maybeProcessBulkAdds();
+ this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getNonNullCow();
+ iterator = (Iterator<T>) navSet.iterator(); // in case iterator was reverse, etc.
+// resetConcurrentModification(); // follow create of iterator, which, in turn, does any pending batch processing
+ isGoingForward = true;
+ isCurrentElementFromLastGet = false;
+ }
+
+ @Override
+ public void moveToLast() {
+// fsSetSortIndex.maybeProcessBulkAdds();
+ this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getNonNullCow();
+ iterator = (Iterator<T>) navSet.descendingIterator();
+// resetConcurrentModification(); // follow create of iterator, which, in turn, does any pending batch processing
+ isGoingForward = false;
+ isCurrentElementFromLastGet = false;
+ }
+
+ @Override
+ public void moveToNextNvc() {
+ if (isGoingForward) {
+ if (isCurrentElementFromLastGet) {
+ isCurrentElementFromLastGet = false;
+ } else {
+ maybeTraceCowUsingCopy(fsSetSortIndex, (CopyOnWriteIndexPart) navSet);
+ currentElement = iterator.next();
+ // leave isCurrentElementFromLastGet false because we just moved to next, but haven't retrieved that value
+ }
+ } else {
+ //reverse direction
+ if (!isCurrentElementFromLastGet) {
+ maybeTraceCowUsingCopy(fsSetSortIndex, (CopyOnWriteIndexPart) navSet);
+ currentElement = iterator.next(); // need current value to do reverse iterator starting point
+ }
+ assert(currentElement != null);
+ iterator = (Iterator<T>) navSet.tailSet((TOP)currentElement, false).iterator();
+ isGoingForward = true;
+ isCurrentElementFromLastGet = false;
+ }
+ }
+
+ @Override
+ public void moveToPreviousNvc() {
+ if (!isGoingForward) {
+ if (isCurrentElementFromLastGet) {
+ isCurrentElementFromLastGet = false;
+ } else {
+ maybeTraceCowUsingCopy(fsSetSortIndex, (CopyOnWriteIndexPart) navSet);
+ currentElement = iterator.next();
+ // leave isCurrentElementFromLastGet false
+ }
+ } else {
+ //reverse direction
+ if (!isCurrentElementFromLastGet) {
+ maybeTraceCowUsingCopy(fsSetSortIndex, (CopyOnWriteIndexPart) navSet);
+ currentElement = iterator.next(); // need current value to do reverse iterator starting point
+ }
+ assert(currentElement != null);
+ iterator = (Iterator<T>) navSet.headSet((TOP)currentElement, false).descendingIterator();
+ isGoingForward = false;
+ isCurrentElementFromLastGet = false;
+ }
+ }
+
+ @Override
+ public T getNvc() {
+ if (!isCurrentElementFromLastGet) {
+ currentElement = iterator.next();
+ isCurrentElementFromLastGet = true;
+ }
+ maybeTraceCowUsingCopy(fsSetSortIndex, (CopyOnWriteIndexPart) navSet);
+ return currentElement;
+ }
+
+ /**
+ * @see org.apache.uima.internal.util.IntPointerIterator#copy()
+ */
+ @Override
+ public FsIterator_set_sorted<T> copy() {
+ return new FsIterator_set_sorted<T>(this.fsSetSortIndex, ti, this.comparator);
+ }
+
+ /**
+ * move to the "left most" fs that is equal using the comparator
+ * - this means the one after a LT compare or the beginning.
+ * reset isCurrentElementFromLastSet
+ * set isGoingForward
+ * @param fs the template FS indicating the position
+ */
+ @Override
+ public void moveTo(FeatureStructure fsIn) {
+ TOP fs = (TOP) fsIn;
+ isGoingForward = true;
+ isCurrentElementFromLastGet = false;
+ currentElement = null;
+ this.navSet = (NavigableSet<TOP>) fsSetSortIndex.getNonNullCow();
+// fsSetSortIndex.maybeProcessBulkAdds(); // not needed, always done due to previous size() call when creating iterator
+ Iterator<T> it = (Iterator<T>) navSet.headSet(fs, false).descendingIterator(); // may have a bunch of equal (using withoutID compare) at end
+ // last element in headSet is 1 before the one LE fs.
+ // define "target element" to be the found in the search
+ // the last element in the headSet if was "inclusive" mode
+ // target element is LE fs including id compare
+ // not including ID compare: target element is LE fs, maybe more likely equal
+ // last element for "exclusive":
+ // target if target is LT,
+ // one before target if EQ
+ // by including ID, sometimes last element may be EQ to target
+
+ // if the 1st previous element doesn't exist, then start at the first element
+ if (!it.hasNext()) {
+ moveToFirst();
+ return;
+ }
+
+ // iterator is valid. Move backwards until either hit the end or find element not equal
+ TOP elementBefore = null;
+ boolean comparedEqual = false; // value is ignored, but needed for Java compile
+ while (it.hasNext()) {
+ comparedEqual = (0 == ((CopyOnWriteOrderedFsSet_array)navSet).comparatorWithoutID.compare(elementBefore = (TOP)it.next(), fs));
+ if (!comparedEqual) {
+ break;
+ }
+ }
+
+ if (comparedEqual) { // then we ran off the end
+ moveToFirst();
+ return;
+ }
+
+ iterator = (Iterator<T>) navSet.tailSet(elementBefore, false).iterator();
+// resetConcurrentModification(); // follow create of iterator, which, in turn, does any pending batch processing
+ return;
+ }
+
+ @Override
+ public int ll_indexSize() {
+ return navSet.size();
+ }
+
+
+ @Override
+ public int ll_maxAnnotSpan() {
+ return fsSetSortIndex.isAnnotIdx
+ ? fsSetSortIndex.ll_maxAnnotSpan()
+ : Integer.MAX_VALUE;
+ }
+
+ @Override
+ public LowLevelIndex<T> ll_getIndex() {
+ return fsSetSortIndex;
+ }
+
+// @Override
+// protected int getModificationCountFromIndex() {
+// return ((CopyOnWriteOrderedFsSet_array)navSet).getModificationCount();
+// }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.LowLevelIterator#isIndexesHaveBeenUpdated()
+ */
+ @Override
+ public boolean isIndexesHaveBeenUpdated() {
+ return navSet != fsSetSortIndex.getCopyOnWriteIndexPart();
+ }
+
+ @Override
+ public boolean maybeReinitIterator() {
+ throw Misc.internalError(); // not yet done
+ }
+
+ @Override
+ public void moveToFirstNoReinit() {
+ Misc.internalError(); // not yet done
+ }
+
+ @Override
+ public void moveToLastNoReinit() {
+ Misc.internalError(); // not yet done
+ }
+
+ @Override
+ public void moveToNoReinit(FeatureStructure fs) {
+ Misc.internalError(); // not yet done
+ }
+
+}
+
Added: uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes.java?rev=1802482&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes.java (added)
+++ uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes.java Thu Jul 20 13:25:05 2017
@@ -0,0 +1,58 @@
+/*
+ * 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 org.apache.uima.cas.FeatureStructure;
+
+
+public abstract class FsIterator_subtypes<T extends FeatureStructure> extends FsIterator_multiple_indexes<T> {
+
+ // The IICP
+ final protected FsIndex_iicp<T> iicp;
+
+ public FsIterator_subtypes(FsIndex_iicp<T> iicp) {
+ super(iicp.getIterators());
+ this.iicp = iicp;
+ }
+
+ protected FsIndex_iicp<? extends FeatureStructure> getIicp() {
+ return iicp;
+ }
+
+ @Override
+ public LowLevelIndex<T> ll_getIndex() {
+ return iicp;
+ }
+
+ @Override
+ public int ll_maxAnnotSpan() {
+ return iicp.ll_maxAnnotSpan();
+ }
+
+ @Override
+ public String toString() {
+ TypeImpl type = (TypeImpl) this.ll_getIndex().getType();
+ StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()).append(":").append(System.identityHashCode(this));
+ sb.append(" over Type: ").append(type.getName()).append(":").append(type.getCode());
+ sb.append(", index size: ").append(this.ll_indexSize());
+ return sb.toString();
+ }
+
+}
Added: uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes_list_unused.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes_list_unused.java?rev=1802482&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes_list_unused.java (added)
+++ uima/uv3/uimaj-v3/trunk/unused-saved/src/org/apache/uima/cas/impl/FsIterator_subtypes_list_unused.java Thu Jul 20 13:25:05 2017
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FeatureStructure;
+
+public abstract class FsIterator_subtypes_list_unused <T extends FeatureStructure> extends FsIterator_multiple_indexes<T> {
+
+ public FsIterator_subtypes_list_unused(FsIndex_iicp<T> iicp) {
+ super(iicp.getIterators());
+ }
+
+
+}