lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r827772 [5/6] - in /lucene/java/branches/flex_1458: ./ contrib/ contrib/instantiated/src/java/org/apache/lucene/store/instantiated/ contrib/misc/src/java/org/apache/lucene/queryParser/precedence/ contrib/queries/src/java/org/apache/lucene/s...
Date Tue, 20 Oct 2009 19:58:22 GMT
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PhraseQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PhraseQuery.java Tue Oct 20 19:58:18 2009
@@ -36,8 +36,8 @@
  */
 public class PhraseQuery extends Query {
   private String field;
-  private ArrayList terms = new ArrayList(4);
-  private ArrayList positions = new ArrayList(4);
+  private ArrayList<Term> terms = new ArrayList<Term>(4);
+  private ArrayList<Integer> positions = new ArrayList<Integer>(4);
   private int maxPosition = 0;
   private int slop = 0;
 
@@ -69,7 +69,7 @@
   public void add(Term term) {
     int position = 0;
     if(positions.size() > 0)
-        position = ((Integer) positions.get(positions.size()-1)).intValue() + 1;
+        position = positions.get(positions.size()-1).intValue() + 1;
 
     add(term, position);
   }
@@ -96,7 +96,7 @@
 
   /** Returns the set of terms in this phrase. */
   public Term[] getTerms() {
-    return (Term[])terms.toArray(new Term[0]);
+    return terms.toArray(new Term[0]);
   }
 
   /**
@@ -105,7 +105,7 @@
   public int[] getPositions() {
       int[] result = new int[positions.size()];
       for(int i = 0; i < positions.size(); i++)
-          result[i] = ((Integer) positions.get(i)).intValue();
+          result[i] = positions.get(i).intValue();
       return result;
   }
 
@@ -148,7 +148,7 @@
       DocsEnum[] docs = new DocsEnum[terms.size()];
       final Bits delDocs = reader.getDeletedDocs();
       for (int i = 0; i < terms.size(); i++) {
-        final Term t = (Term) terms.get(i);
+        final Term t = terms.get(i);
         DocsEnum docsEnum = reader.termDocsEnum(delDocs,
                                                 t.field(),
                                                 new TermRef(t.text()));
@@ -183,7 +183,7 @@
           query.append(" ");
         }
 
-        Term term = (Term)terms.get(i);
+        Term term = terms.get(i);
 
         query.append(term.text());
       }
@@ -249,7 +249,7 @@
 
   public Weight createWeight(Searcher searcher) throws IOException {
     if (terms.size() == 1) {			  // optimize one-term case
-      Term term = (Term)terms.get(0);
+      Term term = terms.get(0);
       Query termQuery = new TermQuery(term);
       termQuery.setBoost(getBoost());
       return termQuery.createWeight(searcher);
@@ -275,12 +275,12 @@
     buffer.append("\"");
     String[] pieces = new String[maxPosition + 1];
     for (int i = 0; i < terms.size(); i++) {
-      int pos = ((Integer)positions.get(i)).intValue();
+      int pos = positions.get(i).intValue();
       String s = pieces[pos];
       if (s == null) {
-        s = ((Term)terms.get(i)).text();
+        s = (terms.get(i)).text();
       } else {
-        s = s + "|" + ((Term)terms.get(i)).text();
+        s = s + "|" + (terms.get(i)).text();
       }
       pieces[pos] = s;
     }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PrefixFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PrefixFilter.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PrefixFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/PrefixFilter.java Tue Oct 20 19:58:18 2009
@@ -23,13 +23,13 @@
  * A Filter that restricts search results to values that have a matching prefix in a given
  * field.
  */
-public class PrefixFilter extends MultiTermQueryWrapperFilter {
+public class PrefixFilter extends MultiTermQueryWrapperFilter<PrefixQuery> {
 
   public PrefixFilter(Term prefix) {
     super(new PrefixQuery(prefix));
   }
 
-  public Term getPrefix() { return ((PrefixQuery)query).getPrefix(); }
+  public Term getPrefix() { return query.getPrefix(); }
 
   /** Prints a user-readable version of this query. */
   public String toString () {

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java Tue Oct 20 19:58:18 2009
@@ -20,7 +20,7 @@
 import java.io.IOException;
 
 import java.util.HashSet;
-import java.util.Iterator;
+
 import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;
@@ -126,7 +126,7 @@
    * the other queries.
   */
   public Query combine(Query[] queries) {
-    HashSet uniques = new HashSet();
+    HashSet<Query> uniques = new HashSet<Query>();
     for (int i = 0; i < queries.length; i++) {
       Query query = queries[i];
       BooleanClause[] clauses = null;
@@ -152,10 +152,9 @@
     if(uniques.size() == 1){
         return (Query)uniques.iterator().next();
     }
-    Iterator it = uniques.iterator();
     BooleanQuery result = new BooleanQuery(true);
-    while (it.hasNext())
-      result.add((Query) it.next(), BooleanClause.Occur.SHOULD);
+    for (final Query query : uniques)
+      result.add(query, BooleanClause.Occur.SHOULD);
     return result;
   }
   
@@ -179,20 +178,18 @@
    *<p>A utility for use by {@link #combine(Query[])} implementations.
    */
   public static Query mergeBooleanQueries(BooleanQuery[] queries) {
-    HashSet allClauses = new HashSet();
-    for (int i = 0; i < queries.length; i++) {
-      BooleanClause[] clauses = queries[i].getClauses();
-      for (int j = 0; j < clauses.length; j++) {
-        allClauses.add(clauses[j]);
+    HashSet<BooleanClause> allClauses = new HashSet<BooleanClause>();
+    for (BooleanQuery booleanQuery : queries) {
+      for (BooleanClause clause : booleanQuery) {
+        allClauses.add(clause);
       }
     }
 
     boolean coordDisabled =
       queries.length==0? false : queries[0].isCoordDisabled();
     BooleanQuery result = new BooleanQuery(coordDisabled);
-    Iterator i = allClauses.iterator();
-    while (i.hasNext()) {
-      result.add((BooleanClause)i.next());
+    for(BooleanClause clause2 : allClauses) {
+      result.add(clause2);
     }
     return result;
   }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryTermVector.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryTermVector.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryTermVector.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryTermVector.java Tue Oct 20 19:58:18 2009
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.Iterator;
+
 import java.util.List;
 import java.util.Map;
 
@@ -56,7 +56,7 @@
       TokenStream stream = analyzer.tokenStream("", new StringReader(queryString));
       if (stream != null)
       {
-        List terms = new ArrayList();
+        List<String> terms = new ArrayList<String>();
         try {
           boolean hasMoreTokens = false;
           
@@ -78,30 +78,29 @@
   private void processTerms(String[] queryTerms) {
     if (queryTerms != null) {
       Arrays.sort(queryTerms);
-      Map tmpSet = new HashMap(queryTerms.length);
+      Map<String,Integer> tmpSet = new HashMap<String,Integer>(queryTerms.length);
       //filter out duplicates
-      List tmpList = new ArrayList(queryTerms.length);
-      List tmpFreqs = new ArrayList(queryTerms.length);
+      List<String> tmpList = new ArrayList<String>(queryTerms.length);
+      List<Integer> tmpFreqs = new ArrayList<Integer>(queryTerms.length);
       int j = 0;
       for (int i = 0; i < queryTerms.length; i++) {
         String term = queryTerms[i];
-        Integer position = (Integer)tmpSet.get(term);
+        Integer position = tmpSet.get(term);
         if (position == null) {
           tmpSet.put(term, Integer.valueOf(j++));
           tmpList.add(term);
           tmpFreqs.add(Integer.valueOf(1));
         }       
         else {
-          Integer integer = (Integer)tmpFreqs.get(position.intValue());
+          Integer integer = tmpFreqs.get(position.intValue());
           tmpFreqs.set(position.intValue(), Integer.valueOf(integer.intValue() + 1));          
         }
       }
-      terms = (String[])tmpList.toArray(terms);
+      terms = tmpList.toArray(terms);
       //termFreqs = (int[])tmpFreqs.toArray(termFreqs);
       termFreqs = new int[tmpFreqs.size()];
       int i = 0;
-      for (Iterator iter = tmpFreqs.iterator(); iter.hasNext();) {
-        Integer integer = (Integer) iter.next();
+      for (final Integer integer : tmpFreqs) {
         termFreqs[i++] = integer.intValue();
       }
     }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Searchable.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Searchable.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Searchable.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Searchable.java Tue Oct 20 19:58:18 2009
@@ -18,6 +18,7 @@
  */
 
 import java.io.IOException;
+import java.io.Closeable;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.FieldSelector;
@@ -41,7 +42,7 @@
  * expected to be implemented directly, it may be changed unexpectedly between
  * releases.
  */
-public interface Searchable {
+public interface Searchable extends Closeable {
   
   /**
    * Lower-level search API.

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java Tue Oct 20 19:58:18 2009
@@ -27,7 +27,7 @@
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.IdentityHashMap;
-import java.util.Iterator;
+
 
 /** 
  * Expert: Scoring API.
@@ -787,11 +787,11 @@
    * @return idf score factor
    * @deprecated see {@link #idfExplain(Collection, Searcher)}
    */
-  public float idf(Collection terms, Searcher searcher) throws IOException {
+  public float idf(Collection<Term> terms, Searcher searcher) throws IOException {
     float idf = 0.0f;
-    Iterator i = terms.iterator();
-    while (i.hasNext()) {
-      idf += idf((Term)i.next(), searcher);
+
+    for(final Term term: terms) {
+      idf += idf(term, searcher);
     }
     return idf;
   }
@@ -810,7 +810,7 @@
    *         for each term.
    * @throws IOException
    */
-  public IDFExplanation idfExplain(Collection terms, Searcher searcher) throws IOException {
+  public IDFExplanation idfExplain(Collection<Term> terms, Searcher searcher) throws IOException {
     if(supportedMethods.overridesCollectionIDF) {
       final float idf = idf(terms, searcher);
       return new IDFExplanation() {
@@ -827,9 +827,7 @@
     final int max = searcher.maxDoc();
     float idf = 0.0f;
     final StringBuilder exp = new StringBuilder();
-    Iterator i = terms.iterator();
-    while (i.hasNext()) {
-      Term term = (Term)i.next();
+    for (final Term term : terms ) {
       final int df = searcher.docFreq(term);
       idf += idf(df, max);
       exp.append(" ");
@@ -955,7 +953,7 @@
   }
   
   /** @deprecated Remove this when old API is removed! */
-  private static final IdentityHashMap/*<Class<? extends Similarity>,MethodSupport>*/ knownMethodSupport = new IdentityHashMap();
+  private static final IdentityHashMap<Class<? extends Similarity>,MethodSupport> knownMethodSupport = new IdentityHashMap();
   
   /** @deprecated Remove this when old API is removed! */
   private static MethodSupport getSupportedMethods(Class clazz) {

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SloppyPhraseScorer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SloppyPhraseScorer.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SloppyPhraseScorer.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SloppyPhraseScorer.java Tue Oct 20 19:58:18 2009
@@ -146,14 +146,14 @@
         if (!checkedRepeats) {
             checkedRepeats = true;
             // check for repeats
-            HashMap m = null;
+            HashMap<PhrasePositions, Object> m = null;
             for (PhrasePositions pp = first; pp != null; pp = pp.next) {
                 int tpPos = pp.position + pp.offset;
                 for (PhrasePositions pp2 = pp.next; pp2 != null; pp2 = pp2.next) {
                     int tpPos2 = pp2.position + pp2.offset;
                     if (tpPos2 == tpPos) { 
                         if (m == null)
-                            m = new HashMap();
+                            m = new HashMap<PhrasePositions, Object>();
                         pp.repeats = true;
                         pp2.repeats = true;
                         m.put(pp,null);
@@ -162,7 +162,7 @@
                 }
             }
             if (m!=null)
-                repeats = (PhrasePositions[]) m.keySet().toArray(new PhrasePositions[0]);
+                repeats = m.keySet().toArray(new PhrasePositions[0]);
         }
         
         // with repeats must advance some repeating pp's so they all start with differing tp's       

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java Tue Oct 20 19:58:18 2009
@@ -16,7 +16,7 @@
  */
 
 import java.util.ArrayList;
-import java.util.BitSet;
+
 import java.util.List;
 
 
@@ -29,14 +29,14 @@
  **/
 public class SpanFilterResult {
   private DocIdSet docIdSet;
-  private List positions;//Spans spans;
+  private List<PositionInfo> positions;//Spans spans;
   
   /**
   *
   * @param docIdSet The DocIdSet for the Filter
   * @param positions A List of {@link org.apache.lucene.search.SpanFilterResult.PositionInfo} objects
   */
-  public SpanFilterResult(DocIdSet docIdSet, List positions) {
+  public SpanFilterResult(DocIdSet docIdSet, List<PositionInfo> positions) {
     this.docIdSet = docIdSet;
     this.positions = positions;
   }
@@ -46,7 +46,7 @@
    * Entries are increasing by document order
    * @return A List of PositionInfo objects
    */
-  public List getPositions() {
+  public List<PositionInfo> getPositions() {
     return positions;
   }
 
@@ -57,12 +57,12 @@
 
   public static class PositionInfo {
     private int doc;
-    private List positions;
+    private List<StartEnd> positions;
 
 
     public PositionInfo(int doc) {
       this.doc = doc;
-      positions = new ArrayList();
+      positions = new ArrayList<StartEnd>();
     }
 
     public void addPosition(int start, int end)
@@ -76,9 +76,9 @@
 
     /**
      *
-     * @return A List of {@link org.apache.lucene.search.SpanFilterResult.StartEnd} objects
+     * @return Positions
      */
-    public List getPositions() {
+    public List<StartEnd> getPositions() {
       return positions;
     }
   }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java Tue Oct 20 19:58:18 2009
@@ -63,7 +63,7 @@
 
     final OpenBitSet bits = new OpenBitSet(reader.maxDoc());
     Spans spans = query.getSpans(reader);
-    List tmp = new ArrayList(20);
+    List<SpanFilterResult.PositionInfo> tmp = new ArrayList<SpanFilterResult.PositionInfo>(20);
     int currentDoc = -1;
     SpanFilterResult.PositionInfo currentInfo = null;
     while (spans.next())

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TermRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TermRangeFilter.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TermRangeFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TermRangeFilter.java Tue Oct 20 19:58:18 2009
@@ -32,7 +32,7 @@
  * same field, {@link FieldCacheRangeFilter} may have significantly better performance. 
  * @since 2.9
  */
-public class TermRangeFilter extends MultiTermQueryWrapperFilter {
+public class TermRangeFilter extends MultiTermQueryWrapperFilter<TermRangeQuery> {
     
   /**
    * @param fieldName The field this range applies to
@@ -89,20 +89,20 @@
   }
 
   /** Returns the field name for this filter */
-  public String getField() { return ((TermRangeQuery) query).getField(); }
+  public String getField() { return query.getField(); }
   
   /** Returns the lower value of this range filter */
-  public String getLowerTerm() { return ((TermRangeQuery) query).getLowerTerm(); }
+  public String getLowerTerm() { return query.getLowerTerm(); }
 
   /** Returns the upper value of this range filter */
-  public String getUpperTerm() { return ((TermRangeQuery) query).getUpperTerm(); }
+  public String getUpperTerm() { return query.getUpperTerm(); }
   
   /** Returns <code>true</code> if the lower endpoint is inclusive */
-  public boolean includesLower() { return ((TermRangeQuery) query).includesLower(); }
+  public boolean includesLower() { return query.includesLower(); }
   
   /** Returns <code>true</code> if the upper endpoint is inclusive */
-  public boolean includesUpper() { return ((TermRangeQuery) query).includesUpper(); }
+  public boolean includesUpper() { return query.includesUpper(); }
 
   /** Returns the collator used to determine range inclusion, if any. */
-  public Collator getCollator() { return ((TermRangeQuery) query).getCollator(); }
+  public Collator getCollator() { return query.getCollator(); }
 }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopDocsCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopDocsCollector.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopDocsCollector.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopDocsCollector.java Tue Oct 20 19:58:18 2009
@@ -17,6 +17,7 @@
  * limitations under the License.
  */
 
+
 import org.apache.lucene.util.PriorityQueue;
 
 /**
@@ -27,7 +28,7 @@
  * Extending classes can override {@link #topDocs(int, int)} and
  * {@link #getTotalHits()} in order to provide their own implementation.
  */
-public abstract class TopDocsCollector extends Collector {
+public abstract class TopDocsCollector<T> extends Collector {
 
   // This is used in case topDocs() is called with illegal parameters, or there
   // simply aren't (enough) results.
@@ -39,12 +40,12 @@
    * HitQueue for example aggregates the top scoring documents, while other PQ
    * implementations may hold documents sorted by other criteria.
    */
-  protected PriorityQueue pq;
+  protected PriorityQueue<T> pq;
 
   /** The total number of documents that the collector encountered. */
   protected int totalHits;
   
-  protected TopDocsCollector(PriorityQueue pq) {
+  protected TopDocsCollector(PriorityQueue<T> pq) {
     this.pq = pq;
   }
   

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java Tue Oct 20 19:58:18 2009
@@ -33,7 +33,7 @@
  * <p><b>NOTE:</b> This API is experimental and might change in
  * incompatible ways in the next release.</p>
  */
-public abstract class TopFieldCollector extends TopDocsCollector {
+public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
   
   // TODO: one optimization we could do is to pre-fill
   // the queue with sentinel value that guaranteed to
@@ -60,7 +60,7 @@
     final void updateBottom(int doc) {
       // bottom.score is already set to Float.NaN in add().
       bottom.docID = docBase + doc;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -161,7 +161,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -273,7 +273,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom =  pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -380,7 +380,7 @@
     final void updateBottom(int doc) {
       // bottom.score is already set to Float.NaN in add().
       bottom.docID = docBase + doc;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -529,7 +529,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom =  pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -675,7 +675,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -833,7 +833,7 @@
   // internal versions. If someone will define a constructor with any other
   // visibility, then anyone will be able to extend the class, which is not what
   // we want.
-  private TopFieldCollector(PriorityQueue pq, int numHits, boolean fillFields) {
+  private TopFieldCollector(PriorityQueue<Entry> pq, int numHits, boolean fillFields) {
     super(pq);
     this.numHits = numHits;
     this.fillFields = fillFields;
@@ -925,7 +925,7 @@
   }
   
   final void add(int slot, int doc, float score) {
-    bottom = (Entry) pq.add(new Entry(slot, docBase + doc, score));
+    bottom = pq.add(new Entry(slot, docBase + doc, score));
     queueFull = totalHits == numHits;
   }
 
@@ -943,7 +943,7 @@
       }
     } else {
       for (int i = howMany - 1; i >= 0; i--) {
-        Entry entry = (Entry) pq.pop();
+        Entry entry = pq.pop();
         results[i] = new FieldDoc(entry.docID, entry.score);
       }
     }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java Tue Oct 20 19:58:18 2009
@@ -34,7 +34,7 @@
  * not valid scores.  This collector will not properly
  * collect hits with such scores.
  */
-public abstract class TopScoreDocCollector extends TopDocsCollector {
+public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
 
   // Assumes docs are scored in order.
   private static class InOrderTopScoreDocCollector extends TopScoreDocCollector {
@@ -53,7 +53,7 @@
       }
       pqTop.doc = doc + docBase;
       pqTop.score = score;
-      pqTop = (ScoreDoc) pq.updateTop();
+      pqTop = pq.updateTop();
     }
     
     public boolean acceptsDocsOutOfOrder() {
@@ -76,7 +76,7 @@
       }
       pqTop.doc = doc;
       pqTop.score = score;
-      pqTop = (ScoreDoc) pq.updateTop();
+      pqTop = pq.updateTop();
     }
     
     public boolean acceptsDocsOutOfOrder() {
@@ -113,7 +113,7 @@
     super(new HitQueue(numHits, true));
     // HitQueue implements getSentinelObject to return a ScoreDoc, so we know
     // that at this point top() is already initialized.
-    pqTop = (ScoreDoc) pq.top();
+    pqTop = pq.top();
   }
 
   protected TopDocs newTopDocs(ScoreDoc[] results, int start) {
@@ -130,7 +130,7 @@
       maxScore = results[0].score;
     } else {
       for (int i = pq.size(); i > 1; i--) { pq.pop(); }
-      maxScore = ((ScoreDoc) pq.pop()).score;
+      maxScore = pq.pop().score;
     }
     
     return new TopDocs(totalHits, results, maxScore);

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java Tue Oct 20 19:58:18 2009
@@ -75,8 +75,7 @@
     SpanQuery[] newClauses = new SpanQuery[sz];
 
     for (int i = 0; i < sz; i++) {
-      SpanQuery clause = (SpanQuery) clauses.get(i);
-      newClauses[i] = (SpanQuery) clause.clone();
+      newClauses[i] = (SpanQuery) clauses.get(i).clone();
     }
     PayloadNearQuery boostingNearQuery = new PayloadNearQuery(newClauses, slop,
         inOrder);
@@ -87,9 +86,9 @@
   public String toString(String field) {
     StringBuilder buffer = new StringBuilder();
     buffer.append("payloadNear([");
-    Iterator i = clauses.iterator();
+    Iterator<SpanQuery> i = clauses.iterator();
     while (i.hasNext()) {
-      SpanQuery clause = (SpanQuery) i.next();
+      SpanQuery clause = i.next();
       buffer.append(clause.toString(field));
       if (i.hasNext()) {
         buffer.append(", ");
@@ -195,9 +194,8 @@
      * 
      * @see Spans
      */
-    protected void processPayloads(Collection payLoads, int start, int end) {
-      for (Iterator iterator = payLoads.iterator(); iterator.hasNext();) {
-        byte[] thePayload = (byte[]) iterator.next();
+    protected void processPayloads(Collection<byte[]> payLoads, int start, int end) {
+      for (final byte[] thePayload : payLoads) {
         payloadScore = function.currentScore(doc, fieldName, start, end,
             payloadsSeen, payloadScore, similarity.scorePayload(doc, fieldName,
                 spans.start(), spans.end(), thePayload, 0, thePayload.length));
@@ -207,6 +205,9 @@
 
     //
     protected boolean setFreqCurrentDoc() throws IOException {
+      if (!more) {
+        return false;
+      }
       Spans[] spansArr = new Spans[1];
       spansArr[0] = spans;
       payloadScore = 0;

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java Tue Oct 20 19:58:18 2009
@@ -69,13 +69,13 @@
    * @return payloads Collection
    * @throws IOException
    */
-  public Collection getPayloadsForQuery(Query query) throws IOException {
-    Collection payloads = new ArrayList();
+  public Collection<byte[]> getPayloadsForQuery(Query query) throws IOException {
+    Collection<byte[]> payloads = new ArrayList<byte[]>();
     queryToSpanQuery(query, payloads);
     return payloads;
   }
 
-  private void queryToSpanQuery(Query query, Collection payloads)
+  private void queryToSpanQuery(Query query, Collection<byte[]> payloads)
       throws IOException {
     if (query instanceof BooleanQuery) {
       BooleanClause[] queryClauses = ((BooleanQuery) query).getClauses();
@@ -113,14 +113,14 @@
       queryToSpanQuery(((FilteredQuery) query).getQuery(), payloads);
     } else if (query instanceof DisjunctionMaxQuery) {
 
-      for (Iterator iterator = ((DisjunctionMaxQuery) query).iterator(); iterator
+      for (Iterator<Query> iterator = ((DisjunctionMaxQuery) query).iterator(); iterator
           .hasNext();) {
-        queryToSpanQuery((Query) iterator.next(), payloads);
+        queryToSpanQuery(iterator.next(), payloads);
       }
 
     } else if (query instanceof MultiPhraseQuery) {
       final MultiPhraseQuery mpq = (MultiPhraseQuery) query;
-      final List termArrays = mpq.getTermArrays();
+      final List<Term[]> termArrays = mpq.getTermArrays();
       final int[] positions = mpq.getPositions();
       if (positions.length > 0) {
 
@@ -131,19 +131,19 @@
           }
         }
 
-        final List[] disjunctLists = new List[maxPosition + 1];
+        final List<Query>[] disjunctLists = new List[maxPosition + 1];
         int distinctPositions = 0;
 
         for (int i = 0; i < termArrays.size(); ++i) {
-          final Term[] termArray = (Term[]) termArrays.get(i);
-          List disjuncts = disjunctLists[positions[i]];
+          final Term[] termArray = termArrays.get(i);
+          List<Query> disjuncts = disjunctLists[positions[i]];
           if (disjuncts == null) {
-            disjuncts = (disjunctLists[positions[i]] = new ArrayList(
+            disjuncts = (disjunctLists[positions[i]] = new ArrayList<Query>(
                 termArray.length));
             ++distinctPositions;
           }
-          for (int j = 0; j < termArray.length; ++j) {
-            disjuncts.add(new SpanTermQuery(termArray[j]));
+          for (final Term term : termArray) {
+            disjuncts.add(new SpanTermQuery(term));
           }
         }
 
@@ -151,9 +151,9 @@
         int position = 0;
         final SpanQuery[] clauses = new SpanQuery[distinctPositions];
         for (int i = 0; i < disjunctLists.length; ++i) {
-          List disjuncts = disjunctLists[i];
+          List<Query> disjuncts = disjunctLists[i];
           if (disjuncts != null) {
-            clauses[position++] = new SpanOrQuery((SpanQuery[]) disjuncts
+            clauses[position++] = new SpanOrQuery(disjuncts
                 .toArray(new SpanQuery[disjuncts.size()]));
           } else {
             ++positionGaps;
@@ -171,16 +171,14 @@
     }
   }
 
-  private void getPayloads(Collection payloads, SpanQuery query)
+  private void getPayloads(Collection<byte []> payloads, SpanQuery query)
       throws IOException {
     Spans spans = query.getSpans(reader);
 
     while (spans.next() == true) {
       if (spans.isPayloadAvailable()) {
-        Collection payload = spans.getPayload();
-        Iterator it = payload.iterator();
-        while (it.hasNext()) {
-          byte[] bytes = (byte[]) it.next();
+        Collection<byte[]> payload = spans.getPayload();
+        for (byte [] bytes : payload) {
           payloads.add(bytes);
         }
 

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java Tue Oct 20 19:58:18 2009
@@ -18,7 +18,6 @@
  */
 
 import java.io.IOException;
-import java.util.Collection;
 import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java Tue Oct 20 19:58:18 2009
@@ -65,12 +65,12 @@
   private int matchDoc = -1;
   private int matchStart = -1;
   private int matchEnd = -1;
-  private List/*<byte[]>*/ matchPayload;
+  private List<byte[]> matchPayload;
 
   private final Spans[] subSpansByDoc;
-  private final Comparator spanDocComparator = new Comparator() {
-    public int compare(Object o1, Object o2) {
-      return ((Spans)o1).doc() - ((Spans)o2).doc();
+  private final Comparator<Spans> spanDocComparator = new Comparator<Spans>() {
+    public int compare(Spans o1, Spans o2) {
+      return o1.doc() - o2.doc();
     }
   };
   
@@ -91,7 +91,7 @@
     allowedSlop = spanNearQuery.getSlop();
     SpanQuery[] clauses = spanNearQuery.getClauses();
     subSpans = new Spans[clauses.length];
-    matchPayload = new LinkedList();
+    matchPayload = new LinkedList<byte[]>();
     subSpansByDoc = new Spans[clauses.length];
     for (int i = 0; i < clauses.length; i++) {
       subSpans[i] = clauses[i].getSpans(reader);
@@ -115,7 +115,7 @@
 
   // TODO: Remove warning after API has been finalized
   // TODO: Would be nice to be able to lazy load payloads
-  public Collection/*<byte[]>*/ getPayload() throws IOException {
+  public Collection<byte[]> getPayload() throws IOException {
     return matchPayload;
   }
 
@@ -256,12 +256,12 @@
   private boolean shrinkToAfterShortestMatch() throws IOException {
     matchStart = subSpans[subSpans.length - 1].start();
     matchEnd = subSpans[subSpans.length - 1].end();
-    Set possibleMatchPayloads = new HashSet();
+    Set<byte[]> possibleMatchPayloads = new HashSet<byte[]>();
     if (subSpans[subSpans.length - 1].isPayloadAvailable()) {
       possibleMatchPayloads.addAll(subSpans[subSpans.length - 1].getPayload());
     }
 
-    Collection possiblePayload = null;
+    Collection<byte[]> possiblePayload = null;
     
     int matchSlop = 0;
     int lastStart = matchStart;
@@ -269,8 +269,8 @@
     for (int i = subSpans.length - 2; i >= 0; i--) {
       Spans prevSpans = subSpans[i];
       if (collectPayloads && prevSpans.isPayloadAvailable()) {
-        Collection payload = prevSpans.getPayload();
-        possiblePayload = new ArrayList(payload.size());
+        Collection<byte[]> payload = prevSpans.getPayload();
+        possiblePayload = new ArrayList<byte[]>(payload.size());
         possiblePayload.addAll(payload);
       }
       
@@ -293,8 +293,8 @@
             prevStart = ppStart;
             prevEnd = ppEnd;
             if (collectPayloads && prevSpans.isPayloadAvailable()) {
-              Collection payload = prevSpans.getPayload();
-              possiblePayload = new ArrayList(payload.size());
+              Collection<byte[]> payload = prevSpans.getPayload();
+              possiblePayload = new ArrayList<byte[]>(payload.size());
               possiblePayload.addAll(payload);
             }
           }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java Tue Oct 20 19:58:18 2009
@@ -36,7 +36,7 @@
 public class NearSpansUnordered extends Spans {
   private SpanNearQuery query;
 
-  private List ordered = new ArrayList();         // spans in query order
+  private List<SpansCell> ordered = new ArrayList<SpansCell>();         // spans in query order
   private Spans[] subSpans;  
   private int slop;                               // from query
 
@@ -107,8 +107,8 @@
     public int start() { return spans.start(); }
     public int end() { return spans.end(); }
                     // TODO: Remove warning after API has been finalized
-    public Collection/*<byte[]>*/ getPayload() throws IOException {
-      return new ArrayList(spans.getPayload());
+    public Collection<byte[]> getPayload() throws IOException {
+      return new ArrayList<byte[]>(spans.getPayload());
     }
 
     // TODO: Remove warning after API has been finalized
@@ -223,8 +223,8 @@
    * @return Collection of <code>byte[]</code> payloads
    * @throws IOException
    */
-  public Collection/*<byte[]>*/ getPayload() throws IOException {
-    Set/*<byte[]*/ matchPayload = new HashSet();
+  public Collection<byte[]> getPayload() throws IOException {
+    Set<byte[]> matchPayload = new HashSet<byte[]>();
     for (SpansCell cell = first; cell != null; cell = cell.next) {
       if (cell.isPayloadAvailable()) {
         matchPayload.addAll(cell.getPayload());
@@ -253,7 +253,7 @@
 
   private void initList(boolean next) throws IOException {
     for (int i = 0; more && i < ordered.size(); i++) {
-      SpansCell cell = (SpansCell)ordered.get(i);
+      SpansCell cell = ordered.get(i);
       if (next)
         more = cell.next();                       // move to first entry
       if (more) {

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java Tue Oct 20 19:58:18 2009
@@ -94,10 +94,10 @@
         public int end() { return spans.end(); }
 
       // TODO: Remove warning after API has been finalized
-      public Collection/*<byte[]>*/ getPayload() throws IOException {
-        ArrayList result = null;
+      public Collection<byte[]> getPayload() throws IOException {
+        ArrayList<byte[]> result = null;
         if (spans.isPayloadAvailable()) {
-          result = new ArrayList(spans.getPayload());
+          result = new ArrayList<byte[]>(spans.getPayload());
         }
         return result;//TODO: any way to avoid the new construction?
       }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Tue Oct 20 19:58:18 2009
@@ -19,7 +19,7 @@
 
 import java.io.IOException;
 
-import java.util.Collection;
+
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -35,7 +35,7 @@
  * maximum number of intervening unmatched positions, as well as whether
  * matches are required to be in-order. */
 public class SpanNearQuery extends SpanQuery implements Cloneable {
-  protected List clauses;
+  protected List<SpanQuery> clauses;
   protected int slop;
   protected boolean inOrder;
 
@@ -53,7 +53,7 @@
   public SpanNearQuery(SpanQuery[] clauses, int slop, boolean inOrder, boolean collectPayloads) {
 
     // copy clauses array into an ArrayList
-    this.clauses = new ArrayList(clauses.length);
+    this.clauses = new ArrayList<SpanQuery>(clauses.length);
     for (int i = 0; i < clauses.length; i++) {
       SpanQuery clause = clauses[i];
       if (i == 0) {                               // check field
@@ -70,7 +70,7 @@
 
   /** Return the clauses whose spans are matched. */
   public SpanQuery[] getClauses() {
-    return (SpanQuery[])clauses.toArray(new SpanQuery[clauses.size()]);
+    return clauses.toArray(new SpanQuery[clauses.size()]);
   }
 
   /** Return the maximum number of intervening unmatched positions permitted.*/
@@ -82,9 +82,7 @@
   public String getField() { return field; }
   
   public void extractTerms(Set<Term> terms) {
-	    Iterator i = clauses.iterator();
-	    while (i.hasNext()) {
-	      SpanQuery clause = (SpanQuery)i.next();
+	    for (final SpanQuery clause : clauses) {
 	      clause.extractTerms(terms);
 	    }
   }  
@@ -93,9 +91,9 @@
   public String toString(String field) {
     StringBuilder buffer = new StringBuilder();
     buffer.append("spanNear([");
-    Iterator i = clauses.iterator();
+    Iterator<SpanQuery> i = clauses.iterator();
     while (i.hasNext()) {
-      SpanQuery clause = (SpanQuery)i.next();
+      SpanQuery clause = i.next();
       buffer.append(clause.toString(field));
       if (i.hasNext()) {
         buffer.append(", ");
@@ -115,7 +113,7 @@
       return new SpanOrQuery(getClauses()).getSpans(reader);
 
     if (clauses.size() == 1)                      // optimize 1-clause case
-      return ((SpanQuery)clauses.get(0)).getSpans(reader);
+      return clauses.get(0).getSpans(reader);
 
     return inOrder
             ? (Spans) new NearSpansOrdered(this, reader, collectPayloads)
@@ -125,7 +123,7 @@
   public Query rewrite(IndexReader reader) throws IOException {
     SpanNearQuery clone = null;
     for (int i = 0 ; i < clauses.size(); i++) {
-      SpanQuery c = (SpanQuery)clauses.get(i);
+      SpanQuery c = clauses.get(i);
       SpanQuery query = (SpanQuery) c.rewrite(reader);
       if (query != c) {                     // clause rewrote: must clone
         if (clone == null)
@@ -145,8 +143,7 @@
     SpanQuery[] newClauses = new SpanQuery[sz];
 
     for (int i = 0; i < sz; i++) {
-      SpanQuery clause = (SpanQuery) clauses.get(i);
-      newClauses[i] = (SpanQuery) clause.clone();
+      newClauses[i] = (SpanQuery) clauses.get(i).clone();
     }
     SpanNearQuery spanNearQuery = new SpanNearQuery(newClauses, slop, inOrder);
     spanNearQuery.setBoost(getBoost());

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNotQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanNotQuery.java Tue Oct 20 19:58:18 2009
@@ -132,10 +132,10 @@
         public int end() { return includeSpans.end(); }
 
       // TODO: Remove warning after API has been finalized
-      public Collection/*<byte[]>*/ getPayload() throws IOException {
-        ArrayList result = null;
+      public Collection<byte[]> getPayload() throws IOException {
+        ArrayList<byte[]> result = null;
         if (includeSpans.isPayloadAvailable()) {
-          result = new ArrayList(includeSpans.getPayload());
+          result = new ArrayList<byte[]>(includeSpans.getPayload());
         }
         return result;
       }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanOrQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanOrQuery.java Tue Oct 20 19:58:18 2009
@@ -33,14 +33,14 @@
 
 /** Matches the union of its clauses.*/
 public class SpanOrQuery extends SpanQuery implements Cloneable {
-  private List clauses;
+  private List<SpanQuery> clauses;
   private String field;
 
   /** Construct a SpanOrQuery merging the provided clauses. */
   public SpanOrQuery(SpanQuery[] clauses) {
 
     // copy clauses array into an ArrayList
-    this.clauses = new ArrayList(clauses.length);
+    this.clauses = new ArrayList<SpanQuery>(clauses.length);
     for (int i = 0; i < clauses.length; i++) {
       SpanQuery clause = clauses[i];
       if (i == 0) {                               // check field
@@ -60,9 +60,7 @@
   public String getField() { return field; }
 
   public void extractTerms(Set<Term> terms) {
-    Iterator i = clauses.iterator();
-    while (i.hasNext()) {
-      SpanQuery clause = (SpanQuery)i.next();
+    for(final SpanQuery clause: clauses) {
       clause.extractTerms(terms);
     }
   }
@@ -72,8 +70,7 @@
     SpanQuery[] newClauses = new SpanQuery[sz];
 
     for (int i = 0; i < sz; i++) {
-      SpanQuery clause = (SpanQuery) clauses.get(i);
-      newClauses[i] = (SpanQuery) clause.clone();
+      newClauses[i] = (SpanQuery) clauses.get(i).clone();
     }
     SpanOrQuery soq = new SpanOrQuery(newClauses);
     soq.setBoost(getBoost());
@@ -83,7 +80,7 @@
   public Query rewrite(IndexReader reader) throws IOException {
     SpanOrQuery clone = null;
     for (int i = 0 ; i < clauses.size(); i++) {
-      SpanQuery c = (SpanQuery)clauses.get(i);
+      SpanQuery c = clauses.get(i);
       SpanQuery query = (SpanQuery) c.rewrite(reader);
       if (query != c) {                     // clause rewrote: must clone
         if (clone == null)
@@ -101,9 +98,9 @@
   public String toString(String field) {
     StringBuilder buffer = new StringBuilder();
     buffer.append("spanOr([");
-    Iterator i = clauses.iterator();
+    Iterator<SpanQuery> i = clauses.iterator();
     while (i.hasNext()) {
-      SpanQuery clause = (SpanQuery)i.next();
+      SpanQuery clause = i.next();
       buffer.append(clause.toString(field));
       if (i.hasNext()) {
         buffer.append(", ");
@@ -134,14 +131,12 @@
   }
 
 
-  private class SpanQueue extends PriorityQueue {
+  private class SpanQueue extends PriorityQueue<Spans> {
     public SpanQueue(int size) {
       initialize(size);
     }
 
-    protected final boolean lessThan(Object o1, Object o2) {
-      Spans spans1 = (Spans)o1;
-      Spans spans2 = (Spans)o2;
+    protected final boolean lessThan(Spans spans1, Spans spans2) {
       if (spans1.doc() == spans2.doc()) {
         if (spans1.start() == spans2.start()) {
           return spans1.end() < spans2.end();
@@ -163,9 +158,9 @@
 
         private boolean initSpanQueue(int target) throws IOException {
           queue = new SpanQueue(clauses.size());
-          Iterator i = clauses.iterator();
+          Iterator<SpanQuery> i = clauses.iterator();
           while (i.hasNext()) {
-            Spans spans = ((SpanQuery)i.next()).getSpans(reader);
+            Spans spans = i.next().getSpans(reader);
             if (   ((target == -1) && spans.next())
                 || ((target != -1) && spans.skipTo(target))) {
               queue.add(spans);
@@ -219,11 +214,11 @@
         public int start() { return top().start(); }
         public int end() { return top().end(); }
 
-      public Collection/*<byte[]>*/ getPayload() throws IOException {
-        ArrayList result = null;
+      public Collection<byte[]> getPayload() throws IOException {
+        ArrayList<byte[]> result = null;
         Spans theTop = top();
         if (theTop != null && theTop.isPayloadAvailable()) {
-          result = new ArrayList(theTop.getPayload());
+          result = new ArrayList<byte[]>(theTop.getPayload());
         }
         return result;
       }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanQuery.java Tue Oct 20 19:58:18 2009
@@ -18,8 +18,6 @@
  */
 
 import java.io.IOException;
-import java.util.Collection;
-import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.Query;

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanTermQuery.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanTermQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanTermQuery.java Tue Oct 20 19:58:18 2009
@@ -23,8 +23,6 @@
 import org.apache.lucene.util.ToStringUtils;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Set;
 
 /** Matches spans containing a term. */

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanWeight.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanWeight.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanWeight.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/SpanWeight.java Tue Oct 20 19:58:18 2009
@@ -18,6 +18,7 @@
  */
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.*;
 import org.apache.lucene.search.Explanation.IDFExplanation;
 
@@ -35,7 +36,7 @@
   protected float queryNorm;
   protected float queryWeight;
 
-  protected Set terms;
+  protected Set<Term> terms;
   protected SpanQuery query;
   private IDFExplanation idfExp;
 
@@ -43,8 +44,10 @@
     throws IOException {
     this.similarity = query.getSimilarity(searcher);
     this.query = query;
-    terms=new HashSet();
+    
+    terms=new HashSet<Term>();
     query.extractTerms(terms);
+    
     idfExp = similarity.idfExplain(terms, searcher);
     idf = idfExp.getIdf();
   }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java Tue Oct 20 19:58:18 2009
@@ -75,7 +75,7 @@
    * @throws java.io.IOException
     */
   // TODO: Remove warning after API has been finalized
-  public abstract Collection/*<byte[]>*/ getPayload() throws IOException;
+  public abstract Collection<byte[]> getPayload() throws IOException;
 
   /**
    * Checks if a payload can be loaded at this position.

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/TermSpans.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/TermSpans.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/TermSpans.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/TermSpans.java Tue Oct 20 19:58:18 2009
@@ -87,7 +87,7 @@
   }
 
   // TODO: Remove warning after API has been finalized
-  public Collection/*<byte[]>*/ getPayload() throws IOException {
+  public Collection<byte[]> getPayload() throws IOException {
     byte [] bytes = new byte[positions.getPayloadLength()]; 
     bytes = positions.getPayload(bytes, 0);
     return Collections.singletonList(bytes);

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/Directory.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/Directory.java Tue Oct 20 19:58:18 2009
@@ -18,6 +18,7 @@
  */
 
 import java.io.IOException;
+import java.io.Closeable;
 
 /** A Directory is a flat list of files.  Files may be written once, when they
  * are created.  Once a file is created it may only be opened for read, or
@@ -35,7 +36,7 @@
  * instance using {@link #setLockFactory}.
  *
  */
-public abstract class Directory {
+public abstract class Directory implements Closeable {
 
   volatile protected boolean isOpen = true;
 

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FSDirectory.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FSDirectory.java Tue Oct 20 19:58:18 2009
@@ -19,14 +19,10 @@
 
 import java.io.File;
 import java.io.FilenameFilter;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.lucene.util.Constants;
 

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java Tue Oct 20 19:58:18 2009
@@ -37,10 +37,10 @@
 public class FileSwitchDirectory extends Directory {
   private final Directory secondaryDir;
   private final Directory primaryDir;
-  private final Set primaryExtensions;
+  private final Set<String> primaryExtensions;
   private boolean doClose;
 
-  public FileSwitchDirectory(Set primaryExtensions, Directory primaryDir, Directory secondaryDir, boolean doClose) {
+  public FileSwitchDirectory(Set<String> primaryExtensions, Directory primaryDir, Directory secondaryDir, boolean doClose) {
     this.primaryExtensions = primaryExtensions;
     this.primaryDir = primaryDir;
     this.secondaryDir = secondaryDir;

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java Tue Oct 20 19:58:18 2009
@@ -18,6 +18,7 @@
  */
 
 import java.io.IOException;
+import java.io.Closeable;
 import java.util.Map;
 import java.util.HashMap;
 
@@ -25,7 +26,7 @@
  * random-access input stream.  Used for all Lucene index input operations.
  * @see Directory
  */
-public abstract class IndexInput implements Cloneable {
+public abstract class IndexInput implements Cloneable,Closeable {
   private byte[] bytes;                           // used by readString()
   private char[] chars;                           // used by readModifiedUTF8String()
   private boolean preUTF8Strings;                 // true if we are reading old (modified UTF8) string format

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexOutput.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexOutput.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexOutput.java Tue Oct 20 19:58:18 2009
@@ -18,8 +18,8 @@
  */
 
 import java.io.IOException;
+import java.io.Closeable;
 import java.util.Map;
-import java.util.Iterator;
 import org.apache.lucene.util.UnicodeUtil;
 
 /** Abstract base class for output to a file in a Directory.  A random-access
@@ -27,7 +27,7 @@
  * @see Directory
  * @see IndexInput
  */
-public abstract class IndexOutput {
+public abstract class IndexOutput implements Closeable {
 
   private UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result();
 
@@ -210,17 +210,14 @@
    */
   public void setLength(long length) throws IOException {};
 
-  // map must be Map<String, String>
-  public void writeStringStringMap(Map map) throws IOException {
+  public void writeStringStringMap(Map<String,String> map) throws IOException {
     if (map == null) {
       writeInt(0);
     } else {
       writeInt(map.size());
-      final Iterator it = map.entrySet().iterator();
-      while(it.hasNext()) {
-        Map.Entry entry = (Map.Entry) it.next();
-        writeString((String) entry.getKey());
-        writeString((String) entry.getValue());
+      for(final Map.Entry<String, String> entry: map.entrySet()) {
+        writeString(entry.getKey());
+        writeString(entry.getValue());
       }
     }
   }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/MMapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/MMapDirectory.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/MMapDirectory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/MMapDirectory.java Tue Oct 20 19:58:18 2009
@@ -148,7 +148,7 @@
   final void cleanMapping(final ByteBuffer buffer) throws IOException {
     if (useUnmapHack) {
       try {
-        AccessController.doPrivileged(new PrivilegedExceptionAction() {
+        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
           public Object run() throws Exception {
             final Method getCleanerMethod = buffer.getClass()
               .getMethod("cleaner", NO_PARAM_TYPES);

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java Tue Oct 20 19:58:18 2009
@@ -164,7 +164,7 @@
    * one JVM (each with their own NativeFSLockFactory
    * instance) have set the same lock dir and lock prefix.
    */
-  private static HashSet LOCK_HELD = new HashSet();
+  private static HashSet<String> LOCK_HELD = new HashSet<String>();
 
   public NativeFSLock(File lockDir, String lockFileName) {
     this.lockDir = lockDir;

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMDirectory.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMDirectory.java Tue Oct 20 19:58:18 2009
@@ -21,7 +21,6 @@
 import java.io.FileNotFoundException;
 import java.io.Serializable;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Set;
 
 /**
@@ -33,7 +32,7 @@
 
   private static final long serialVersionUID = 1l;
 
-  HashMap fileMap = new HashMap();
+  HashMap<String,RAMFile> fileMap = new HashMap<String,RAMFile>();
   long sizeInBytes = 0;
   
   // *****
@@ -72,12 +71,11 @@
 
   public synchronized final String[] listAll() {
     ensureOpen();
-    Set fileNames = fileMap.keySet();
+    Set<String> fileNames = fileMap.keySet();
     String[] result = new String[fileNames.size()];
     int i = 0;
-    Iterator it = fileNames.iterator();
-    while (it.hasNext())
-      result[i++] = (String)it.next();
+    for(final String fileName: fileNames) 
+      result[i++] = fileName;
     return result;
   }
 
@@ -86,7 +84,7 @@
     ensureOpen();
     RAMFile file;
     synchronized (this) {
-      file = (RAMFile)fileMap.get(name);
+      file = fileMap.get(name);
     }
     return file != null;
   }
@@ -98,7 +96,7 @@
     ensureOpen();
     RAMFile file;
     synchronized (this) {
-      file = (RAMFile)fileMap.get(name);
+      file = fileMap.get(name);
     }
     if (file==null)
       throw new FileNotFoundException(name);
@@ -112,7 +110,7 @@
     ensureOpen();
     RAMFile file;
     synchronized (this) {
-      file = (RAMFile)fileMap.get(name);
+      file = fileMap.get(name);
     }
     if (file==null)
       throw new FileNotFoundException(name);
@@ -140,7 +138,7 @@
     ensureOpen();
     RAMFile file;
     synchronized (this) {
-      file = (RAMFile)fileMap.get(name);
+      file = fileMap.get(name);
     }
     if (file==null)
       throw new FileNotFoundException(name);
@@ -160,7 +158,7 @@
    */
   public synchronized void deleteFile(String name) throws IOException {
     ensureOpen();
-    RAMFile file = (RAMFile)fileMap.get(name);
+    RAMFile file = fileMap.get(name);
     if (file!=null) {
         fileMap.remove(name);
         file.directory = null;
@@ -174,7 +172,7 @@
     ensureOpen();
     RAMFile file = new RAMFile(this);
     synchronized (this) {
-      RAMFile existing = (RAMFile)fileMap.get(name);
+      RAMFile existing = fileMap.get(name);
       if (existing!=null) {
         sizeInBytes -= existing.sizeInBytes;
         existing.directory = null;
@@ -189,7 +187,7 @@
     ensureOpen();
     RAMFile file;
     synchronized (this) {
-      file = (RAMFile)fileMap.get(name);
+      file = fileMap.get(name);
     }
     if (file == null)
       // nocommit

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMFile.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMFile.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMFile.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/RAMFile.java Tue Oct 20 19:58:18 2009
@@ -24,7 +24,7 @@
 
   private static final long serialVersionUID = 1l;
 
-  private ArrayList buffers = new ArrayList();
+  private ArrayList<byte[]> buffers = new ArrayList<byte[]>();
   long length;
   RAMDirectory directory;
   long sizeInBytes;                  // Only maintained if in a directory; updates synchronized on directory

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/SingleInstanceLockFactory.java Tue Oct 20 19:58:18 2009
@@ -33,7 +33,7 @@
 
 public class SingleInstanceLockFactory extends LockFactory {
 
-  private HashSet locks = new HashSet();
+  private HashSet<String> locks = new HashSet<String>();
 
   public Lock makeLock(String lockName) {
     // We do not use the LockPrefix at all, because the private
@@ -54,9 +54,9 @@
 class SingleInstanceLock extends Lock {
 
   String lockName;
-  private HashSet locks;
+  private HashSet<String> locks;
 
-  public SingleInstanceLock(HashSet locks, String lockName) {
+  public SingleInstanceLock(HashSet<String> locks, String lockName) {
     this.locks = locks;
     this.lockName = lockName;
   }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/AverageGuessMemoryModel.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/AverageGuessMemoryModel.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/AverageGuessMemoryModel.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/AverageGuessMemoryModel.java Tue Oct 20 19:58:18 2009
@@ -26,7 +26,7 @@
  */
 public class AverageGuessMemoryModel extends MemoryModel {
   // best guess primitive sizes
-  private final Map sizes = new IdentityHashMap() {
+  private final Map<Class,Integer> sizes = new IdentityHashMap<Class,Integer>() {
     {
       put(boolean.class, Integer.valueOf(1));
       put(byte.class, Integer.valueOf(1));
@@ -61,7 +61,7 @@
    * @see org.apache.lucene.util.MemoryModel#getPrimitiveSize(java.lang.Class)
    */
   public int getPrimitiveSize(Class clazz) {
-    return ((Integer) sizes.get(clazz)).intValue();
+    return sizes.get(clazz).intValue();
   }
 
   /* (non-Javadoc)

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/CloseableThreadLocal.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/CloseableThreadLocal.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/CloseableThreadLocal.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/CloseableThreadLocal.java Tue Oct 20 19:58:18 2009
@@ -21,6 +21,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.lang.ref.WeakReference;
+import java.io.Closeable;
 
 /** Java's builtin ThreadLocal has a serious flaw:
  *  it can take an arbitrarily long amount of time to
@@ -42,20 +43,20 @@
  *  references are cleared and then GC is freely able to
  *  reclaim space by objects stored in it. */
 
-public class CloseableThreadLocal {
+public class CloseableThreadLocal<T> implements Closeable {
 
-  private ThreadLocal t = new ThreadLocal();
+  private ThreadLocal<WeakReference<T>> t = new ThreadLocal<WeakReference<T>>();
 
-  private Map hardRefs = new HashMap();
+  private Map<Thread,T> hardRefs = new HashMap<Thread,T>();
   
-  protected Object initialValue() {
+  protected T initialValue() {
     return null;
   }
   
-  public Object get() {
-    WeakReference weakRef = (WeakReference) t.get();
+  public T get() {
+    WeakReference<T> weakRef = t.get();
     if (weakRef == null) {
-      Object iv = initialValue();
+      T iv = initialValue();
       if (iv != null) {
         set(iv);
         return iv;
@@ -66,17 +67,16 @@
     }
   }
 
-  public void set(Object object) {
+  public void set(T object) {
 
-    t.set(new WeakReference(object));
+    t.set(new WeakReference<T>(object));
 
     synchronized(hardRefs) {
       hardRefs.put(Thread.currentThread(), object);
 
       // Purge dead threads
-      Iterator it = hardRefs.keySet().iterator();
-      while(it.hasNext()) {
-        Thread t = (Thread) it.next();
+      for (Iterator<Thread> it = hardRefs.keySet().iterator(); it.hasNext();) {
+        final Thread t = it.next();
         if (!t.isAlive())
           it.remove();
       }

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java Tue Oct 20 19:58:18 2009
@@ -19,7 +19,6 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -111,13 +110,13 @@
     //
     // maps the (valId) identityhashCode of cache values to 
     // sets of CacheEntry instances
-    final MapOfSets valIdToItems = new MapOfSets(new HashMap(17));
+    final MapOfSets<Integer, CacheEntry> valIdToItems = new MapOfSets<Integer, CacheEntry>(new HashMap<Integer, Set<CacheEntry>>(17));
     // maps ReaderField keys to Sets of ValueIds
-    final MapOfSets readerFieldToValIds = new MapOfSets(new HashMap(17));
+    final MapOfSets<ReaderField, Integer> readerFieldToValIds = new MapOfSets<ReaderField, Integer>(new HashMap<ReaderField, Set<Integer>>(17));
     //
 
     // any keys that we know result in more then one valId
-    final Set valMismatchKeys = new HashSet();
+    final Set<ReaderField> valMismatchKeys = new HashSet<ReaderField>();
 
     // iterate over all the cacheEntries to get the mappings we'll need
     for (int i = 0; i < cacheEntries.length; i++) {
@@ -139,7 +138,7 @@
       }
     }
 
-    final List insanity = new ArrayList(valMismatchKeys.size() * 3);
+    final List<Insanity> insanity = new ArrayList<Insanity>(valMismatchKeys.size() * 3);
 
     insanity.addAll(checkValueMismatch(valIdToItems, 
                                        readerFieldToValIds, 
@@ -147,7 +146,7 @@
     insanity.addAll(checkSubreaders(valIdToItems, 
                                     readerFieldToValIds));
                     
-    return (Insanity[]) insanity.toArray(new Insanity[insanity.size()]);
+    return insanity.toArray(new Insanity[insanity.size()]);
   }
 
   /** 
@@ -157,31 +156,27 @@
    * the Insanity objects. 
    * @see InsanityType#VALUEMISMATCH
    */
-  private Collection checkValueMismatch(MapOfSets valIdToItems,
-                                        MapOfSets readerFieldToValIds,
-                                        Set valMismatchKeys) {
+  private Collection<Insanity> checkValueMismatch(MapOfSets<Integer, CacheEntry> valIdToItems,
+                                        MapOfSets<ReaderField, Integer> readerFieldToValIds,
+                                        Set<ReaderField> valMismatchKeys) {
 
-    final List insanity = new ArrayList(valMismatchKeys.size() * 3);
+    final List<Insanity> insanity = new ArrayList<Insanity>(valMismatchKeys.size() * 3);
 
     if (! valMismatchKeys.isEmpty() ) { 
       // we have multiple values for some ReaderFields
 
-      final Map rfMap = readerFieldToValIds.getMap();
-      final Map valMap = valIdToItems.getMap();
-      final Iterator mismatchIter = valMismatchKeys.iterator();
-      while (mismatchIter.hasNext()) {
-        final ReaderField rf = (ReaderField)mismatchIter.next();
-        final List badEntries = new ArrayList(valMismatchKeys.size() * 2);
-        final Iterator valIter = ((Set)rfMap.get(rf)).iterator();
-        while (valIter.hasNext()) {
-          Iterator entriesIter = ((Set)valMap.get(valIter.next())).iterator();
-          while (entriesIter.hasNext()) {
-            badEntries.add(entriesIter.next());
+      final Map<ReaderField, Set<Integer>> rfMap = readerFieldToValIds.getMap();
+      final Map<Integer, Set<CacheEntry>> valMap = valIdToItems.getMap();
+      for (final ReaderField rf : valMismatchKeys) {
+        final List<CacheEntry> badEntries = new ArrayList<CacheEntry>(valMismatchKeys.size() * 2);
+        for(final Integer value: rfMap.get(rf)) {
+          for (final CacheEntry cacheEntry : valMap.get(value)) {
+            badEntries.add(cacheEntry);
           }
         }
 
         CacheEntry[] badness = new CacheEntry[badEntries.size()];
-        badness = (CacheEntry[]) badEntries.toArray(badness);
+        badness = badEntries.toArray(badness);
 
         insanity.add(new Insanity(InsanityType.VALUEMISMATCH,
                                   "Multiple distinct value objects for " + 
@@ -199,35 +194,33 @@
    *
    * @see InsanityType#SUBREADER
    */
-  private Collection checkSubreaders(MapOfSets valIdToItems,
-                                     MapOfSets readerFieldToValIds) {
+  private Collection<Insanity> checkSubreaders( MapOfSets<Integer, CacheEntry>  valIdToItems,
+                                      MapOfSets<ReaderField, Integer> readerFieldToValIds) {
 
-    final List insanity = new ArrayList(23);
+    final List<Insanity> insanity = new ArrayList<Insanity>(23);
 
-    Map badChildren = new HashMap(17);
-    MapOfSets badKids = new MapOfSets(badChildren); // wrapper
+    Map<ReaderField, Set<ReaderField>> badChildren = new HashMap<ReaderField, Set<ReaderField>>(17);
+    MapOfSets<ReaderField, ReaderField> badKids = new MapOfSets<ReaderField, ReaderField>(badChildren); // wrapper
 
-    Map viToItemSets = valIdToItems.getMap();
-    Map rfToValIdSets = readerFieldToValIds.getMap();
+    Map<Integer, Set<CacheEntry>> viToItemSets = valIdToItems.getMap();
+    Map<ReaderField, Set<Integer>> rfToValIdSets = readerFieldToValIds.getMap();
 
-    Set seen = new HashSet(17);
+    Set<ReaderField> seen = new HashSet<ReaderField>(17);
 
-    Set readerFields = rfToValIdSets.keySet();
-    Iterator rfIter = readerFields.iterator();
-    while (rfIter.hasNext()) {
-      ReaderField rf = (ReaderField) rfIter.next();
+    Set<ReaderField> readerFields = rfToValIdSets.keySet();
+    for (final ReaderField rf : readerFields) {
       
       if (seen.contains(rf)) continue;
 
       List kids = getAllDecendentReaderKeys(rf.readerKey);
-      for (int i = 0; i < kids.size(); i++) {
-        ReaderField kid = new ReaderField(kids.get(i), rf.fieldName);
+      for (Object kidKey : kids) {
+        ReaderField kid = new ReaderField(kidKey, rf.fieldName);
         
         if (badChildren.containsKey(kid)) {
           // we've already process this kid as RF and found other problems
           // track those problems as our own
           badKids.put(rf, kid);
-          badKids.putAll(rf, (Collection)badChildren.get(kid));
+          badKids.putAll(rf, badChildren.get(kid));
           badChildren.remove(kid);
           
         } else if (rfToValIdSets.containsKey(kid)) {
@@ -240,33 +233,27 @@
     }
 
     // every mapping in badKids represents an Insanity
-    Iterator parentsIter = badChildren.keySet().iterator();
-    while (parentsIter.hasNext()) {
-      ReaderField parent = (ReaderField) parentsIter.next();
-      Set kids = (Set) badChildren.get(parent);
+    for (final ReaderField parent : badChildren.keySet()) {
+      Set<ReaderField> kids = badChildren.get(parent);
 
-      List badEntries = new ArrayList(kids.size() * 2);
+      List<CacheEntry> badEntries = new ArrayList<CacheEntry>(kids.size() * 2);
 
       // put parent entr(ies) in first
       {
-        Iterator valIter =((Set)rfToValIdSets.get(parent)).iterator();
-        while (valIter.hasNext()) {
-          badEntries.addAll((Set)viToItemSets.get(valIter.next()));
+        for (final Integer value  : rfToValIdSets.get(parent)) {
+          badEntries.addAll(viToItemSets.get(value));
         }
       }
 
       // now the entries for the descendants
-      Iterator kidsIter = kids.iterator();
-      while (kidsIter.hasNext()) {
-        ReaderField kid = (ReaderField) kidsIter.next();
-        Iterator valIter =((Set)rfToValIdSets.get(kid)).iterator();
-        while (valIter.hasNext()) {
-          badEntries.addAll((Set)viToItemSets.get(valIter.next()));
+      for (final ReaderField kid : kids) {
+        for (final Integer value : rfToValIdSets.get(kid)) {
+          badEntries.addAll(viToItemSets.get(value));
         }
       }
 
       CacheEntry[] badness = new CacheEntry[badEntries.size()];
-      badness = (CacheEntry[]) badEntries.toArray(badness);
+      badness = badEntries.toArray(badness);
 
       insanity.add(new Insanity(InsanityType.SUBREADER,
                                 "Found caches for decendents of " + 

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/MapOfSets.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/MapOfSets.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/MapOfSets.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/MapOfSets.java Tue Oct 20 19:58:18 2009
@@ -26,21 +26,21 @@
 /**
  * Helper class for keeping Lists of Objects associated with keys. <b>WARNING: THIS CLASS IS NOT THREAD SAFE</b>
  */
-public class MapOfSets {
+public class MapOfSets<K, V> {
 
-  private final Map theMap;
+  private final Map<K, Set<V>> theMap;
 
   /**
    * @param m the backing store for this object
    */
-  public MapOfSets(Map m) {
+  public MapOfSets(Map<K, Set<V>> m) {
     theMap = m;
   }
 
   /**
    * @return direct access to the map backing this object.
    */
-  public Map getMap() {
+  public Map<K, Set<V>> getMap() {
     return theMap;
   }
 
@@ -49,12 +49,12 @@
    * already in the map, a new Set will first be created.
    * @return the size of the Set associated with key once val is added to it.
    */
-  public int put(Object key, Object val) {
-    final Set theSet;
+  public int put(K key, V val) {
+    final Set<V> theSet;
     if (theMap.containsKey(key)) {
-      theSet = (Set)theMap.get(key);
+      theSet = theMap.get(key);
     } else {
-      theSet = new HashSet(23);
+      theSet = new HashSet<V>(23);
       theMap.put(key, theSet);
     }
     theSet.add(val);
@@ -66,12 +66,12 @@
    * already in the map, a new Set will first be created.
    * @return the size of the Set associated with key once val is added to it.
    */
-  public int putAll(Object key, Collection vals) {
-    final Set theSet;
+  public int putAll(K key, Collection<? extends V> vals) {
+    final Set<V> theSet;
     if (theMap.containsKey(key)) {
-      theSet = (Set)theMap.get(key);
+      theSet = theMap.get(key);
     } else {
-      theSet = new HashSet(23);
+      theSet = new HashSet<V>(23);
       theMap.put(key, theSet);
     }
     theSet.addAll(vals);

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/Parameter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/Parameter.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/Parameter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/Parameter.java Tue Oct 20 19:58:18 2009
@@ -28,7 +28,7 @@
  */
 public abstract class Parameter implements Serializable
 {
-  static Map allParameters = new HashMap();
+  static Map<String,Parameter> allParameters = new HashMap<String,Parameter>();
   
   private String name;
   

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/RamUsageEstimator.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/RamUsageEstimator.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/RamUsageEstimator.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/RamUsageEstimator.java Tue Oct 20 19:58:18 2009
@@ -37,7 +37,7 @@
 public final class RamUsageEstimator {
   private MemoryModel memoryModel;
 
-  private final Map seen;
+  private final Map<Object,Object> seen;
 
   private int refSize;
   private int arraySize;
@@ -82,7 +82,7 @@
     this.checkInterned = checkInterned;
     // Use Map rather than Set so that we can use an IdentityHashMap - not
     // seeing an IdentityHashSet
-    seen = new IdentityHashMap(64);
+    seen = new IdentityHashMap<Object,Object>(64);
     this.refSize = memoryModel.getReferenceSize();
     this.arraySize = memoryModel.getArraySize();
     this.classSize = memoryModel.getClassSize();

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/ReaderUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/ReaderUtil.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/ReaderUtil.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/ReaderUtil.java Tue Oct 20 19:58:18 2009
@@ -34,7 +34,7 @@
    * @param allSubReaders
    * @param reader
    */
-  public static void gatherSubReaders(List allSubReaders, IndexReader reader) {
+  public static void gatherSubReaders(List<IndexReader> allSubReaders, IndexReader reader) {
     IndexReader[] subReaders = reader.getSequentialSubReaders();
     if (subReaders == null) {
       // Add the reader itself, and do not recurse
@@ -54,7 +54,7 @@
    * @return sub reader of parent which contains the specified doc id
    */
   public static IndexReader subReader(int doc, IndexReader reader) {
-    List subReadersList = new ArrayList();
+    List<IndexReader> subReadersList = new ArrayList<IndexReader>();
     ReaderUtil.gatherSubReaders(subReadersList, reader);
     IndexReader[] subReaders = (IndexReader[]) subReadersList
         .toArray(new IndexReader[subReadersList.size()]);
@@ -75,7 +75,7 @@
    * @return the subreader at subIndex
    */
   public static IndexReader subReader(IndexReader reader, int subIndex) {
-    List subReadersList = new ArrayList();
+    List<IndexReader> subReadersList = new ArrayList<IndexReader>();
     ReaderUtil.gatherSubReaders(subReadersList, reader);
     IndexReader[] subReaders = (IndexReader[]) subReadersList
         .toArray(new IndexReader[subReadersList.size()]);

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/cache/Cache.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/cache/Cache.java?rev=827772&r1=827771&r2=827772&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/cache/Cache.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/util/cache/Cache.java Tue Oct 20 19:58:18 2009
@@ -17,47 +17,53 @@
  * limitations under the License.
  */
 
+import java.io.Closeable;
 
 /**
  * Base class for cache implementations.
  */
-public abstract class Cache {
+public abstract class Cache<K,V> implements Closeable {
   
   /**
    * Simple Cache wrapper that synchronizes all
    * calls that access the cache. 
    */
-  static class SynchronizedCache extends Cache {
-    Object mutex;
-    Cache  cache;
+  static class SynchronizedCache<K,V> extends Cache<K,V> {
+    private Object mutex;
+    private Cache<K,V> cache;
     
-    SynchronizedCache(Cache cache) {
+    SynchronizedCache(Cache<K,V> cache) {
       this.cache = cache;
       this.mutex = this;
     }
     
-    SynchronizedCache(Cache cache, Object mutex) {
+    SynchronizedCache(Cache<K,V> cache, Object mutex) {
       this.cache = cache;
       this.mutex = mutex;
     }
     
-    public void put(Object key, Object value) {
+    @Override
+    public void put(K key, V value) {
       synchronized(mutex) {cache.put(key, value);}
     }
     
-    public Object get(Object key) {
+    @Override
+    public V get(Object key) {
       synchronized(mutex) {return cache.get(key);}
     }
     
+    @Override
     public boolean containsKey(Object key) {
       synchronized(mutex) {return cache.containsKey(key);}
     }
     
+    @Override
     public void close() {
       synchronized(mutex) {cache.close();}
     }
     
-    Cache getSynchronizedCache() {
+    @Override
+    Cache<K,V> getSynchronizedCache() {
       return this;
     }
   }
@@ -67,7 +73,7 @@
    * In order to guarantee thread-safety, all access to the backed cache must
    * be accomplished through the returned cache.
    */
-  public static Cache synchronizedCache(Cache cache) {
+  public static <K,V> Cache<K,V> synchronizedCache(Cache<K,V> cache) {
     return cache.getSynchronizedCache();
   }
 
@@ -78,19 +84,19 @@
    * e. g. subclasses of {@link SynchronizedCache} or this
    * in case this cache is already synchronized.
    */
-  Cache getSynchronizedCache() {
-    return new SynchronizedCache(this);
+  Cache<K,V> getSynchronizedCache() {
+    return new SynchronizedCache<K,V>(this);
   }
   
   /**
    * Puts a (key, value)-pair into the cache. 
    */
-  public abstract void put(Object key, Object value);
+  public abstract void put(K key, V value);
   
   /**
    * Returns the value for the given key. 
    */
-  public abstract Object get(Object key);
+  public abstract V get(Object key);
   
   /**
    * Returns whether the given key is in this cache. 



Mime
View raw message