lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r826601 - in /lucene/java/trunk/src/java/org/apache/lucene: analysis/ index/
Date Mon, 19 Oct 2009 08:14:24 GMT
Author: uschindler
Date: Mon Oct 19 08:14:23 2009
New Revision: 826601

URL: http://svn.apache.org/viewvc?rev=826601&view=rev
Log:
LUCENE-1257: More generified APIs and implementations. Thanks Kay Kay & Robert Muir!

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/analysis/Analyzer.java
    lucene/java/trunk/src/java/org/apache/lucene/analysis/BaseCharFilter.java
    lucene/java/trunk/src/java/org/apache/lucene/analysis/CachingTokenFilter.java
    lucene/java/trunk/src/java/org/apache/lucene/analysis/PerFieldAnalyzerWrapper.java
    lucene/java/trunk/src/java/org/apache/lucene/analysis/TeeSinkTokenFilter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/FieldsReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/TermInfosReader.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/analysis/Analyzer.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/analysis/Analyzer.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/analysis/Analyzer.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/analysis/Analyzer.java Mon Oct 19 08:14:23
2009
@@ -52,7 +52,7 @@
     return tokenStream(fieldName, reader);
   }
 
-  private CloseableThreadLocal tokenStreams = new CloseableThreadLocal();
+  private CloseableThreadLocal<Object> tokenStreams = new CloseableThreadLocal<Object>();
 
   /** Used by Analyzers that implement reusableTokenStream
    *  to retrieve previously saved TokenStreams for re-use

Modified: lucene/java/trunk/src/java/org/apache/lucene/analysis/BaseCharFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/analysis/BaseCharFilter.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/analysis/BaseCharFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/analysis/BaseCharFilter.java Mon Oct 19 08:14:23
2009
@@ -33,8 +33,7 @@
  */
 public abstract class BaseCharFilter extends CharFilter {
 
-  //private List<OffCorrectMap> pcmList;
-  private List pcmList;
+  private List<OffCorrectMap> pcmList;
   
   public BaseCharFilter(CharStream in) {
     super(in);
@@ -64,7 +63,7 @@
 
   protected void addOffCorrectMap(int off, int cumulativeDiff) {
     if (pcmList == null) {
-      pcmList = new ArrayList();
+      pcmList = new ArrayList<OffCorrectMap>();
     }
     pcmList.add(new OffCorrectMap(off, cumulativeDiff));
   }

Modified: lucene/java/trunk/src/java/org/apache/lucene/analysis/CachingTokenFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/analysis/CachingTokenFilter.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/analysis/CachingTokenFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/analysis/CachingTokenFilter.java Mon Oct
19 08:14:23 2009
@@ -34,8 +34,8 @@
  * stream to the first Token. 
  */
 public final class CachingTokenFilter extends TokenFilter {
-  private List cache = null;
-  private Iterator iterator = null; 
+  private List<AttributeSource.State> cache = null;
+  private Iterator<AttributeSource.State> iterator = null; 
   private AttributeSource.State finalState;
   
   public CachingTokenFilter(TokenStream input) {
@@ -45,7 +45,7 @@
   public final boolean incrementToken() throws IOException {
     if (cache == null) {
       // fill cache lazily
-      cache = new LinkedList();
+      cache = new LinkedList<AttributeSource.State>();
       fillCache();
       iterator = cache.iterator();
     }
@@ -55,7 +55,7 @@
       return false;
     }
     // Since the TokenFilter can be reset, the tokens need to be preserved as immutable.
-    restoreState((AttributeSource.State) iterator.next());
+    restoreState(iterator.next());
     return true;
   }
   

Modified: lucene/java/trunk/src/java/org/apache/lucene/analysis/PerFieldAnalyzerWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/analysis/PerFieldAnalyzerWrapper.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/analysis/PerFieldAnalyzerWrapper.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/analysis/PerFieldAnalyzerWrapper.java Mon
Oct 19 08:14:23 2009
@@ -44,7 +44,7 @@
  */
 public class PerFieldAnalyzerWrapper extends Analyzer {
   private Analyzer defaultAnalyzer;
-  private Map analyzerMap = new HashMap();
+  private Map<String,Analyzer> analyzerMap = new HashMap<String,Analyzer>();
 
 
   /**
@@ -67,7 +67,7 @@
    * used for those fields 
    */
   public PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer, 
-      Map /*<String, Analyzer>*/ fieldAnalyzers) {
+      Map<String,Analyzer> fieldAnalyzers) {
     this.defaultAnalyzer = defaultAnalyzer;
     if (fieldAnalyzers != null) {
       analyzerMap.putAll(fieldAnalyzers);
@@ -87,7 +87,7 @@
   }
 
   public TokenStream tokenStream(String fieldName, Reader reader) {
-    Analyzer analyzer = (Analyzer) analyzerMap.get(fieldName);
+    Analyzer analyzer = analyzerMap.get(fieldName);
     if (analyzer == null) {
       analyzer = defaultAnalyzer;
     }
@@ -102,7 +102,7 @@
       // tokenStream but not reusableTokenStream
       return tokenStream(fieldName, reader);
     }
-    Analyzer analyzer = (Analyzer) analyzerMap.get(fieldName);
+    Analyzer analyzer = analyzerMap.get(fieldName);
     if (analyzer == null)
       analyzer = defaultAnalyzer;
 
@@ -111,7 +111,7 @@
   
   /** Return the positionIncrementGap from the analyzer assigned to fieldName */
   public int getPositionIncrementGap(String fieldName) {
-    Analyzer analyzer = (Analyzer) analyzerMap.get(fieldName);
+    Analyzer analyzer = analyzerMap.get(fieldName);
     if (analyzer == null)
       analyzer = defaultAnalyzer;
     return analyzer.getPositionIncrementGap(fieldName);

Modified: lucene/java/trunk/src/java/org/apache/lucene/analysis/TeeSinkTokenFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/analysis/TeeSinkTokenFilter.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/analysis/TeeSinkTokenFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/analysis/TeeSinkTokenFilter.java Mon Oct
19 08:14:23 2009
@@ -73,7 +73,7 @@
  * <p>Note, the EntityDetect and URLDetect TokenStreams are for the example and do
not currently exist in Lucene.
  */
 public final class TeeSinkTokenFilter extends TokenFilter {
-  private final List sinks = new LinkedList();
+  private final List<WeakReference<SinkTokenStream>> sinks = new LinkedList<WeakReference<SinkTokenStream>>();
   
   /**
    * Instantiates a new TeeSinkTokenFilter.
@@ -96,7 +96,7 @@
    */
   public SinkTokenStream newSinkTokenStream(SinkFilter filter) {
     SinkTokenStream sink = new SinkTokenStream(this.cloneAttributes(), filter);
-    this.sinks.add(new WeakReference(sink));
+    this.sinks.add(new WeakReference<SinkTokenStream>(sink));
     return sink;
   }
   
@@ -111,10 +111,10 @@
       throw new IllegalArgumentException("The supplied sink is not compatible to this tee");
     }
     // add eventually missing attribute impls to the existing sink
-    for (Iterator it = this.cloneAttributes().getAttributeImplsIterator(); it.hasNext();
) {
-      sink.addAttributeImpl((AttributeImpl) it.next());
+    for (Iterator<AttributeImpl> it = this.cloneAttributes().getAttributeImplsIterator();
it.hasNext(); ) {
+      sink.addAttributeImpl(it.next());
     }
-    this.sinks.add(new WeakReference(sink));
+    this.sinks.add(new WeakReference<SinkTokenStream>(sink));
   }
   
   /**
@@ -131,8 +131,8 @@
     if (input.incrementToken()) {
       // capture state lazily - maybe no SinkFilter accepts this state
       AttributeSource.State state = null;
-      for (Iterator it = sinks.iterator(); it.hasNext(); ) {
-        final SinkTokenStream sink = (SinkTokenStream) ((WeakReference) it.next()).get();
+      for (WeakReference<SinkTokenStream> ref : sinks) {
+        final SinkTokenStream sink = ref.get();
         if (sink != null) {
           if (sink.accept(this)) {
             if (state == null) {
@@ -151,8 +151,8 @@
   public final void end() throws IOException {
     super.end();
     AttributeSource.State finalState = captureState();
-    for (Iterator it = sinks.iterator(); it.hasNext(); ) {
-      final SinkTokenStream sink = (SinkTokenStream) ((WeakReference) it.next()).get();
+    for (WeakReference<SinkTokenStream> ref : sinks) {
+      final SinkTokenStream sink = ref.get();
       if (sink != null) {
         sink.setFinalState(finalState);
       }
@@ -179,9 +179,9 @@
   }
   
   public static final class SinkTokenStream extends TokenStream {
-    private final List cachedStates = new LinkedList();
+    private final List<AttributeSource.State> cachedStates = new LinkedList<AttributeSource.State>();
     private AttributeSource.State finalState;
-    private Iterator it = null;
+    private Iterator<AttributeSource.State> it = null;
     private SinkFilter filter;
     
     private SinkTokenStream(AttributeSource source, SinkFilter filter) {
@@ -214,7 +214,7 @@
         return false;
       }
       
-      AttributeSource.State state = (State) it.next();
+      AttributeSource.State state = it.next();
       restoreState(state);
       return true;
     }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/FieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/FieldsReader.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/FieldsReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/FieldsReader.java Mon Oct 19 08:14:23
2009
@@ -55,7 +55,7 @@
   // file.  This will be 0 if we have our own private file.
   private int docStoreOffset;
 
-  private CloseableThreadLocal fieldsStreamTL = new CloseableThreadLocal();
+  private CloseableThreadLocal<IndexInput> fieldsStreamTL = new CloseableThreadLocal<IndexInput>();
   private boolean isOriginal = false;
 
   /** Returns a cloned FieldsReader that shares open
@@ -417,7 +417,7 @@
     }
 
     private IndexInput getFieldStream() {
-      IndexInput localFieldsStream = (IndexInput) fieldsStreamTL.get();
+      IndexInput localFieldsStream = fieldsStreamTL.get();
       if (localFieldsStream == null) {
         localFieldsStream = (IndexInput) cloneableFieldsStream.clone();
         fieldsStreamTL.set(localFieldsStream);

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java Mon Oct 19 08:14:23
2009
@@ -23,7 +23,7 @@
 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;
@@ -49,8 +49,8 @@
   private SegmentInfo si;
   private int readBufferSize;
 
-  CloseableThreadLocal fieldsReaderLocal = new FieldsReaderLocal();
-  CloseableThreadLocal termVectorsLocal = new CloseableThreadLocal();
+  CloseableThreadLocal<FieldsReader> fieldsReaderLocal = new FieldsReaderLocal();
+  CloseableThreadLocal<TermVectorsReader> termVectorsLocal = new CloseableThreadLocal<TermVectorsReader>();
 
   BitVector deletedDocs = null;
   Ref deletedDocsRef = null;
@@ -292,9 +292,9 @@
   /**
    * Sets the initial value 
    */
-  private class FieldsReaderLocal extends CloseableThreadLocal {
-    protected Object initialValue() {
-      return core.getFieldsReaderOrig().clone();
+  private class FieldsReaderLocal extends CloseableThreadLocal<FieldsReader> {
+    protected FieldsReader initialValue() {
+      return (FieldsReader) core.getFieldsReaderOrig().clone();
     }
   }
   
@@ -824,7 +824,7 @@
   }
 
   FieldsReader getFieldsReader() {
-    return (FieldsReader) fieldsReaderLocal.get();
+    return fieldsReaderLocal.get();
   }
 
   protected void doClose() throws IOException {
@@ -1149,7 +1149,7 @@
    * @return TermVectorsReader
    */
   TermVectorsReader getTermVectorsReader() {
-    TermVectorsReader tvReader = (TermVectorsReader) termVectorsLocal.get();
+    TermVectorsReader tvReader = termVectorsLocal.get();
     if (tvReader == null) {
       TermVectorsReader orig = core.getTermVectorsReaderOrig();
       if (orig == null) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/TermInfosReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/TermInfosReader.java?rev=826601&r1=826600&r2=826601&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/TermInfosReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/TermInfosReader.java Mon Oct 19 08:14:23
2009
@@ -33,7 +33,7 @@
   private final String segment;
   private final FieldInfos fieldInfos;
 
-  private final CloseableThreadLocal threadResources = new CloseableThreadLocal();
+  private final CloseableThreadLocal<ThreadResources> threadResources = new CloseableThreadLocal<ThreadResources>();
   private final SegmentTermEnum origEnum;
   private final long size;
 
@@ -138,7 +138,7 @@
   }
 
   private ThreadResources getThreadResources() {
-    ThreadResources resources = (ThreadResources)threadResources.get();
+    ThreadResources resources = threadResources.get();
     if (resources == null) {
       resources = new ThreadResources();
       resources.termEnum = terms();



Mime
View raw message