lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r749875 - in /lucene/java/trunk/src: java/org/apache/lucene/search/ test/org/apache/lucene/search/ test/org/apache/lucene/util/
Date Wed, 04 Mar 2009 01:50:28 GMT
Author: mikemccand
Date: Wed Mar  4 01:50:27 2009
New Revision: 749875

URL: http://svn.apache.org/viewvc?rev=749875&view=rev
Log:
replace java 5 only constructs w/ java 1.4 equivalents

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestDocIdSet.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java
    lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java?rev=749875&r1=749874&r2=749875&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheTermsFilter.java Wed Mar
 4 01:50:27 2009
@@ -22,7 +22,6 @@
 import org.apache.lucene.util.OpenBitSet;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 /**
  * A {@link Filter} that only accepts documents whose single
@@ -96,9 +95,9 @@
 
 public class FieldCacheTermsFilter extends Filter {
   private String field;
-  private Iterable terms;
+  private String[] terms;
 
-  public FieldCacheTermsFilter(String field, Iterable terms) {
+  public FieldCacheTermsFilter(String field, String[] terms) {
     this.field = field;
     this.terms = terms;
   }
@@ -119,9 +118,8 @@
     public FieldCacheTermsFilterDocIdSet(FieldCache.StringIndex fcsi) {
       this.fcsi = fcsi;
       openBitSet = new OpenBitSet(this.fcsi.lookup.length);
-      for (Iterator it = terms.iterator(); it.hasNext();) {
-        Object term = it.next();
-        int termNumber = this.fcsi.binarySearchLookup((String) term);
+      for (int i=0;i<terms.length;i++) {
+        int termNumber = this.fcsi.binarySearchLookup(terms[i]);
         if (termNumber > 0) {
           openBitSet.fastSet(termNumber);
         }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestDocIdSet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestDocIdSet.java?rev=749875&r1=749874&r2=749875&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestDocIdSet.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestDocIdSet.java Wed Mar  4 01:50:27
2009
@@ -23,6 +23,7 @@
 import java.util.Iterator;
 
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
 
 public class TestDocIdSet extends LuceneTestCase {
   public void testFilteredDocIdSet() throws Exception {
@@ -85,8 +86,8 @@
     int[] answer = new int[]{4,6,8};
     boolean same = Arrays.equals(answer, docs);
     if (!same) {
-      System.out.println("answer: "+Arrays.toString(answer));
-      System.out.println("gotten: "+Arrays.toString(docs));
+      System.out.println("answer: "+_TestUtil.arrayToString(answer));
+      System.out.println("gotten: "+_TestUtil.arrayToString(docs));
       fail();
     }
   }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java?rev=749875&r1=749874&r2=749875&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java Wed
Mar  4 01:50:27 2009
@@ -55,18 +55,18 @@
 
     List terms = new ArrayList();
     terms.add("5");
-    results = searcher.search(q, new FieldCacheTermsFilter(fieldName, terms), numDocs).scoreDocs;
+    results = searcher.search(q, new FieldCacheTermsFilter(fieldName, (String[]) terms.toArray(new
String[0])), numDocs).scoreDocs;
     assertEquals("Must match nothing", 0, results.length);
 
     terms = new ArrayList();
     terms.add("10");
-    results = searcher.search(q, new FieldCacheTermsFilter(fieldName, terms), numDocs).scoreDocs;
+    results = searcher.search(q, new FieldCacheTermsFilter(fieldName, (String[]) terms.toArray(new
String[0])), numDocs).scoreDocs;
     assertEquals("Must match 1", 1, results.length);
 
     terms = new ArrayList();
     terms.add("10");
     terms.add("20");
-    results = searcher.search(q, new FieldCacheTermsFilter(fieldName, terms), numDocs).scoreDocs;
+    results = searcher.search(q, new FieldCacheTermsFilter(fieldName, (String[]) terms.toArray(new
String[0])), numDocs).scoreDocs;
     assertEquals("Must match 2", 2, results.length);
 
     reader.close();

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=749875&r1=749874&r2=749875&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java Wed Mar  4 01:50:27
2009
@@ -181,7 +181,7 @@
   }
   
   public String getRandomNumberString(int num, int low, int high) {
-    StringBuilder sb = new StringBuilder();
+    StringBuffer sb = new StringBuffer();
     for (int i = 0; i < num; i++) {
       sb.append(getRandomNumber(low, high));
     }
@@ -193,7 +193,7 @@
   }
   
   public String getRandomCharString(int num, int start, int end) {
-    StringBuilder sb = new StringBuilder();
+    StringBuffer sb = new StringBuffer();
     for (int i = 0; i < num; i++) {
       sb.append(new Character((char) getRandomNumber(start, end)));
     }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java?rev=749875&r1=749874&r2=749875&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java Wed Mar  4 01:50:27
2009
@@ -25,6 +25,7 @@
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.util._TestUtil;
 
 import java.util.Random;
 import java.util.Arrays;
@@ -338,8 +339,9 @@
         assert newDocs[i] instanceof FieldDoc;
         FieldDoc oldHit = (FieldDoc) oldDocs[i];
         FieldDoc newHit = (FieldDoc) newDocs[i];
-        assertEquals("hit " + i + " of " + oldDocs.length + " differs: oldDoc=" + oldHit.doc
+ " vs newDoc=" + newHit.doc + " oldFields=" + Arrays.toString(oldHit.fields) + " newFields="
+ Arrays.toString(newHit.fields),
+        assertEquals("hit " + i + " of " + oldDocs.length + " differs: oldDoc=" + oldHit.doc
+ " vs newDoc=" + newHit.doc + " oldFields=" + _TestUtil.arrayToString(oldHit.fields) + "
newFields=" + _TestUtil.arrayToString(newHit.fields),
                      oldHit.doc, newHit.doc);
+
         assertEquals(oldHit.score, newHit.score, 0.00001);
         assertTrue(Arrays.equals(oldHit.fields, newHit.fields));
       } else {

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java?rev=749875&r1=749874&r2=749875&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java Wed Mar  4 01:50:27 2009
@@ -71,4 +71,36 @@
       return true;
   }
 
+  /** Use only for testing.
+   *  @deprecated -- in 3.0 we can use Arrays.toString
+   *  instead */
+  public static String arrayToString(int[] array) {
+    StringBuffer buf = new StringBuffer();
+    buf.append("[");
+    for(int i=0;i<array.length;i++) {
+      if (i > 0) {
+        buf.append(" ");
+      }
+      buf.append(array[i]);
+    }
+    buf.append("]");
+    return buf.toString();
+  }
+
+  /** Use only for testing.
+   *  @deprecated -- in 3.0 we can use Arrays.toString
+   *  instead */
+  public static String arrayToString(Object[] array) {
+    StringBuffer buf = new StringBuffer();
+    buf.append("[");
+    for(int i=0;i<array.length;i++) {
+      if (i > 0) {
+        buf.append(" ");
+      }
+      buf.append(array[i]);
+    }
+    buf.append("]");
+    return buf.toString();
+  }
+
 }



Mime
View raw message