diff --git a/src/test/org/apache/lucene/index/DocHelper.java b/src/test/org/apache/lucene/index/DocHelper.java index 51a8eb73491..2de9f1ff42e 100644 --- a/src/test/org/apache/lucene/index/DocHelper.java +++ b/src/test/org/apache/lucene/index/DocHelper.java @@ -16,17 +16,18 @@ package org.apache.lucene.index; * limitations under the License. */ -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.analysis.WhitespaceAnalyzer; -import org.apache.lucene.document.*; -import org.apache.lucene.search.Similarity; -import org.apache.lucene.store.Directory; - import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; -import java.util.Enumeration; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.WhitespaceAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.Fieldable; +import org.apache.lucene.search.Similarity; +import org.apache.lucene.store.Directory; class DocHelper { public static final String FIELD_1_TEXT = "field one text"; @@ -257,13 +258,6 @@ class DocHelper { } public static int numFields(Document doc) { - Enumeration fields = doc.fields(); - int result = 0; - while (fields.hasMoreElements()) { - String name = fields.nextElement().toString(); - name += ""; // avoid compiler warning - result++; - } - return result; + return doc.getFields().size(); } } diff --git a/src/test/org/apache/lucene/index/TestFieldsReader.java b/src/test/org/apache/lucene/index/TestFieldsReader.java index 720e47aedf1..e6441ba9668 100644 --- a/src/test/org/apache/lucene/index/TestFieldsReader.java +++ b/src/test/org/apache/lucene/index/TestFieldsReader.java @@ -16,19 +16,25 @@ package org.apache.lucene.index; * limitations under the License. */ -import junit.framework.TestCase; -import org.apache.lucene.analysis.WhitespaceAnalyzer; -import org.apache.lucene.document.*; -import org.apache.lucene.search.Similarity; -import org.apache.lucene.store.FSDirectory; -import org.apache.lucene.store.RAMDirectory; - import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; +import java.util.List; import java.util.Set; -import java.util.Enumeration; + +import junit.framework.TestCase; + +import org.apache.lucene.analysis.WhitespaceAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.Fieldable; +import org.apache.lucene.document.LoadFirstFieldSelector; +import org.apache.lucene.document.SetBasedFieldSelector; +import org.apache.lucene.search.Similarity; +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.RAMDirectory; public class TestFieldsReader extends TestCase { private RAMDirectory dir = new RAMDirectory(); @@ -137,9 +143,9 @@ public class TestFieldsReader extends TestCase { Document doc = reader.doc(0, fieldSelector); assertTrue("doc is null and it shouldn't be", doc != null); int count = 0; - Enumeration enumeration = doc.fields(); - while (enumeration.hasMoreElements()) { - Field field = (Field) enumeration.nextElement(); + List l = doc.getFields(); + for (Iterator iter = l.iterator(); iter.hasNext();) { + Field field = (Field) iter.next(); assertTrue("field is null and it shouldn't be", field != null); String sv = field.stringValue(); assertTrue("sv is null and it shouldn't be", sv != null); diff --git a/src/test/org/apache/lucene/index/TestParallelReader.java b/src/test/org/apache/lucene/index/TestParallelReader.java index f33a4c87606..3c35a57fad3 100644 --- a/src/test/org/apache/lucene/index/TestParallelReader.java +++ b/src/test/org/apache/lucene/index/TestParallelReader.java @@ -16,26 +16,26 @@ package org.apache.lucene.index; * limitations under the License. */ +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; + import junit.framework.TestCase; + import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.MapFieldSelector; -import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Hits; import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; +import org.apache.lucene.search.Query; import org.apache.lucene.search.Searcher; import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Enumeration; - public class TestParallelReader extends TestCase { private Searcher parallel; @@ -87,9 +87,9 @@ public class TestParallelReader extends TestCase { Document doc24 = pr.document(1, new MapFieldSelector(Arrays.asList(new String[] {"f4"}))); Document doc223 = pr.document(1, new MapFieldSelector(new String[] {"f2", "f3"})); - assertEquals(1, numFields(doc11)); - assertEquals(1, numFields(doc24)); - assertEquals(2, numFields(doc223)); + assertEquals(1, doc11.getFields().size()); + assertEquals(1, doc24.getFields().size()); + assertEquals(2, doc223.getFields().size()); assertEquals("v1", doc11.get("f1")); assertEquals("v2", doc24.get("f4")); @@ -97,14 +97,6 @@ public class TestParallelReader extends TestCase { assertEquals("v2", doc223.get("f3")); } - private int numFields(Document doc) { - int num; - Enumeration e = doc.fields(); - for (num=0; e.hasMoreElements(); num++) - e.nextElement(); - return num; - } - public void testIncompatibleIndexes() throws IOException { // two documents: Directory dir1 = getDir1(); diff --git a/src/test/org/apache/lucene/index/TestSegmentReader.java b/src/test/org/apache/lucene/index/TestSegmentReader.java index bdd55a317e8..135fd5698da 100644 --- a/src/test/org/apache/lucene/index/TestSegmentReader.java +++ b/src/test/org/apache/lucene/index/TestSegmentReader.java @@ -16,16 +16,17 @@ package org.apache.lucene.index; * limitations under the License. */ -import junit.framework.TestCase; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Fieldable; -import org.apache.lucene.search.DefaultSimilarity; - import java.io.IOException; import java.util.Collection; import java.util.Iterator; -import java.util.Enumeration; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Fieldable; +import org.apache.lucene.search.DefaultSimilarity; +import org.apache.lucene.store.RAMDirectory; public class TestSegmentReader extends TestCase { private RAMDirectory dir = new RAMDirectory(); @@ -62,9 +63,9 @@ public class TestSegmentReader extends TestCase { //There are 2 unstored fields on the document that are not preserved across writing assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - DocHelper.unstored.size()); - Enumeration fields = result.fields(); - while (fields.hasMoreElements()) { - Fieldable field = (Fieldable) fields.nextElement(); + List fields = result.getFields(); + for (Iterator iter = fields.iterator(); iter.hasNext();) { + Fieldable field = (Fieldable) iter.next(); assertTrue(field != null); assertTrue(DocHelper.nameValues.containsKey(field.name())); }