LUCENE-1945: Add Closeable interface to all public interfaces/super-classes that define close(). Package-private classes inside oal.index are not changed (as they often only define package-private close())

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@826540 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-10-18 22:21:43 +00:00
parent 1c0678d148
commit 11c7039a82
15 changed files with 29 additions and 15 deletions

View File

@ -18,6 +18,7 @@ package org.apache.lucene.store.instantiated;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.io.Closeable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -52,7 +53,7 @@ import org.apache.lucene.index.TermPositions;
* Consider using InstantiatedIndex as if it was immutable. * Consider using InstantiatedIndex as if it was immutable.
*/ */
public class InstantiatedIndex public class InstantiatedIndex
implements Serializable { implements Serializable,Closeable {
private static final long serialVersionUID = 1l; private static final long serialVersionUID = 1l;

View File

@ -19,6 +19,7 @@ package org.apache.lucene.store.instantiated;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.StringReader; import java.io.StringReader;
import java.io.Closeable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -58,7 +59,7 @@ import org.apache.lucene.util.AttributeImpl;
* *
* @see org.apache.lucene.index.IndexWriter * @see org.apache.lucene.index.IndexWriter
*/ */
public class InstantiatedIndexWriter { public class InstantiatedIndexWriter implements Closeable {
private PrintStream infoStream = null; private PrintStream infoStream = null;

View File

@ -19,6 +19,7 @@ package org.apache.lucene.analysis;
import java.io.Reader; import java.io.Reader;
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.apache.lucene.util.CloseableThreadLocal; import org.apache.lucene.util.CloseableThreadLocal;
@ -33,7 +34,7 @@ import org.apache.lucene.document.Fieldable;
* characters from the Reader into raw Tokens. One or more TokenFilters may * characters from the Reader into raw Tokens. One or more TokenFilters may
* then be applied to the output of the Tokenizer. * then be applied to the output of the Tokenizer.
*/ */
public abstract class Analyzer { public abstract class Analyzer implements Closeable {
/** Creates a TokenStream which tokenizes all the text in the provided /** Creates a TokenStream which tokenizes all the text in the provided
* Reader. Must be able to handle null field name for * Reader. Must be able to handle null field name for
* backward compatibility. * backward compatibility.

View File

@ -18,6 +18,7 @@ package org.apache.lucene.analysis;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
@ -76,7 +77,7 @@ import org.apache.lucene.util.AttributeSource;
* {@link AttributeSource#captureState} and {@link AttributeSource#restoreState} * {@link AttributeSource#captureState} and {@link AttributeSource#restoreState}
* can be used. * can be used.
*/ */
public abstract class TokenStream extends AttributeSource { public abstract class TokenStream extends AttributeSource implements Closeable {
/** /**
* A TokenStream using the default attribute factory. * A TokenStream using the default attribute factory.

View File

@ -25,6 +25,7 @@ import org.apache.lucene.store.*;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@ -75,7 +76,7 @@ import java.util.Map;
<code>IndexReader</code> instance; use your own <code>IndexReader</code> instance; use your own
(non-Lucene) objects instead. (non-Lucene) objects instead.
*/ */
public abstract class IndexReader implements Cloneable { public abstract class IndexReader implements Cloneable,Closeable {
/** /**
* Constants describing field properties, for example used for * Constants describing field properties, for example used for

View File

@ -30,6 +30,7 @@ import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.util.Constants; import org.apache.lucene.util.Constants;
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.List; import java.util.List;
import java.util.Collection; import java.util.Collection;
@ -165,7 +166,7 @@ import java.util.Map;
* referenced by the "front" of the index). For this, IndexFileDeleter * referenced by the "front" of the index). For this, IndexFileDeleter
* keeps track of the last non commit checkpoint. * keeps track of the last non commit checkpoint.
*/ */
public class IndexWriter { public class IndexWriter implements Closeable {
/** /**
* Default value for the write lock timeout (1,000). * Default value for the write lock timeout (1,000).

View File

@ -61,7 +61,7 @@ import java.util.Set;
* these APIs. * these APIs.
*/ */
public abstract class MergePolicy { public abstract class MergePolicy implements java.io.Closeable {
/** OneMerge provides the information necessary to perform /** OneMerge provides the information necessary to perform
* an individual primitive merge operation, resulting in * an individual primitive merge operation, resulting in

View File

@ -18,6 +18,7 @@ package org.apache.lucene.index;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
/** TermDocs provides an interface for enumerating &lt;document, frequency&gt; /** TermDocs provides an interface for enumerating &lt;document, frequency&gt;
pairs for a term. <p> The document portion names each document containing pairs for a term. <p> The document portion names each document containing
@ -28,7 +29,7 @@ import java.io.IOException;
@see IndexReader#termDocs() @see IndexReader#termDocs()
*/ */
public interface TermDocs { public interface TermDocs extends Closeable {
/** Sets this to the data for a term. /** Sets this to the data for a term.
* The enumeration is reset to the start of the data for this term. * The enumeration is reset to the start of the data for this term.
*/ */

View File

@ -18,13 +18,14 @@ package org.apache.lucene.index;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
/** Abstract class for enumerating terms. /** Abstract class for enumerating terms.
<p>Term enumerations are always ordered by Term.compareTo(). Each term in <p>Term enumerations are always ordered by Term.compareTo(). Each term in
the enumeration is greater than all that precede it. */ the enumeration is greater than all that precede it. */
public abstract class TermEnum { public abstract class TermEnum implements Closeable {
/** Increments the enumeration to the next element. True if one exists.*/ /** Increments the enumeration to the next element. True if one exists.*/
public abstract boolean next() throws IOException; public abstract boolean next() throws IOException;

View File

@ -18,6 +18,7 @@ package org.apache.lucene.search;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldSelector; import org.apache.lucene.document.FieldSelector;
@ -41,7 +42,7 @@ import org.apache.lucene.index.Term;
* expected to be implemented directly, it may be changed unexpectedly between * expected to be implemented directly, it may be changed unexpectedly between
* releases. * releases.
*/ */
public interface Searchable { public interface Searchable extends Closeable {
/** /**
* Lower-level search API. * Lower-level search API.

View File

@ -18,6 +18,7 @@ package org.apache.lucene.store;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import org.apache.lucene.index.IndexFileNameFilter; import org.apache.lucene.index.IndexFileNameFilter;
@ -37,7 +38,7 @@ import org.apache.lucene.index.IndexFileNameFilter;
* instance using {@link #setLockFactory}. * instance using {@link #setLockFactory}.
* *
*/ */
public abstract class Directory { public abstract class Directory implements Closeable {
volatile protected boolean isOpen = true; volatile protected boolean isOpen = true;

View File

@ -18,6 +18,7 @@ package org.apache.lucene.store;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
@ -25,7 +26,7 @@ import java.util.HashMap;
* random-access input stream. Used for all Lucene index input operations. * random-access input stream. Used for all Lucene index input operations.
* @see Directory * @see Directory
*/ */
public abstract class IndexInput implements Cloneable { public abstract class IndexInput implements Cloneable,Closeable {
private byte[] bytes; // used by readString() private byte[] bytes; // used by readString()
private char[] chars; // used by readModifiedUTF8String() private char[] chars; // used by readModifiedUTF8String()
private boolean preUTF8Strings; // true if we are reading old (modified UTF8) string format private boolean preUTF8Strings; // true if we are reading old (modified UTF8) string format

View File

@ -18,6 +18,7 @@ package org.apache.lucene.store;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.Closeable;
import java.util.Map; import java.util.Map;
import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util.UnicodeUtil;
@ -26,7 +27,7 @@ import org.apache.lucene.util.UnicodeUtil;
* @see Directory * @see Directory
* @see IndexInput * @see IndexInput
*/ */
public abstract class IndexOutput { public abstract class IndexOutput implements Closeable {
private UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result(); private UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result();

View File

@ -21,6 +21,7 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.io.Closeable;
/** Java's builtin ThreadLocal has a serious flaw: /** Java's builtin ThreadLocal has a serious flaw:
* it can take an arbitrarily long amount of time to * it can take an arbitrarily long amount of time to
@ -42,7 +43,7 @@ import java.lang.ref.WeakReference;
* references are cleared and then GC is freely able to * references are cleared and then GC is freely able to
* reclaim space by objects stored in it. */ * reclaim space by objects stored in it. */
public class CloseableThreadLocal<T> { public class CloseableThreadLocal<T> implements Closeable {
private ThreadLocal<WeakReference<T>> t = new ThreadLocal<WeakReference<T>>(); private ThreadLocal<WeakReference<T>> t = new ThreadLocal<WeakReference<T>>();

View File

@ -17,11 +17,12 @@ package org.apache.lucene.util.cache;
* limitations under the License. * limitations under the License.
*/ */
import java.io.Closeable;
/** /**
* Base class for cache implementations. * Base class for cache implementations.
*/ */
public abstract class Cache<K,V> { public abstract class Cache<K,V> implements Closeable {
/** /**
* Simple Cache wrapper that synchronizes all * Simple Cache wrapper that synchronizes all