lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r1479862 [15/38] - in /lucene/dev/branches/lucene4258: ./ dev-tools/ dev-tools/idea/.idea/ dev-tools/idea/.idea/libraries/ dev-tools/maven/ dev-tools/maven/solr/ dev-tools/maven/solr/core/src/java/ dev-tools/maven/solr/solrj/src/java/ dev-t...
Date Tue, 07 May 2013 11:21:14 GMT
Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.java Tue May  7 11:20:55 2013
@@ -17,8 +17,9 @@ package org.apache.lucene.util;
  * limitations under the License.
  */
 
-import java.util.Comparator;
+
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.RandomAccess;
 
@@ -34,190 +35,144 @@ import java.util.RandomAccess;
 public final class CollectionUtil {
 
   private CollectionUtil() {} // no instance
-  
-  /** SorterTemplate with custom {@link Comparator} */
-  private static <T> SorterTemplate getSorter(final List<T> list, final Comparator<? super T> comp) {
-    if (!(list instanceof RandomAccess))
-      throw new IllegalArgumentException("CollectionUtil can only sort random access lists in-place.");
-    return new SorterTemplate() {
-      @Override
-      protected void swap(int i, int j) {
-        Collections.swap(list, i, j);
-      }
-      
-      @Override
-      protected int compare(int i, int j) {
-        return comp.compare(list.get(i), list.get(j));
-      }
+  private static final class ListIntroSorter<T> extends IntroSorter {
 
-      @Override
-      protected void setPivot(int i) {
-        pivot = list.get(i);
-      }
-  
-      @Override
-      protected int comparePivot(int j) {
-        return comp.compare(pivot, list.get(j));
-      }
-      
-      private T pivot;
-    };
-  }
-  
-  /** Natural SorterTemplate */
-  private static <T extends Comparable<? super T>> SorterTemplate getSorter(final List<T> list) {
-    if (!(list instanceof RandomAccess))
-      throw new IllegalArgumentException("CollectionUtil can only sort random access lists in-place.");
-    return new SorterTemplate() {
-      @Override
-      protected void swap(int i, int j) {
-        Collections.swap(list, i, j);
-      }
-      
-      @Override
-      protected int compare(int i, int j) {
-        return list.get(i).compareTo(list.get(j));
-      }
-
-      @Override
-      protected void setPivot(int i) {
-        pivot = list.get(i);
-      }
-  
-      @Override
-      protected int comparePivot(int j) {
-        return pivot.compareTo(list.get(j));
-      }
-      
-      private T pivot;
-    };
-  }
+    T pivot;
+    final List<T> list;
+    final Comparator<? super T> comp;
+
+    ListIntroSorter(List<T> list, Comparator<? super T> comp) {
+      super();
+      if (!(list instanceof RandomAccess))
+        throw new IllegalArgumentException("CollectionUtil can only sort random access lists in-place.");
+      this.list = list;
+      this.comp = comp;
+    }
+
+    @Override
+    protected void setPivot(int i) {
+      pivot = list.get(i);
+    }
+
+    @Override
+    protected void swap(int i, int j) {
+      Collections.swap(list, i, j);
+    }
+
+    @Override
+    protected int compare(int i, int j) {
+      return comp.compare(list.get(i), list.get(j));
+    }
+
+    @Override
+    protected int comparePivot(int j) {
+      return comp.compare(pivot, list.get(j));
+    }
+
+  }
+
+  private static final class ListTimSorter<T> extends TimSorter {
+
+    final List<T> list;
+    final Comparator<? super T> comp;
+    final T[] tmp;
+
+    @SuppressWarnings("unchecked")
+    ListTimSorter(List<T> list, Comparator<? super T> comp, int maxTempSlots) {
+      super(maxTempSlots);
+      if (!(list instanceof RandomAccess))
+        throw new IllegalArgumentException("CollectionUtil can only sort random access lists in-place.");
+      this.list = list;
+      this.comp = comp;
+      if (maxTempSlots > 0) {
+        this.tmp = (T[]) new Object[maxTempSlots];
+      } else {
+        this.tmp = null;
+      }
+    }
+
+    @Override
+    protected void swap(int i, int j) {
+      Collections.swap(list, i, j);
+    }
+
+    @Override
+    protected void copy(int src, int dest) {
+      list.set(dest, list.get(src));
+    }
+
+    @Override
+    protected void save(int i, int len) {
+      for (int j = 0; j < len; ++j) {
+        tmp[j] = list.get(i + j);
+      }
+    }
+
+    @Override
+    protected void restore(int i, int j) {
+      list.set(j, tmp[i]);
+    }
+
+    @Override
+    protected int compare(int i, int j) {
+      return comp.compare(list.get(i), list.get(j));
+    }
+
+    @Override
+    protected int compareSaved(int i, int j) {
+      return comp.compare(tmp[i], list.get(j));
+    }
 
-  /**
-   * Sorts the given random access {@link List} using the {@link Comparator}.
-   * The list must implement {@link RandomAccess}. This method uses the quick sort
-   * algorithm, but falls back to insertion sort for small lists.
-   * @throws IllegalArgumentException if list is e.g. a linked list without random access.
-   */
-  public static <T> void quickSort(List<T> list, Comparator<? super T> comp) {
-    final int size = list.size();
-    if (size <= 1) return;
-    getSorter(list, comp).quickSort(0, size-1);
-  }
-  
-  /**
-   * Sorts the given random access {@link List} in natural order.
-   * The list must implement {@link RandomAccess}. This method uses the quick sort
-   * algorithm, but falls back to insertion sort for small lists.
-   * @throws IllegalArgumentException if list is e.g. a linked list without random access.
-   */
-  public static <T extends Comparable<? super T>> void quickSort(List<T> list) {
-    final int size = list.size();
-    if (size <= 1) return;
-    getSorter(list).quickSort(0, size-1);
   }
 
-  // mergeSorts:
-  
   /**
    * Sorts the given random access {@link List} using the {@link Comparator}.
-   * The list must implement {@link RandomAccess}. This method uses the merge sort
+   * The list must implement {@link RandomAccess}. This method uses the intro sort
    * algorithm, but falls back to insertion sort for small lists.
    * @throws IllegalArgumentException if list is e.g. a linked list without random access.
    */
-  public static <T> void mergeSort(List<T> list, Comparator<? super T> comp) {
+  public static <T> void introSort(List<T> list, Comparator<? super T> comp) {
     final int size = list.size();
     if (size <= 1) return;
-    getSorter(list, comp).mergeSort(0, size-1);
+    new ListIntroSorter<>(list, comp).sort(0, size);
   }
   
   /**
    * Sorts the given random access {@link List} in natural order.
-   * The list must implement {@link RandomAccess}. This method uses the merge sort
+   * The list must implement {@link RandomAccess}. This method uses the intro sort
    * algorithm, but falls back to insertion sort for small lists.
    * @throws IllegalArgumentException if list is e.g. a linked list without random access.
    */
-  public static <T extends Comparable<? super T>> void mergeSort(List<T> list) {
+  public static <T extends Comparable<? super T>> void introSort(List<T> list) {
     final int size = list.size();
     if (size <= 1) return;
-    getSorter(list).mergeSort(0, size-1);
+    introSort(list, ArrayUtil.<T>naturalComparator());
   }
 
-  // timSorts:
+  // Tim sorts:
   
   /**
    * Sorts the given random access {@link List} using the {@link Comparator}.
-   * The list must implement {@link RandomAccess}. This method uses the TimSort
+   * The list must implement {@link RandomAccess}. This method uses the Tim sort
    * algorithm, but falls back to binary sort for small lists.
    * @throws IllegalArgumentException if list is e.g. a linked list without random access.
    */
   public static <T> void timSort(List<T> list, Comparator<? super T> comp) {
     final int size = list.size();
     if (size <= 1) return;
-    getSorter(list, comp).timSort(0, size-1);
+    new ListTimSorter<>(list, comp, list.size() / 64).sort(0, size);
   }
   
   /**
    * Sorts the given random access {@link List} in natural order.
-   * The list must implement {@link RandomAccess}. This method uses the TimSort
+   * The list must implement {@link RandomAccess}. This method uses the Tim sort
    * algorithm, but falls back to binary sort for small lists.
    * @throws IllegalArgumentException if list is e.g. a linked list without random access.
    */
   public static <T extends Comparable<? super T>> void timSort(List<T> list) {
     final int size = list.size();
     if (size <= 1) return;
-    getSorter(list).timSort(0, size-1);
-  }
-
-  // insertionSorts:
-  
-  /**
-   * Sorts the given random access {@link List} using the {@link Comparator}.
-   * The list must implement {@link RandomAccess}. This method uses the insertion sort
-   * algorithm. It is only recommended to use this algorithm for partially sorted small lists!
-   * @throws IllegalArgumentException if list is e.g. a linked list without random access.
-   */
-  public static <T> void insertionSort(List<T> list, Comparator<? super T> comp) {
-    final int size = list.size();
-    if (size <= 1) return;
-    getSorter(list, comp).insertionSort(0, size-1);
-  }
-  
-  /**
-   * Sorts the given random access {@link List} in natural order.
-   * The list must implement {@link RandomAccess}. This method uses the insertion sort
-   * algorithm. It is only recommended to use this algorithm for partially sorted small lists!
-   * @throws IllegalArgumentException if list is e.g. a linked list without random access.
-   */
-  public static <T extends Comparable<? super T>> void insertionSort(List<T> list) {
-    final int size = list.size();
-    if (size <= 1) return;
-    getSorter(list).insertionSort(0, size-1);
+    timSort(list, ArrayUtil.<T>naturalComparator());
   }
 
-  // binarySorts:
-  
-  /**
-   * Sorts the given random access {@link List} using the {@link Comparator}.
-   * The list must implement {@link RandomAccess}. This method uses the binary sort
-   * algorithm. It is only recommended to use this algorithm for small lists!
-   * @throws IllegalArgumentException if list is e.g. a linked list without random access.
-   */
-  public static <T> void binarySort(List<T> list, Comparator<? super T> comp) {
-    final int size = list.size();
-    if (size <= 1) return;
-    getSorter(list, comp).binarySort(0, size-1);
-  }
-  
-  /**
-   * Sorts the given random access {@link List} in natural order.
-   * The list must implement {@link RandomAccess}. This method uses the insertion sort
-   * algorithm. It is only recommended to use this algorithm for small lists!
-   * @throws IllegalArgumentException if list is e.g. a linked list without random access.
-   */
-  public static <T extends Comparable<? super T>> void binarySort(List<T> list) {
-    final int size = list.size();
-    if (size <= 1) return;
-    getSorter(list).binarySort(0, size-1);
-  }
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/InfoStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/InfoStream.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/InfoStream.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/InfoStream.java Tue May  7 11:20:55 2013
@@ -30,7 +30,7 @@ import java.io.Closeable;
  * 
  * @lucene.internal 
  */
-public abstract class InfoStream implements Closeable {
+public abstract class InfoStream implements Closeable, Cloneable {
 
   /** Instance of InfoStream that does no logging at all. */
   public static final InfoStream NO_OUTPUT = new NoOutput();
@@ -74,5 +74,14 @@ public abstract class InfoStream impleme
     }
     defaultInfoStream = infoStream;
   }
-  
+
+  @Override
+  public InfoStream clone() {
+    try {
+      return (InfoStream) super.clone();
+    } catch (CloneNotSupportedException e) {
+      throw new Error(e);
+    }
+  }
+
 }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/MathUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/MathUtil.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/MathUtil.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/MathUtil.java Tue May  7 11:20:55 2013
@@ -17,10 +17,11 @@ package org.apache.lucene.util;
  * limitations under the License.
  */
 
+import java.math.BigInteger;
+
 /**
  * Math static utility methods.
  */
-
 public final class MathUtil {
 
   // No instance:
@@ -42,4 +43,39 @@ public final class MathUtil {
     }
     return ret;
   }
+
+  /** Return the greatest common divisor of <code>a</code> and <code>b</code>,
+   *  consistently with {@link BigInteger#gcd(BigInteger)}.
+   *  <p><b>NOTE</b>: A greatest common divisor must be positive, but
+   *  <code>2^64</code> cannot be expressed as a long although it
+   *  is the GCD of {@link Long#MIN_VALUE} and <code>0</code> and the GCD of
+   *  {@link Long#MIN_VALUE} and {@link Long#MIN_VALUE}. So in these 2 cases,
+   *  and only them, this method will return {@link Long#MIN_VALUE}. */
+  // see http://en.wikipedia.org/wiki/Binary_GCD_algorithm#Iterative_version_in_C.2B.2B_using_ctz_.28count_trailing_zeros.29
+  public static long gcd(long a, long b) {
+    a = Math.abs(a);
+    b = Math.abs(b);
+    if (a == 0) {
+      return b;
+    } else if (b == 0) {
+      return a;
+    }
+    final int commonTrailingZeros = Long.numberOfTrailingZeros(a | b);
+    a >>>= Long.numberOfTrailingZeros(a);
+    while (true) {
+      b >>>= Long.numberOfTrailingZeros(b);
+      if (a == b) {
+        break;
+      } else if (a > b || a == Long.MIN_VALUE) { // MIN_VALUE is treated as 2^64
+        final long tmp = a;
+        a = b;
+        b = tmp;
+      }
+      if (a == 1) {
+        break;
+      }
+      b -= a;
+    }
+    return a << commonTrailingZeros;
+  }
 }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/SentinelIntSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/SentinelIntSet.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/SentinelIntSet.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/SentinelIntSet.java Tue May  7 11:20:55 2013
@@ -20,26 +20,42 @@ package org.apache.lucene.util;
 import java.util.Arrays;
 
 /**
- * A native int set where one value is reserved to mean "EMPTY"
+ * A native int hash-based set where one value is reserved to mean "EMPTY" internally. The space overhead is fairly low
+ * as there is only one power-of-two sized int[] to hold the values.  The set is re-hashed when adding a value that
+ * would make it >= 75% full.  Consider extending and over-riding {@link #hash(int)} if the values might be poor
+ * hash keys; Lucene docids should be fine.
+ * The internal fields are exposed publicly to enable more efficient use at the expense of better O-O principles.
+ * <p/>
+ * To iterate over the integers held in this set, simply use code like this:
+ * <pre class="prettyprint">
+ * SentinelIntSet set = ...
+ * for (int v : set.keys) {
+ *   if (v == set.emptyVal)
+ *     continue;
+ *   //use v...
+ * }</pre>
  *
  * @lucene.internal
  */
 public class SentinelIntSet {
+  /** A power-of-2 over-sized array holding the integers in the set along with empty values. */
   public int[] keys;
   public int count;
   public final int emptyVal;
-  public int rehashCount;   // the count at which a rehash should be done
+  /** the count at which a rehash should be done */
+  public int rehashCount;
 
   /**
    *
-   * @param size  The minimum number of elements this set should be able to hold without re-hashing (i.e. the slots are guaranteed not to change)
+   * @param size  The minimum number of elements this set should be able to hold without rehashing
+   *              (i.e. the slots are guaranteed not to change)
    * @param emptyVal The integer value to use for EMPTY
    */
   public SentinelIntSet(int size, int emptyVal) {
     this.emptyVal = emptyVal;
     int tsize = Math.max(org.apache.lucene.util.BitUtil.nextHighestPowerOfTwo(size), 1);
     rehashCount = tsize - (tsize>>2);
-    if (size >= rehashCount) {  // should be able to hold "size" w/o rehashing
+    if (size >= rehashCount) {  // should be able to hold "size" w/o re-hashing
       tsize <<= 1;
       rehashCount = tsize - (tsize>>2);
     }
@@ -53,13 +69,17 @@ public class SentinelIntSet {
     count = 0;
   }
 
+  /** (internal) Return the hash for the key. The default implementation just returns the key,
+   * which is not appropriate for general purpose use.
+   */
   public int hash(int key) {
     return key;
   }
 
+  /** The number of integers in this set. */
   public int size() { return count; }
 
-  /** returns the slot for this key */
+  /** (internal) Returns the slot for this key */
   public int getSlot(int key) {
     assert key != emptyVal;
     int h = hash(key);
@@ -73,7 +93,7 @@ public class SentinelIntSet {
     return s;
   }
 
-  /** returns the slot for this key, or -slot-1 if not found */
+  /** (internal) Returns the slot for this key, or -slot-1 if not found */
   public int find(int key) {
     assert key != emptyVal;
     int h = hash(key);
@@ -89,10 +109,13 @@ public class SentinelIntSet {
     }
   }
 
+  /** Does this set contain the specified integer? */
   public boolean exists(int key) {
     return find(key) >= 0;
   }
 
+  /** Puts this integer (key) in the set, and returns the slot index it was added to.
+   * It rehashes if adding it would make the set more than 75% full. */
   public int put(int key) {
     int s = find(key);
     if (s < 0) {
@@ -108,14 +131,14 @@ public class SentinelIntSet {
     return s;
   }
 
+  /** (internal) Rehashes by doubling {@code int[] key} and filling with the old values. */
   public void rehash() {
     int newSize = keys.length << 1;
     int[] oldKeys = keys;
     keys = new int[newSize];
     if (emptyVal != 0) Arrays.fill(keys, emptyVal);
 
-    for (int i=0; i<oldKeys.length; i++) {
-      int key = oldKeys[i];
+    for (int key : oldKeys) {
       if (key == emptyVal) continue;
       int newSlot = getSlot(key);
       keys[newSlot] = key;

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.java Tue May  7 11:20:55 2013
@@ -395,43 +395,77 @@ public final class UnicodeUtil {
 
   /* Map UTF-8 encoded prefix byte to sequence length.  -1 (0xFF)
    * means illegal prefix.  see RFC 2279 for details */
-  static byte[] utf8CodeLength = new byte[] {
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
-    4, 4, 4, 4, 4, 4, 4, 4 //, 5, 5, 5, 5, 6, 6, 0, 0
-  };
-
-
-  /** Returns the number of code points in this utf8
-   *  sequence.  Behavior is undefined if the utf8 sequence
-   *  is invalid.*/
+  static final int [] utf8CodeLength;
+  static {
+    final int v = Integer.MIN_VALUE;
+    utf8CodeLength = new int [] {
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
+        v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
+        v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
+        v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
+        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+        4, 4, 4, 4, 4, 4, 4, 4 //, 5, 5, 5, 5, 6, 6, 0, 0
+      };
+  }
+
+  /** 
+   * Returns the number of code points in this UTF8 sequence.
+   * 
+   * <p>This method assumes valid UTF8 input. This method 
+   * <strong>does not perform</strong> full UTF8 validation, it will check only the 
+   * first byte of each codepoint (for multi-byte sequences any bytes after 
+   * the head are skipped).  
+   * 
+   * @throws IllegalArgumentException If invalid codepoint header byte occurs or the 
+   *    content is prematurely truncated.
+   */
   public static int codePointCount(BytesRef utf8) {
-    int upto = utf8.offset;
-    final int limit = utf8.offset + utf8.length;
+    int pos = utf8.offset;
+    final int limit = pos + utf8.length;
     final byte[] bytes = utf8.bytes;
+
     int codePointCount = 0;
-    while (upto < limit) {
-      codePointCount++;
-      upto += utf8CodeLength[bytes[upto]&0xFF];
+    for (; pos < limit; codePointCount++) {
+      int v = bytes[pos] & 0xFF;
+      if (v <   /* 0xxx xxxx */ 0x80) { pos += 1; continue; }
+      if (v >=  /* 110x xxxx */ 0xc0) {
+        if (v < /* 111x xxxx */ 0xe0) { pos += 2; continue; } 
+        if (v < /* 1111 xxxx */ 0xf0) { pos += 3; continue; } 
+        if (v < /* 1111 1xxx */ 0xf8) { pos += 4; continue; }
+        // fallthrough, consider 5 and 6 byte sequences invalid. 
+      }
+
+      // Anything not covered above is invalid UTF8.
+      throw new IllegalArgumentException();
     }
+
+    // Check if we didn't go over the limit on the last character.
+    if (pos > limit) throw new IllegalArgumentException();
+
     return codePointCount;
   }
 
-  // TODO: broken if incoming result.offset != 0
+  /**
+   * <p>This method assumes valid UTF8 input. This method 
+   * <strong>does not perform</strong> full UTF8 validation, it will check only the 
+   * first byte of each codepoint (for multi-byte sequences any bytes after 
+   * the head are skipped).  
+   * 
+   * @throws IllegalArgumentException If invalid codepoint header byte occurs or the 
+   *    content is prematurely truncated.
+   */
   public static void UTF8toUTF32(final BytesRef utf8, final IntsRef utf32) {
+    // TODO: broken if incoming result.offset != 0
     // pre-alloc for worst case
     // TODO: ints cannot be null, should be an assert
     if (utf32.ints == null || utf32.ints.length < utf8.length) {
@@ -443,7 +477,7 @@ public final class UnicodeUtil {
     final byte[] bytes = utf8.bytes;
     final int utf8Limit = utf8.offset + utf8.length;
     while(utf8Upto < utf8Limit) {
-      final int numBytes = utf8CodeLength[bytes[utf8Upto]&0xFF];
+      final int numBytes = utf8CodeLength[bytes[utf8Upto] & 0xFF];
       int v = 0;
       switch(numBytes) {
       case 1:
@@ -462,11 +496,11 @@ public final class UnicodeUtil {
         v = bytes[utf8Upto++] & 7;
         break;
       default :
-        throw new IllegalStateException("invalid utf8");
+        throw new IllegalArgumentException("invalid utf8");
       }
 
+      // TODO: this may read past utf8's limit.
       final int limit = utf8Upto + numBytes-1;
-
       while(utf8Upto < limit) {
         v = v << 6 | bytes[utf8Upto++]&63;
       }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/Version.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/Version.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/Version.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/Version.java Tue May  7 11:20:55 2013
@@ -61,6 +61,13 @@ public enum Version { 
   @Deprecated
   LUCENE_43,
 
+  /**
+   * Match settings and bugs in Lucene's 4.4 release.
+   * @deprecated (5.0) Use latest
+   */
+  @Deprecated
+  LUCENE_44,
+
   /** Match settings and bugs in Lucene's 5.0 release.
    *  <p>
    *  Use this to get the latest &amp; greatest settings, bug

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java Tue May  7 11:20:55 2013
@@ -63,7 +63,7 @@ public final class VirtualMethod<C> {
   private final Class<C> baseClass;
   private final String method;
   private final Class<?>[] parameters;
-  private final WeakIdentityMap<Class<? extends C>, Integer> cache = WeakIdentityMap.newConcurrentHashMap();
+  private final WeakIdentityMap<Class<? extends C>, Integer> cache = WeakIdentityMap.newConcurrentHashMap(false);
 
   /**
    * Creates a new instance for the given {@code baseClass} and method declaration.

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/WeakIdentityMap.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/WeakIdentityMap.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/WeakIdentityMap.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/WeakIdentityMap.java Tue May  7 11:20:55 2013
@@ -44,25 +44,65 @@ import java.util.concurrent.ConcurrentHa
  * if not implemented carefully. The map only contains {@link Iterator} implementations
  * on the values and not-GCed keys. Lucene's implementation also supports {@code null}
  * keys, but those are never weak!
+ * 
+ * <p><a name="reapInfo" />The map supports two modes of operation:
+ * <ul>
+ *  <li>{@code reapOnRead = true}: This behaves identical to a {@link java.util.WeakHashMap}
+ *  where it also cleans up the reference queue on every read operation ({@link #get(Object)},
+ *  {@link #containsKey(Object)}, {@link #size()}, {@link #valueIterator()}), freeing map entries
+ *  of already GCed keys.</li>
+ *  <li>{@code reapOnRead = false}: This mode does not call {@link #reap()} on every read
+ *  operation. In this case, the reference queue is only cleaned up on write operations
+ *  (like {@link #put(Object, Object)}). This is ideal for maps with few entries where
+ *  the keys are unlikely be garbage collected, but there are lots of {@link #get(Object)}
+ *  operations. The code can still call {@link #reap()} to manually clean up the queue without
+ *  doing a write operation.</li>
+ * </ul>
  *
  * @lucene.internal
  */
 public final class WeakIdentityMap<K,V> {
   private final ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
   private final Map<IdentityWeakReference, V> backingStore;
+  private final boolean reapOnRead;
 
-  /** Creates a new {@code WeakIdentityMap} based on a non-synchronized {@link HashMap}. */
-  public static final <K,V> WeakIdentityMap<K,V> newHashMap() {
-    return new WeakIdentityMap<K,V>(new HashMap<IdentityWeakReference,V>());
+
+  /** 
+   * Creates a new {@code WeakIdentityMap} based on a non-synchronized {@link HashMap}.
+   * The map <a href="#reapInfo">cleans up the reference queue on every read operation</a>.
+   */
+  public static <K,V> WeakIdentityMap<K,V> newHashMap() {
+    return newHashMap(true);
+  }
+
+  /**
+   * Creates a new {@code WeakIdentityMap} based on a non-synchronized {@link HashMap}.
+   * @param reapOnRead controls if the map <a href="#reapInfo">cleans up the reference queue on every read operation</a>.
+   */
+  public static <K,V> WeakIdentityMap<K,V> newHashMap(boolean reapOnRead) {
+    return new WeakIdentityMap<K,V>(new HashMap<IdentityWeakReference,V>(), reapOnRead);
+  }
+
+  /**
+   * Creates a new {@code WeakIdentityMap} based on a {@link ConcurrentHashMap}.
+   * The map <a href="#reapInfo">cleans up the reference queue on every read operation</a>.
+   */
+  public static <K,V> WeakIdentityMap<K,V> newConcurrentHashMap() {
+    return newConcurrentHashMap(true);
   }
 
-  /** Creates a new {@code WeakIdentityMap} based on a {@link ConcurrentHashMap}. */
-  public static final <K,V> WeakIdentityMap<K,V> newConcurrentHashMap() {
-    return new WeakIdentityMap<K,V>(new ConcurrentHashMap<IdentityWeakReference,V>());
+  /**
+   * Creates a new {@code WeakIdentityMap} based on a {@link ConcurrentHashMap}.
+   * @param reapOnRead controls if the map <a href="#reapInfo">cleans up the reference queue on every read operation</a>.
+   */
+  public static <K,V> WeakIdentityMap<K,V> newConcurrentHashMap(boolean reapOnRead) {
+    return new WeakIdentityMap<K,V>(new ConcurrentHashMap<IdentityWeakReference,V>(), reapOnRead);
   }
 
-  private WeakIdentityMap(Map<IdentityWeakReference, V> backingStore) {
+  /** Private only constructor, to create use the static factory methods. */
+  private WeakIdentityMap(Map<IdentityWeakReference, V> backingStore, boolean reapOnRead) {
     this.backingStore = backingStore;
+    this.reapOnRead = reapOnRead;
   }
 
   /** Removes all of the mappings from this map. */
@@ -73,13 +113,13 @@ public final class WeakIdentityMap<K,V> 
 
   /** Returns {@code true} if this map contains a mapping for the specified key. */
   public boolean containsKey(Object key) {
-    reap();
+    if (reapOnRead) reap();
     return backingStore.containsKey(new IdentityWeakReference(key, null));
   }
 
   /** Returns the value to which the specified key is mapped. */
   public V get(Object key) {
-    reap();
+    if (reapOnRead) reap();
     return backingStore.get(new IdentityWeakReference(key, null));
   }
 
@@ -113,7 +153,7 @@ public final class WeakIdentityMap<K,V> 
   public int size() {
     if (backingStore.isEmpty())
       return 0;
-    reap();
+    if (reapOnRead) reap();
     return backingStore.size();
   }
   
@@ -178,13 +218,21 @@ public final class WeakIdentityMap<K,V> 
   
   /** Returns an iterator over all values of this map.
    * This iterator may return values whose key is already
-   * garbage collected while iterator is consumed. */
+   * garbage collected while iterator is consumed,
+   * especially if {@code reapOnRead} is {@code false}. */
   public Iterator<V> valueIterator() {
-    reap();
+    if (reapOnRead) reap();
     return backingStore.values().iterator();
   }
 
-  private void reap() {
+  /**
+   * This method manually cleans up the reference queue to remove all garbage
+   * collected key/value pairs from the map. Calling this method is not needed
+   * if {@code reapOnRead = true}. Otherwise it might be a good idea
+   * to call this method when there is spare time (e.g. from a background thread).
+   * @see <a href="#reapInfo">Information about the <code>reapOnRead</code> setting</a>
+   */
+  public void reap() {
     Reference<?> zombie;
     while ((zombie = queue.poll()) != null) {
       backingStore.remove(zombie);

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/BasicOperations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/BasicOperations.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/BasicOperations.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/BasicOperations.java Tue May  7 11:20:55 2013
@@ -557,8 +557,8 @@ final public class BasicOperations {
     }
 
     public void sort() {
-      // mergesort seems to perform better on already sorted arrays:
-      if (count > 1) ArrayUtil.mergeSort(points, 0, count);
+      // Tim sort performs well on already sorted arrays:
+      if (count > 1) ArrayUtil.timSort(points, 0, count);
     }
 
     public void add(Transition t) {

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/State.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/State.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/State.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/automaton/State.java Tue May  7 11:20:55 2013
@@ -239,7 +239,7 @@ public class State implements Comparable
   /** Sorts transitions array in-place. */
   public void sortTransitions(Comparator<Transition> comparator) {
     // mergesort seems to perform better on already sorted arrays:
-    if (numTransitions > 1) ArrayUtil.mergeSort(transitionsArray, 0, numTransitions, comparator);
+    if (numTransitions > 1) ArrayUtil.timSort(transitionsArray, 0, numTransitions, comparator);
   }
   
   /**

Modified: lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/fst/NoOutputs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/fst/NoOutputs.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/fst/NoOutputs.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/java/org/apache/lucene/util/fst/NoOutputs.java Tue May  7 11:20:55 2013
@@ -74,6 +74,13 @@ public final class NoOutputs extends Out
   }
 
   @Override
+  public Object merge(Object first, Object second) {
+    assert first == NO_OUTPUT;
+    assert second == NO_OUTPUT;
+    return NO_OUTPUT;
+  }
+
+  @Override
   public void write(Object prefix, DataOutput out) {
     //assert false;
   }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestDemo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestDemo.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestDemo.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestDemo.java Tue May  7 11:20:55 2013
@@ -57,7 +57,7 @@ public class TestDemo extends LuceneTest
     
     // Now search the index:
     IndexReader ireader = DirectoryReader.open(directory); // read-only=true
-    IndexSearcher isearcher = new IndexSearcher(ireader);
+    IndexSearcher isearcher = newSearcher(ireader);
 
     assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
     Query query = new TermQuery(new Term("fieldname", "text"));

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearch.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearch.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearch.java Tue May  7 11:20:55 2013
@@ -55,7 +55,7 @@ public class TestSearch extends LuceneTe
       
       IndexReader reader = DirectoryReader.open(directory);
       try {
-        IndexSearcher searcher = new IndexSearcher(reader);
+        IndexSearcher searcher = newSearcher(reader);
         
         ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
         assertEquals(1, hits.length);
@@ -136,7 +136,7 @@ public class TestSearch extends LuceneTe
       writer.close();
 
       IndexReader reader = DirectoryReader.open(directory);
-      IndexSearcher searcher = new IndexSearcher(reader);
+      IndexSearcher searcher = newSearcher(reader);
 
       ScoreDoc[] hits = null;
 

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java Tue May  7 11:20:55 2013
@@ -90,7 +90,7 @@ public class TestSearchForDuplicates ext
 
       // try a search without OR
       IndexReader reader = DirectoryReader.open(directory);
-      IndexSearcher searcher = new IndexSearcher(reader);
+      IndexSearcher searcher = newSearcher(reader);
 
       Query query = new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY));
       out.println("Query: " + query.toString(PRIORITY_FIELD));
@@ -106,7 +106,7 @@ public class TestSearchForDuplicates ext
       checkHits(hits, MAX_DOCS, searcher);
 
       // try a new search with OR
-      searcher = new IndexSearcher(reader);
+      searcher = newSearcher(reader);
       hits = null;
 
       BooleanQuery booleanQuery = new BooleanQuery();

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.java Tue May  7 11:20:55 2013
@@ -319,7 +319,7 @@ public class TestGraphTokenizers extends
         };
       
       Random random = random();
-      checkRandomData(random, a, 5, atLeast(1000));
+      checkRandomData(random, a, 5, atLeast(100));
     }
   }
 
@@ -344,7 +344,7 @@ public class TestGraphTokenizers extends
         };
       
       Random random = random();
-      checkRandomData(random, a, 5, atLeast(1000));
+      checkRandomData(random, a, 5, atLeast(100));
     }
   }
 
@@ -368,7 +368,7 @@ public class TestGraphTokenizers extends
         };
       
       Random random = random();
-      checkRandomData(random, a, 5, atLeast(1000));
+      checkRandomData(random, a, 5, atLeast(100));
     }
   }
 
@@ -392,7 +392,7 @@ public class TestGraphTokenizers extends
         };
       
       Random random = random();
-      checkRandomData(random, a, 5, atLeast(1000));
+      checkRandomData(random, a, 5, atLeast(100));
     }
   }
 

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java Tue May  7 11:20:55 2013
@@ -64,16 +64,10 @@ public class TestMockAnalyzer extends Ba
   
   /** Test a configuration that behaves a lot like StopAnalyzer */
   public void testStop() throws Exception {
-    Analyzer a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);
+    Analyzer a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET);
     assertAnalyzesTo(a, "the quick brown a fox",
         new String[] { "quick", "brown", "fox" },
         new int[] { 2, 1, 2 });
-    
-    // disable positions
-    a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, false);
-    assertAnalyzesTo(a, "the quick brown a fox",
-        new String[] { "quick", "brown", "fox" },
-        new int[] { 1, 1, 1 });
   }
   
   /** Test a configuration that behaves a lot like KeepWordFilter */
@@ -83,7 +77,7 @@ public class TestMockAnalyzer extends Ba
           BasicOperations.complement(
               Automaton.union(
                   Arrays.asList(BasicAutomata.makeString("foo"), BasicAutomata.makeString("bar")))));
-    Analyzer a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, keepWords, true);
+    Analyzer a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, keepWords);
     assertAnalyzesTo(a, "quick foo brown bar bar fox foo",
         new String[] { "foo", "bar", "bar", "foo" },
         new int[] { 2, 2, 1, 2 });
@@ -92,7 +86,7 @@ public class TestMockAnalyzer extends Ba
   /** Test a configuration that behaves a lot like LengthFilter */
   public void testLength() throws Exception {
     CharacterRunAutomaton length5 = new CharacterRunAutomaton(new RegExp(".{5,}").toAutomaton());
-    Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, length5, true);
+    Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, length5);
     assertAnalyzesTo(a, "ok toolong fine notfine",
         new String[] { "ok", "fine" },
         new int[] { 1, 2 });

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat3.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat3.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat3.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat3.java Tue May  7 11:20:55 2013
@@ -394,8 +394,8 @@ public class TestBlockPostingsFormat3 ex
       assertNull(rightDocs);
       return;
     }
-    assertTrue(leftDocs.docID() == -1 || leftDocs.docID() == DocIdSetIterator.NO_MORE_DOCS);
-    assertTrue(rightDocs.docID() == -1 || rightDocs.docID() == DocIdSetIterator.NO_MORE_DOCS);
+    assertEquals(-1, leftDocs.docID());
+    assertEquals(-1, rightDocs.docID());
     int docid;
     while ((docid = leftDocs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
       assertEquals(docid, rightDocs.nextDoc());
@@ -417,8 +417,8 @@ public class TestBlockPostingsFormat3 ex
       assertNull(rightDocs);
       return;
     }
-    assertTrue(leftDocs.docID() == -1 || leftDocs.docID() == DocIdSetIterator.NO_MORE_DOCS);
-    assertTrue(rightDocs.docID() == -1 || rightDocs.docID() == DocIdSetIterator.NO_MORE_DOCS);
+    assertEquals(-1, leftDocs.docID());
+    assertEquals(-1, rightDocs.docID());
     int docid;
     while ((docid = leftDocs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
       assertEquals(docid, rightDocs.nextDoc());

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene42/TestLucene42DocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene42/TestLucene42DocValuesFormat.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene42/TestLucene42DocValuesFormat.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/lucene42/TestLucene42DocValuesFormat.java Tue May  7 11:20:55 2013
@@ -18,12 +18,12 @@ package org.apache.lucene.codecs.lucene4
  */
 
 import org.apache.lucene.codecs.Codec;
-import org.apache.lucene.index.BaseDocValuesFormatTestCase;
+import org.apache.lucene.index.BaseCompressingDocValuesFormatTestCase;
 
 /**
  * Tests Lucene42DocValuesFormat
  */
-public class TestLucene42DocValuesFormat extends BaseDocValuesFormatTestCase {
+public class TestLucene42DocValuesFormat extends BaseCompressingDocValuesFormatTestCase {
   private final Codec codec = new Lucene42Codec();
 
   @Override

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldDocValuesFormat.java Tue May  7 11:20:55 2013
@@ -97,7 +97,7 @@ public class TestPerFieldDocValuesFormat
     
     // Now search the index:
     IndexReader ireader = DirectoryReader.open(directory); // read-only=true
-    IndexSearcher isearcher = new IndexSearcher(ireader);
+    IndexSearcher isearcher = newSearcher(ireader);
 
     assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
     Query query = new TermQuery(new Term("fieldname", "text"));

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java Tue May  7 11:20:55 2013
@@ -238,7 +238,7 @@ public class Test2BTerms extends LuceneT
 
   private void testSavedTerms(IndexReader r, List<BytesRef> terms) throws IOException {
     System.out.println("TEST: run " + terms.size() + " terms on reader=" + r);
-    IndexSearcher s = new IndexSearcher(r);
+    IndexSearcher s = newSearcher(r);
     Collections.shuffle(terms);
     TermsEnum termsEnum = MultiFields.getTerms(r, "field").iterator(null);
     boolean failed = false;

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Tue May  7 11:20:55 2013
@@ -362,7 +362,7 @@ public class TestBackwardsCompatibility 
     //Query query = parser.parse("handle:1");
 
     IndexReader reader = DirectoryReader.open(dir);
-    IndexSearcher searcher = new IndexSearcher(reader);
+    IndexSearcher searcher = newSearcher(reader);
 
     _TestUtil.checkIndex(dir);
     
@@ -522,7 +522,7 @@ public class TestBackwardsCompatibility 
 
     // make sure searching sees right # hits
     IndexReader reader = DirectoryReader.open(dir);
-    IndexSearcher searcher = new IndexSearcher(reader);
+    IndexSearcher searcher = newSearcher(reader);
     ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
     StoredDocument d = searcher.getIndexReader().document(hits[0].doc);
     assertEquals("wrong first document", "0", d.get("id"));
@@ -535,7 +535,7 @@ public class TestBackwardsCompatibility 
     writer.close();
 
     reader = DirectoryReader.open(dir);
-    searcher = new IndexSearcher(reader);
+    searcher = newSearcher(reader);
     hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
     assertEquals("wrong number of hits", 44, hits.length);
     d = searcher.doc(hits[0].doc);
@@ -547,7 +547,7 @@ public class TestBackwardsCompatibility 
   public void changeIndexNoAdds(Random random, Directory dir) throws IOException {
     // make sure searching sees right # hits
     DirectoryReader reader = DirectoryReader.open(dir);
-    IndexSearcher searcher = new IndexSearcher(reader);
+    IndexSearcher searcher = newSearcher(reader);
     ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
     assertEquals("wrong number of hits", 34, hits.length);
     StoredDocument d = searcher.doc(hits[0].doc);
@@ -560,7 +560,7 @@ public class TestBackwardsCompatibility 
     writer.close();
 
     reader = DirectoryReader.open(dir);
-    searcher = new IndexSearcher(reader);
+    searcher = newSearcher(reader);
     hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
     assertEquals("wrong number of hits", 34, hits.length);
     doTestHits(hits, 34, searcher.getIndexReader());
@@ -852,7 +852,7 @@ public class TestBackwardsCompatibility 
       
       Directory dir = oldIndexDirs.get(name);
       IndexReader reader = DirectoryReader.open(dir);
-      IndexSearcher searcher = new IndexSearcher(reader);
+      IndexSearcher searcher = newSearcher(reader);
       
       for (int id=10; id<15; id++) {
         ScoreDoc[] hits = searcher.search(NumericRangeQuery.newIntRange("trieInt", 4, Integer.valueOf(id), Integer.valueOf(id), true, true), 100).scoreDocs;

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestBinaryTerms.java Tue May  7 11:20:55 2013
@@ -69,4 +69,9 @@ public class TestBinaryTerms extends Luc
     ir.close();
     dir.close();
   }
+  
+  public void testToString() {
+    Term term = new Term("foo", new BytesRef(new byte[] { (byte) 0xff, (byte) 0xfe }));
+    assertEquals("foo:[ff fe]", term.toString());
+  }
 }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java Tue May  7 11:20:55 2013
@@ -365,7 +365,7 @@ public class TestConcurrentMergeSchedule
         w.deleteDocuments(new Term("id", ""+random().nextInt(i+1)));
       }
     }
-    assertTrue(((TrackingCMS) iwc.getMergeScheduler()).totMergedBytes != 0);
+    assertTrue(((TrackingCMS) w.w.getConfig().getMergeScheduler()).totMergedBytes != 0);
     w.close();
     d.close();
   }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java Tue May  7 11:20:55 2013
@@ -45,7 +45,10 @@ import org.apache.lucene.util._TestUtil;
 public class TestDeletionPolicy extends LuceneTestCase {
   
   private void verifyCommitOrder(List<? extends IndexCommit> commits) {
-    final IndexCommit firstCommit =  commits.get(0);
+    if (commits.isEmpty()) {
+      return;
+    }
+    final IndexCommit firstCommit = commits.get(0);
     long last = SegmentInfos.generationFromSegmentsFileName(firstCommit.getSegmentsFileName());
     assertEquals(last, firstCommit.getGeneration());
     for(int i=1;i<commits.size();i++) {
@@ -57,10 +60,15 @@ public class TestDeletionPolicy extends 
     }
   }
 
-  class KeepAllDeletionPolicy implements IndexDeletionPolicy {
+  class KeepAllDeletionPolicy extends IndexDeletionPolicy {
     int numOnInit;
     int numOnCommit;
     Directory dir;
+
+    KeepAllDeletionPolicy(Directory dir) {
+      this.dir = dir;
+    }
+
     @Override
     public void onInit(List<? extends IndexCommit> commits) throws IOException {
       verifyCommitOrder(commits);
@@ -75,13 +83,14 @@ public class TestDeletionPolicy extends 
       verifyCommitOrder(commits);
       numOnCommit++;
     }
+
   }
 
   /**
    * This is useful for adding to a big index when you know
    * readers are not using it.
    */
-  class KeepNoneOnInitDeletionPolicy implements IndexDeletionPolicy {
+  class KeepNoneOnInitDeletionPolicy extends IndexDeletionPolicy {
     int numOnInit;
     int numOnCommit;
     @Override
@@ -106,7 +115,7 @@ public class TestDeletionPolicy extends 
     }
   }
 
-  class KeepLastNDeletionPolicy implements IndexDeletionPolicy {
+  class KeepLastNDeletionPolicy extends IndexDeletionPolicy {
     int numOnInit;
     int numOnCommit;
     int numToKeep;
@@ -165,7 +174,7 @@ public class TestDeletionPolicy extends 
    * Delete a commit only when it has been obsoleted by N
    * seconds.
    */
-  class ExpirationTimeDeletionPolicy implements IndexDeletionPolicy {
+  class ExpirationTimeDeletionPolicy extends IndexDeletionPolicy {
 
     Directory dir;
     double expirationTimeSeconds;
@@ -178,6 +187,9 @@ public class TestDeletionPolicy extends 
 
     @Override
     public void onInit(List<? extends IndexCommit> commits) throws IOException {
+      if (commits.isEmpty()) {
+        return;
+      }
       verifyCommitOrder(commits);
       onCommit(commits);
     }
@@ -209,15 +221,15 @@ public class TestDeletionPolicy extends 
     final double SECONDS = 2.0;
 
     Directory dir = newDirectory();
-    ExpirationTimeDeletionPolicy policy = new ExpirationTimeDeletionPolicy(dir, SECONDS);
     IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
         new MockAnalyzer(random()))
-        .setIndexDeletionPolicy(policy);
+        .setIndexDeletionPolicy(new ExpirationTimeDeletionPolicy(dir, SECONDS));
     MergePolicy mp = conf.getMergePolicy();
     if (mp instanceof LogMergePolicy) {
       ((LogMergePolicy) mp).setUseCompoundFile(true);
     }
     IndexWriter writer = new IndexWriter(dir, conf);
+    ExpirationTimeDeletionPolicy policy = (ExpirationTimeDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
     Map<String,String> commitData = new HashMap<String,String>();
     commitData.put("commitTime", String.valueOf(System.currentTimeMillis()));
     writer.setCommitData(commitData);
@@ -238,6 +250,7 @@ public class TestDeletionPolicy extends 
         ((LogMergePolicy) mp).setUseCompoundFile(true);
       }
       writer = new IndexWriter(dir, conf);
+      policy = (ExpirationTimeDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
       for(int j=0;j<17;j++) {
         addDoc(writer);
       }
@@ -305,21 +318,19 @@ public class TestDeletionPolicy extends 
 
       boolean useCompoundFile = (pass % 2) != 0;
 
-      // Never deletes a commit
-      KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy();
-
       Directory dir = newDirectory();
-      policy.dir = dir;
 
       IndexWriterConfig conf = newIndexWriterConfig(
           TEST_VERSION_CURRENT, new MockAnalyzer(random()))
-          .setIndexDeletionPolicy(policy).setMaxBufferedDocs(10)
+          .setIndexDeletionPolicy(new KeepAllDeletionPolicy(dir))
+          .setMaxBufferedDocs(10)
           .setMergeScheduler(new SerialMergeScheduler());
       MergePolicy mp = conf.getMergePolicy();
       if (mp instanceof LogMergePolicy) {
         ((LogMergePolicy) mp).setUseCompoundFile(useCompoundFile);
       }
       IndexWriter writer = new IndexWriter(dir, conf);
+      KeepAllDeletionPolicy policy = (KeepAllDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
       for(int i=0;i<107;i++) {
         addDoc(writer);
       }
@@ -343,10 +354,12 @@ public class TestDeletionPolicy extends 
           System.out.println("TEST: open writer for forceMerge");
         }
         writer = new IndexWriter(dir, conf);
+        policy = (KeepAllDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
         writer.forceMerge(1);
         writer.close();
       }
-      assertEquals(needsMerging ? 1:0, policy.numOnInit);
+
+      assertEquals(needsMerging ? 2:1, policy.numOnInit);
 
       // If we are not auto committing then there should
       // be exactly 2 commits (one per close above):
@@ -397,19 +410,16 @@ public class TestDeletionPolicy extends 
    * then, opens a new IndexWriter on a previous commit
    * point. */
   public void testOpenPriorSnapshot() throws IOException {
-    // Never deletes a commit
-    KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy();
-
     Directory dir = newDirectory();
-    policy.dir = dir;
 
     IndexWriter writer = new IndexWriter(
         dir,
         newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).
-            setIndexDeletionPolicy(policy).
+            setIndexDeletionPolicy(new KeepAllDeletionPolicy(dir)).
             setMaxBufferedDocs(2).
             setMergePolicy(newLogMergePolicy(10))
     );
+    KeepAllDeletionPolicy policy = (KeepAllDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
     for(int i=0;i<10;i++) {
       addDoc(writer);
       if ((1+i)%2 == 0)
@@ -508,19 +518,19 @@ public class TestDeletionPolicy extends 
 
       boolean useCompoundFile = (pass % 2) != 0;
 
-      KeepNoneOnInitDeletionPolicy policy = new KeepNoneOnInitDeletionPolicy();
-
       Directory dir = newDirectory();
 
       IndexWriterConfig conf = newIndexWriterConfig(
           TEST_VERSION_CURRENT, new MockAnalyzer(random()))
-          .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
+          .setOpenMode(OpenMode.CREATE)
+          .setIndexDeletionPolicy(new KeepNoneOnInitDeletionPolicy())
           .setMaxBufferedDocs(10);
       MergePolicy mp = conf.getMergePolicy();
       if (mp instanceof LogMergePolicy) {
         ((LogMergePolicy) mp).setUseCompoundFile(useCompoundFile);
       }
       IndexWriter writer = new IndexWriter(dir, conf);
+      KeepNoneOnInitDeletionPolicy policy = (KeepNoneOnInitDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
       for(int i=0;i<107;i++) {
         addDoc(writer);
       }
@@ -533,10 +543,11 @@ public class TestDeletionPolicy extends 
         ((LogMergePolicy) mp).setUseCompoundFile(true);
       }
       writer = new IndexWriter(dir, conf);
+      policy = (KeepNoneOnInitDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
       writer.forceMerge(1);
       writer.close();
 
-      assertEquals(1, policy.numOnInit);
+      assertEquals(2, policy.numOnInit);
       // If we are not auto committing then there should
       // be exactly 2 commits (one per close above):
       assertEquals(2, policy.numOnCommit);
@@ -563,17 +574,18 @@ public class TestDeletionPolicy extends 
       Directory dir = newDirectory();
 
       KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
-
       for(int j=0;j<N+1;j++) {
         IndexWriterConfig conf = newIndexWriterConfig(
             TEST_VERSION_CURRENT, new MockAnalyzer(random()))
-            .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
+            .setOpenMode(OpenMode.CREATE)
+            .setIndexDeletionPolicy(policy)
             .setMaxBufferedDocs(10);
         MergePolicy mp = conf.getMergePolicy();
         if (mp instanceof LogMergePolicy) {
           ((LogMergePolicy) mp).setUseCompoundFile(useCompoundFile);
         }
         IndexWriter writer = new IndexWriter(dir, conf);
+        policy = (KeepLastNDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
         for(int i=0;i<17;i++) {
           addDoc(writer);
         }
@@ -582,7 +594,7 @@ public class TestDeletionPolicy extends 
       }
 
       assertTrue(policy.numDelete > 0);
-      assertEquals(N, policy.numOnInit);
+      assertEquals(N+1, policy.numOnInit);
       assertEquals(N+1, policy.numOnCommit);
 
       // Simplistic check: just verify only the past N segments_N's still
@@ -623,18 +635,18 @@ public class TestDeletionPolicy extends 
 
       boolean useCompoundFile = (pass % 2) != 0;
 
-      KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
-
       Directory dir = newDirectory();
       IndexWriterConfig conf = newIndexWriterConfig(
           TEST_VERSION_CURRENT, new MockAnalyzer(random()))
-          .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
+          .setOpenMode(OpenMode.CREATE)
+          .setIndexDeletionPolicy(new KeepLastNDeletionPolicy(N))
           .setMaxBufferedDocs(10);
       MergePolicy mp = conf.getMergePolicy();
       if (mp instanceof LogMergePolicy) {
         ((LogMergePolicy) mp).setUseCompoundFile(useCompoundFile);
       }
       IndexWriter writer = new IndexWriter(dir, conf);
+      KeepLastNDeletionPolicy policy = (KeepLastNDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
       writer.close();
       Term searchTerm = new Term("content", "aaa");        
       Query query = new TermQuery(searchTerm);
@@ -650,6 +662,7 @@ public class TestDeletionPolicy extends 
           ((LogMergePolicy) mp).setUseCompoundFile(useCompoundFile);
         }
         writer = new IndexWriter(dir, conf);
+        policy = (KeepLastNDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
         for(int j=0;j<17;j++) {
           addDocWithID(writer, i*(N+1)+j);
         }
@@ -659,6 +672,7 @@ public class TestDeletionPolicy extends 
           .setIndexDeletionPolicy(policy)
           .setMergePolicy(NoMergePolicy.COMPOUND_FILES);
         writer = new IndexWriter(dir, conf);
+        policy = (KeepLastNDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
         writer.deleteDocuments(new Term("id", "" + (i*(N+1)+3)));
         // this is a commit
         writer.close();
@@ -671,16 +685,17 @@ public class TestDeletionPolicy extends 
         writer = new IndexWriter(dir, newIndexWriterConfig(
             TEST_VERSION_CURRENT, new MockAnalyzer(random()))
             .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy));
+        policy = (KeepLastNDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
         // This will not commit: there are no changes
         // pending because we opened for "create":
         writer.close();
       }
 
-      assertEquals(3*(N+1), policy.numOnInit);
+      assertEquals(3*(N+1)+1, policy.numOnInit);
       assertEquals(3*(N+1)+1, policy.numOnCommit);
 
       IndexReader rwReader = DirectoryReader.open(dir);
-      IndexSearcher searcher = new IndexSearcher(rwReader);
+      IndexSearcher searcher = newSearcher(rwReader);
       ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
       assertEquals(0, hits.length);
 

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java Tue May  7 11:20:55 2013
@@ -893,18 +893,18 @@ public void testFilesOpenClose() throws 
   // LUCENE-2753
   public void testListCommits() throws Exception {
     Directory dir = newDirectory();
-    SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
-    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( 
-        TEST_VERSION_CURRENT, null).setIndexDeletionPolicy(sdp));
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, null)
+        .setIndexDeletionPolicy(new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy())));
+    SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
     writer.addDocument(new Document());
     writer.commit();
-    sdp.snapshot("c1");
+    sdp.snapshot();
     writer.addDocument(new Document());
     writer.commit();
-    sdp.snapshot("c2");
+    sdp.snapshot();
     writer.addDocument(new Document());
     writer.commit();
-    sdp.snapshot("c3");
+    sdp.snapshot();
     writer.close();
     long currentGen = 0;
     for (IndexCommit ic : DirectoryReader.listCommits(dir)) {
@@ -914,19 +914,6 @@ public void testFilesOpenClose() throws 
     dir.close();
   }
   
-  // LUCENE-2812
-  public void testIndexExists() throws Exception {
-    Directory dir = newDirectory();
-    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
-    writer.addDocument(new Document());
-    writer.prepareCommit();
-    assertFalse(DirectoryReader.indexExists(dir));
-    writer.commit();
-    writer.close();
-    assertTrue(DirectoryReader.indexExists(dir));
-    dir.close();
-  }
-  
   // Make sure totalTermFreq works correctly in the terms
   // dict cache
   public void testTotalTermFreqCached() throws Exception {
@@ -1149,4 +1136,12 @@ public void testFilesOpenClose() throws 
     dir.close();
   }
 
+  public void testIndexExistsOnNonExistentDirectory() throws Exception {
+    File tempDir = _TestUtil.getTempDir("testIndexExistsOnNonExistentDirectory");
+    tempDir.delete();
+    Directory dir = newFSDirectory(tempDir);
+    System.out.println("dir=" + dir);
+    assertFalse(DirectoryReader.indexExists(dir));
+    dir.close();
+  }
 }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java Tue May  7 11:20:55 2013
@@ -530,7 +530,7 @@ public class TestDirectoryReaderReopen e
     protected abstract void modifyIndex(int i) throws IOException;
   }
   
-  static class KeepAllCommits implements IndexDeletionPolicy {
+  static class KeepAllCommits extends IndexDeletionPolicy {
     @Override
     public void onInit(List<? extends IndexCommit> commits) {
     }
@@ -594,4 +594,28 @@ public class TestDirectoryReaderReopen e
     r.close();
     dir.close();
   }
+
+  public void testOpenIfChangedNRTToCommit() throws Exception {
+    Directory dir = newDirectory();
+
+    // Can't use RIW because it randomly commits:
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
+    Document doc = new Document();
+    doc.add(newStringField("field", "value", Field.Store.NO));
+    w.addDocument(doc);
+    w.commit();
+    List<IndexCommit> commits = DirectoryReader.listCommits(dir);
+    assertEquals(1, commits.size());
+    w.addDocument(doc);
+    DirectoryReader r = DirectoryReader.open(w, true);
+
+    assertEquals(2, r.numDocs());
+    IndexReader r2 = DirectoryReader.openIfChanged(r, commits.get(0));
+    assertNotNull(r2);
+    r.close();
+    assertEquals(1, r2.numDocs());
+    w.close();
+    r2.close();
+    dir.close();
+  }
 }

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDoc.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDoc.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDoc.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDoc.java Tue May  7 11:20:55 2013
@@ -25,6 +25,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -218,11 +219,10 @@ public class TestDoc extends LuceneTestC
       TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(si1.info.dir);
       final SegmentInfo si = new SegmentInfo(si1.info.dir, Constants.LUCENE_MAIN_VERSION, merged, -1, false, codec, null, null);
 
-      SegmentMerger merger = new SegmentMerger(si, InfoStream.getDefault(), trackingDir, IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL,
-                                               MergeState.CheckAbort.NONE, new FieldInfos.FieldNumbers(), context);
+      SegmentMerger merger = new SegmentMerger(Arrays.<AtomicReader>asList(r1, r2),
+          si, InfoStream.getDefault(), trackingDir, IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL,
+          MergeState.CheckAbort.NONE, new FieldInfos.FieldNumbers(), context);
 
-      merger.add(r1);
-      merger.add(r2);
       MergeState mergeState = merger.merge();
       r1.close();
       r2.close();

Modified: lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java?rev=1479862&r1=1479861&r2=1479862&view=diff
==============================================================================
--- lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java (original)
+++ lucene/dev/branches/lucene4258/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java Tue May  7 11:20:55 2013
@@ -336,7 +336,7 @@ public class TestDocsAndPositions extend
     AtomicReader r = getOnlySegmentReader(reader);
     DocsEnum disi = _TestUtil.docs(random(), r, "foo", new BytesRef("bar"), null, null, DocsEnum.FLAG_NONE);
     int docid = disi.docID();
-    assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
+    assertEquals(-1, docid);
     assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
     
     // now reuse and check again
@@ -344,7 +344,7 @@ public class TestDocsAndPositions extend
     assertTrue(te.seekExact(new BytesRef("bar"), true));
     disi = _TestUtil.docs(random(), te, null, disi, DocsEnum.FLAG_NONE);
     docid = disi.docID();
-    assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
+    assertEquals(-1, docid);
     assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
     writer.close();
     r.close();
@@ -361,7 +361,7 @@ public class TestDocsAndPositions extend
     AtomicReader r = getOnlySegmentReader(reader);
     DocsAndPositionsEnum disi = r.termPositionsEnum(new Term("foo", "bar"));
     int docid = disi.docID();
-    assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
+    assertEquals(-1, docid);
     assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
     
     // now reuse and check again
@@ -369,7 +369,7 @@ public class TestDocsAndPositions extend
     assertTrue(te.seekExact(new BytesRef("bar"), true));
     disi = te.docsAndPositions(null, disi);
     docid = disi.docID();
-    assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
+    assertEquals(-1, docid);
     assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
     writer.close();
     r.close();



Mime
View raw message