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 2013/02/14 23:53:09 UTC
svn commit: r1446376 - in
/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src:
main/java/org/apache/uima/internal/util/rb_trees/
test/java/org/apache/uima/internal/util/rb_trees/
Author: schor
Date: Thu Feb 14 22:53:09 2013
New Revision: 1446376
URL: http://svn.apache.org/r1446376
Log:
[UIMA-2677] fix the iterator returned from iterator(), add test case.
Added:
uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/
uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java (with props)
Modified:
uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntArrayRBT.java
Modified: uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntArrayRBT.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntArrayRBT.java?rev=1446376&r1=1446375&r2=1446376&view=diff
==============================================================================
--- uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntArrayRBT.java (original)
+++ uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/internal/util/rb_trees/IntArrayRBT.java Thu Feb 14 22:53:09 2013
@@ -183,7 +183,7 @@ public class IntArrayRBT {
if (!hasNext()) {
throw new NoSuchElementException();
}
- this.currentNode = nextNode(this.currentNode);
+ this.currentNode = (this.currentNode == NIL) ? getFirstNode() : nextNode(this.currentNode);
return IntArrayRBT.this.key[this.currentNode];
}
Added: uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java?rev=1446376&view=auto
==============================================================================
--- uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java (added)
+++ uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java Thu Feb 14 22:53:09 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.internal.util.rb_trees;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.uima.internal.util.IntListIterator;
+import org.apache.uima.internal.util.IntPointerIterator;
+
+import junit.framework.TestCase;
+
+public class IntArrayRBTtest extends TestCase {
+ public void testIterator() {
+ IntArrayRBT ia = new IntArrayRBT();
+ Integer[] vs = new Integer[] {2, 2, 5, 1, 6, 7, 3, 4};
+ for (Integer i : vs) {
+ ia.insertKey(i);
+ }
+ Integer[] r = new Integer[vs.length];
+ int i = 0;
+ IntListIterator itl = ia.iterator();
+
+ while(itl.hasNext()){
+ r[i++] = itl.next();
+ }
+ assertEquals(i, vs.length - 1);
+ assertTrue(Arrays.equals(r, new Integer[] {1, 2, 3, 4, 5, 6, 7, null}));
+
+ i = 0;
+ IntPointerIterator it = ia.pointerIterator();
+ while (it.isValid()) {
+ r[i++] = it.get();
+ it.inc();
+ }
+ assertEquals(i, vs.length - 1);
+ assertTrue(Arrays.equals(r, new Integer[] {1, 2, 3, 4, 5, 6, 7, null}));
+
+ it = ia.pointerIterator();
+ assertTrue(it.isValid());
+ it.dec();
+ assertFalse(it.isValid());
+ it.inc();
+ assertFalse(it.isValid());
+ it.moveToLast();
+ assertTrue(it.isValid());
+ it.inc();
+ assertFalse(it.isValid());
+// it.dec(); // causes infinite loop
+// assertFalse(it.isValid());
+
+ }
+}
Propchange: uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/internal/util/rb_trees/IntArrayRBTtest.java
------------------------------------------------------------------------------
svn:eol-style = native