You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by cc...@apache.org on 2012/02/28 23:43:28 UTC
[Lucene.Net] svn commit: r1294875 [30/45] - in /incubator/lucene.net/trunk: ./ build/
build/vs2010/contrib/ build/vs2010/test/ doc/ src/ src/contrib/Analyzers/
src/contrib/Analyzers/AR/ src/contrib/Analyzers/BR/
src/contrib/Analyzers/CJK/ src/contrib/Analyzers/Cn/ ...
Modified: incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/NativeFSLockFactory.cs Tue Feb 28 22:43:08 2012
@@ -16,6 +16,7 @@
*/
using System;
+using System.Collections.Generic;
namespace Lucene.Net.Store
{
@@ -50,7 +51,7 @@ namespace Lucene.Net.Store
/// <seealso cref="LockFactory">
/// </seealso>
- public class NativeFSLockFactory:FSLockFactory
+ public class NativeFSLockFactory : FSLockFactory
{
/// <summary> Create a NativeFSLockFactory instance, with null (unset)
/// lock directory. When you pass this factory to a <see cref="FSDirectory" />
@@ -72,17 +73,6 @@ namespace Lucene.Net.Store
{
}
- /// <summary> Create a NativeFSLockFactory instance, storing lock
- /// files into the specified lockDir:
- ///
- /// </summary>
- /// <param name="lockDir">where lock files are created.
- /// </param>
- [System.Obsolete("Use the constructor that takes a DirectoryInfo, this will be removed in the 3.0 release")]
- public NativeFSLockFactory(System.IO.FileInfo lockDir) : this(new System.IO.DirectoryInfo(lockDir.FullName))
- {
- }
-
/// <summary> Create a NativeFSLockFactory instance, storing lock
/// files into the specified lockDir:
///
@@ -168,12 +158,7 @@ namespace Lucene.Net.Store
* one JVM (each with their own NativeFSLockFactory
* instance) have set the same lock dir and lock prefix.
*/
- private static System.Collections.Hashtable LOCK_HELD = new System.Collections.Hashtable();
-
- [System.Obsolete("Use the constructor that takes a DirectoryInfo, this will be removed in the 3.0 release")]
- public NativeFSLock(System.IO.FileInfo lockDir, System.String lockFileName):this(new System.IO.DirectoryInfo(lockDir.FullName), lockFileName)
- {
- }
+ private static HashSet<string> LOCK_HELD = new HashSet<string>();
public NativeFSLock(System.IO.DirectoryInfo lockDir, System.String lockFileName)
{
@@ -245,7 +230,7 @@ namespace Lucene.Net.Store
// thread trying to obtain this lock, so we own
// the only instance of a channel against this
// file:
- LOCK_HELD.Add(canonicalPath, canonicalPath);
+ LOCK_HELD.Add(canonicalPath);
markedHeld = true;
}
}
Modified: incubator/lucene.net/trunk/src/core/Store/NoLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/NoLockFactory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/NoLockFactory.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/NoLockFactory.cs Tue Feb 28 22:43:08 2012
@@ -21,7 +21,6 @@ namespace Lucene.Net.Store
{
/// <summary> Use this <see cref="LockFactory" /> to disable locking entirely.
- /// This LockFactory is used when you call <see cref="FSDirectory.SetDisableLocks" />.
/// Only one instance of this lock is created. You should call <see cref="GetNoLockFactory()" />
/// to get the instance.
///
@@ -29,7 +28,7 @@ namespace Lucene.Net.Store
/// <seealso cref="LockFactory">
/// </seealso>
- public class NoLockFactory:LockFactory
+ public class NoLockFactory : LockFactory
{
// Single instance returned whenever makeLock is called.
Modified: incubator/lucene.net/trunk/src/core/Store/RAMDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/RAMDirectory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/RAMDirectory.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/RAMDirectory.cs Tue Feb 28 22:43:08 2012
@@ -16,6 +16,7 @@
*/
using System;
+using Lucene.Net.Support;
namespace Lucene.Net.Store
{
@@ -23,18 +24,15 @@ namespace Lucene.Net.Store
/// <summary> A memory-resident <see cref="Directory"/> implementation. Locking
/// implementation is by default the <see cref="SingleInstanceLockFactory"/>
/// but can be changed with <see cref="Directory.SetLockFactory"/>.
- ///
/// </summary>
- /// <version> $Id: RAMDirectory.java 781333 2009-06-03 10:38:57Z mikemccand $
- /// </version>
[Serializable]
public class RAMDirectory:Directory
{
private const long serialVersionUID = 1L;
-
- internal protected System.Collections.Hashtable fileMap = new System.Collections.Hashtable();
- internal protected long sizeInBytes = 0;
+
+ internal protected HashMap<string, RAMFile> fileMap = new HashMap<string, RAMFile>();
+ internal protected long _sizeInBytes = 0;
// *****
// Lock acquisition sequence: RAMDirectory, then RAMFile
@@ -72,36 +70,6 @@ namespace Lucene.Net.Store
Directory.Copy(dir, this, closeDir);
}
- /// <summary> Creates a new <c>RAMDirectory</c> instance from the <see cref="FSDirectory"/>.
- ///
- /// </summary>
- /// <param name="dir">a <c>File</c> specifying the index directory
- ///
- /// </param>
- /// <seealso cref="RAMDirectory(Directory)">
- /// </seealso>
- /// <deprecated> Use <see cref="RAMDirectory(Directory)"/> instead
- /// </deprecated>
- [Obsolete("Use RAMDirectory(Directory) instead")]
- public RAMDirectory(System.IO.FileInfo dir):this(FSDirectory.GetDirectory(dir), true)
- {
- }
-
- /// <summary> Creates a new <c>RAMDirectory</c> instance from the <see cref="FSDirectory"/>.
- ///
- /// </summary>
- /// <param name="dir">a <c>String</c> specifying the full index directory path
- ///
- /// </param>
- /// <seealso cref="RAMDirectory(Directory)">
- /// </seealso>
- /// <deprecated> Use <see cref="RAMDirectory(Directory)"/> instead
- /// </deprecated>
- [Obsolete("Use RAMDirectory(Directory) instead")]
- public RAMDirectory(System.String dir):this(FSDirectory.GetDirectory(dir), true)
- {
- }
-
//https://issues.apache.org/jira/browse/LUCENENET-174
[System.Runtime.Serialization.OnDeserialized]
void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
@@ -111,28 +79,19 @@ namespace Lucene.Net.Store
SetLockFactory(new SingleInstanceLockFactory());
}
}
-
- [Obsolete("Lucene.Net-2.9.1. This method overrides obsolete member Lucene.Net.Store.Directory.List()")]
- public override System.String[] List()
- {
- lock (this)
- {
- return ListAll();
- }
- }
public override System.String[] ListAll()
{
lock (this)
{
EnsureOpen();
- System.Collections.ICollection fileNames = fileMap.Keys;
+ // TODO: may have better performance if our HashMap implmented KeySet() instead of generating one via HashSet
+ System.Collections.Generic.ISet<string> fileNames = new System.Collections.Generic.HashSet<string>(fileMap.Keys);
System.String[] result = new System.String[fileNames.Count];
int i = 0;
- System.Collections.IEnumerator it = fileNames.GetEnumerator();
- while (it.MoveNext())
+ foreach(string filename in fileNames)
{
- result[i++] = ((System.String) it.Current);
+ result[i++] = filename;
}
return result;
}
@@ -145,7 +104,7 @@ namespace Lucene.Net.Store
RAMFile file;
lock (this)
{
- file = (RAMFile) fileMap[name];
+ file = fileMap[name];
}
return file != null;
}
@@ -158,7 +117,7 @@ namespace Lucene.Net.Store
RAMFile file;
lock (this)
{
- file = (RAMFile) fileMap[name];
+ file = fileMap[name];
}
if (file == null)
throw new System.IO.FileNotFoundException(name);
@@ -173,7 +132,7 @@ namespace Lucene.Net.Store
RAMFile file;
lock (this)
{
- file = (RAMFile) fileMap[name];
+ file = fileMap[name];
}
if (file == null)
throw new System.IO.FileNotFoundException(name);
@@ -189,7 +148,7 @@ namespace Lucene.Net.Store
{
// In 3.0 we will change this to throw
// InterruptedException instead
- SupportClass.ThreadClass.Current().Interrupt();
+ ThreadClass.Current().Interrupt();
throw new System.SystemException(ie.Message, ie);
}
ts2 = System.DateTime.Now.Ticks;
@@ -207,7 +166,7 @@ namespace Lucene.Net.Store
RAMFile file;
lock (this)
{
- file = (RAMFile) fileMap[name];
+ file = fileMap[name];
}
if (file == null)
throw new System.IO.FileNotFoundException(name);
@@ -223,7 +182,7 @@ namespace Lucene.Net.Store
lock (this)
{
EnsureOpen();
- return sizeInBytes;
+ return _sizeInBytes;
}
}
@@ -234,42 +193,18 @@ namespace Lucene.Net.Store
lock (this)
{
EnsureOpen();
- RAMFile file = (RAMFile) fileMap[name];
+ RAMFile file = fileMap[name];
if (file != null)
{
fileMap.Remove(name);
file.directory = null;
- sizeInBytes -= file.sizeInBytes;
+ _sizeInBytes -= file.sizeInBytes;
}
else
throw new System.IO.FileNotFoundException(name);
}
}
- /// <summary>Renames an existing file in the directory.</summary>
- /// <throws> FileNotFoundException if from does not exist </throws>
- /// <deprecated>
- /// </deprecated>
- [Obsolete]
- public override void RenameFile(System.String from, System.String to)
- {
- lock (this)
- {
- EnsureOpen();
- RAMFile fromFile = (RAMFile) fileMap[from];
- if (fromFile == null)
- throw new System.IO.FileNotFoundException(from);
- RAMFile toFile = (RAMFile) fileMap[to];
- if (toFile != null)
- {
- sizeInBytes -= toFile.sizeInBytes; // updates to RAMFile.sizeInBytes synchronized on directory
- toFile.directory = null;
- }
- fileMap.Remove(from);
- fileMap[to] = fromFile;
- }
- }
-
/// <summary>Creates a new, empty file in the directory with the given name. Returns a stream writing this file. </summary>
public override IndexOutput CreateOutput(System.String name)
{
@@ -277,10 +212,10 @@ namespace Lucene.Net.Store
RAMFile file = new RAMFile(this);
lock (this)
{
- RAMFile existing = (RAMFile) fileMap[name];
+ RAMFile existing = fileMap[name];
if (existing != null)
{
- sizeInBytes -= existing.sizeInBytes;
+ _sizeInBytes -= existing.sizeInBytes;
existing.directory = null;
}
fileMap[name] = file;
@@ -295,37 +230,29 @@ namespace Lucene.Net.Store
RAMFile file;
lock (this)
{
- file = (RAMFile) fileMap[name];
+ file = fileMap[name];
}
if (file == null)
throw new System.IO.FileNotFoundException(name);
return new RAMInputStream(file);
}
-
- /// <summary>Closes the store to future operations, releasing associated memory. </summary>
- public override void Close()
- {
- isOpen = false;
- fileMap = null;
- }
- /// <summary>
- /// .NET
- /// </summary>
- public override void Dispose()
+ /// <summary>Closes the store to future operations, releasing associated memory. </summary>
+ protected override void Dispose(bool disposing)
{
- Close();
+ isOpen = false;
+ fileMap = null;
}
- public System.Collections.Hashtable fileMap_ForNUnit
- {
- get { return fileMap; }
- }
-
- public long sizeInBytes_ForNUnitTest
- {
- get { return sizeInBytes; }
- set { sizeInBytes = value; }
- }
+ //public HashMap<string, RAMFile> fileMap_ForNUnit
+ //{
+ // get { return fileMap; }
+ //}
+
+ //public long sizeInBytes_ForNUnitTest
+ //{
+ // get { return sizeInBytes; }
+ // set { sizeInBytes = value; }
+ //}
}
}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/src/core/Store/RAMFile.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/RAMFile.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/RAMFile.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/RAMFile.cs Tue Feb 28 22:43:08 2012
@@ -26,7 +26,7 @@ namespace Lucene.Net.Store
private const long serialVersionUID = 1L;
- protected System.Collections.ArrayList buffers = new System.Collections.ArrayList();
+ protected System.Collections.Generic.List<byte[]> buffers = new System.Collections.Generic.List<byte[]>();
internal long length;
internal RAMDirectory directory;
internal long sizeInBytes;
@@ -91,7 +91,7 @@ namespace Lucene.Net.Store
{
lock (directory) //{{DIGY}} what if directory gets null in the mean time?
{
- directory.sizeInBytes += size;
+ directory._sizeInBytes += size;
}
}
@@ -102,7 +102,7 @@ namespace Lucene.Net.Store
{
lock (this)
{
- return (byte[]) buffers[index];
+ return buffers[index];
}
}
Modified: incubator/lucene.net/trunk/src/core/Store/RAMInputStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/RAMInputStream.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/RAMInputStream.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/RAMInputStream.cs Tue Feb 28 22:43:08 2012
@@ -23,10 +23,7 @@ namespace Lucene.Net.Store
/// <summary> A memory-resident <see cref="IndexInput" /> implementation.
///
/// </summary>
- /// <version> $Id: RAMInputStream.java 632120 2008-02-28 21:13:59Z mikemccand $
- /// </version>
-
- public class RAMInputStream:IndexInput, System.ICloneable
+ public class RAMInputStream : IndexInput
{
internal static readonly int BUFFER_SIZE;
@@ -54,11 +51,11 @@ namespace Lucene.Net.Store
currentBufferIndex = - 1;
currentBuffer = null;
}
-
- public override void Close()
- {
- // nothing to do here
- }
+
+ protected override void Dispose(bool disposing)
+ {
+ // do nothing
+ }
public override long Length()
{
@@ -110,7 +107,7 @@ namespace Lucene.Net.Store
}
else
{
- currentBuffer = (byte[]) file.GetBuffer(currentBufferIndex);
+ currentBuffer = file.GetBuffer(currentBufferIndex);
bufferPosition = 0;
bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex;
long buflen = length - bufferStart;
Modified: incubator/lucene.net/trunk/src/core/Store/RAMOutputStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/RAMOutputStream.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/RAMOutputStream.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/RAMOutputStream.cs Tue Feb 28 22:43:08 2012
@@ -21,11 +21,8 @@ namespace Lucene.Net.Store
{
/// <summary> A memory-resident <see cref="IndexOutput" /> implementation.
- ///
+ /// <para>For lucene internal use.</para>
/// </summary>
- /// <version> $Id: RAMOutputStream.java 691694 2008-09-03 17:34:29Z mikemccand $
- /// </version>
-
public class RAMOutputStream:IndexOutput
{
internal const int BUFFER_SIZE = 1024;
@@ -34,7 +31,9 @@ namespace Lucene.Net.Store
private byte[] currentBuffer;
private int currentBufferIndex;
-
+
+ private bool isDisposed;
+
private int bufferPosition;
private long bufferStart;
private int bufferLength;
@@ -70,7 +69,7 @@ namespace Lucene.Net.Store
// at the last buffer
length = (int) (end - pos);
}
- out_Renamed.WriteBytes((byte[]) file.GetBuffer(buffer++), length);
+ out_Renamed.WriteBytes(file.GetBuffer(buffer++), length);
pos = nextPos;
}
}
@@ -87,10 +86,17 @@ namespace Lucene.Net.Store
file.SetLength(0);
}
- public override void Close()
- {
- Flush();
- }
+ protected override void Dispose(bool disposing)
+ {
+ if (isDisposed) return;
+
+ if (disposing)
+ {
+ Flush();
+ }
+
+ isDisposed = true;
+ }
public override void Seek(long pos)
{
@@ -149,7 +155,7 @@ namespace Lucene.Net.Store
}
else
{
- currentBuffer = (byte[]) file.GetBuffer(currentBufferIndex);
+ currentBuffer = file.GetBuffer(currentBufferIndex);
}
bufferPosition = 0;
bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex;
Modified: incubator/lucene.net/trunk/src/core/Store/SimpleFSDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/SimpleFSDirectory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/SimpleFSDirectory.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/SimpleFSDirectory.cs Tue Feb 28 22:43:08 2012
@@ -27,22 +27,8 @@ namespace Lucene.Net.Store
/// read from the same file. It's usually better to use
/// <see cref="NIOFSDirectory" /> or <see cref="MMapDirectory" /> instead.
/// </summary>
- public class SimpleFSDirectory:FSDirectory
+ public class SimpleFSDirectory : FSDirectory
{
-
- /// <summary>Create a new SimpleFSDirectory for the named location.
- ///
- /// </summary>
- /// <param name="path">the path of the directory
- /// </param>
- /// <param name="lockFactory">the lock factory to use, or null for the default.
- /// </param>
- /// <throws> IOException </throws>
- [System.Obsolete("Use the constructor that takes a DirectoryInfo, this will be removed in the 3.0 release")]
- public SimpleFSDirectory(System.IO.FileInfo path, LockFactory lockFactory):base(new System.IO.DirectoryInfo(path.FullName), lockFactory)
- {
- }
-
/// <summary>Create a new SimpleFSDirectory for the named location.
///
/// </summary>
@@ -51,40 +37,22 @@ namespace Lucene.Net.Store
/// <param name="lockFactory">the lock factory to use, or null for the default.
/// </param>
/// <throws> IOException </throws>
- public SimpleFSDirectory(System.IO.DirectoryInfo path, LockFactory lockFactory) : base(path, lockFactory)
+ public SimpleFSDirectory(System.IO.DirectoryInfo path, LockFactory lockFactory)
+ : base(path, lockFactory)
{
}
-
- /// <summary>Create a new SimpleFSDirectory for the named location and the default lock factory.
- ///
- /// </summary>
- /// <param name="path">the path of the directory
- /// </param>
- /// <throws> IOException </throws>
- [System.Obsolete("Use the constructor that takes a DirectoryInfo, this will be removed in the 3.0 release")]
- public SimpleFSDirectory(System.IO.FileInfo path):base(new System.IO.DirectoryInfo(path.FullName), null)
- {
- }
-
- // back compatibility so FSDirectory can instantiate via reflection
- /// <deprecated>
- /// </deprecated>
- [Obsolete]
- internal SimpleFSDirectory()
- {
- }
-
- /// <summary>Create a new SimpleFSDirectory for the named location and the default lock factory.
+
+ /// <summary>Create a new SimpleFSDirectory for the named location and the default lock factory.
///
/// </summary>
/// <param name="path">the path of the directory
/// </param>
/// <throws> IOException </throws>
public SimpleFSDirectory(System.IO.DirectoryInfo path) : base(path, null)
- {
- }
+ {
+ }
- /// <summary>Creates an IndexOutput for the file with the given name. </summary>
+ /// <summary>Creates an IndexOutput for the file with the given name. </summary>
public override IndexOutput CreateOutput(System.String name)
{
InitOutput(name);
@@ -96,33 +64,36 @@ namespace Lucene.Net.Store
{
EnsureOpen();
- Exception e = null;
- for (int i = 0; i < 10; i++)
- {
- try
- {
- return new SimpleFSIndexInput(new System.IO.FileInfo(System.IO.Path.Combine(directory.FullName, name)), bufferSize, GetReadChunkSize());
- }
- catch (System.UnauthorizedAccessException ex)
- {
- e = ex;
+ Exception e = null;
+ for (var i = 0; i < 10; i++)
+ {
+ try
+ {
+ return new SimpleFSIndexInput(new System.IO.FileInfo(
+ System.IO.Path.Combine(directory.FullName, name)), bufferSize, GetReadChunkSize());
+ }
+ catch (System.UnauthorizedAccessException ex)
+ {
+ e = ex;
System.Threading.Thread.Sleep(1);
- }
- }
+ }
+ }
throw e;
}
- public /*protected internal*/class SimpleFSIndexInput:BufferedIndexInput, System.ICloneable
+ protected internal class SimpleFSIndexInput : BufferedIndexInput
{
-
- protected internal class Descriptor:System.IO.BinaryReader
+ // TODO: This is a bad way to handle memory and disposing
+ protected internal class Descriptor : System.IO.BinaryReader
{
// remember if the file is open, so that we don't try to close it
// more than once
protected internal volatile bool isOpen;
internal long position;
internal long length;
+
+ private bool isDisposed;
public Descriptor(/*FSIndexInput enclosingInstance,*/ System.IO.FileInfo file, System.IO.FileAccess mode)
: base(new System.IO.FileStream(file.FullName, System.IO.FileMode.Open, mode, System.IO.FileShare.ReadWrite))
@@ -130,21 +101,28 @@ namespace Lucene.Net.Store
isOpen = true;
length = file.Length;
}
-
- public override void Close()
- {
- if (isOpen)
- {
- isOpen = false;
- base.Close();
- }
- }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (isDisposed) return;
+
+ if (disposing)
+ {
+ if (isOpen)
+ {
+ isOpen = false;
+ }
+ }
+
+ isDisposed = true;
+ base.Dispose(disposing);
+ }
~Descriptor()
{
try
{
- Close();
+ Dispose(false);
}
finally
{
@@ -154,30 +132,18 @@ namespace Lucene.Net.Store
protected internal Descriptor file;
internal bool isClone;
+ private bool isDisposed;
// LUCENE-1566 - maximum read length on a 32bit JVM to prevent incorrect OOM
protected internal int chunkSize;
-
- /// <deprecated> Please use ctor taking chunkSize
- /// </deprecated>
- [Obsolete("Please use ctor taking chunkSize ")]
- public SimpleFSIndexInput(System.IO.FileInfo path):this(path, BufferedIndexInput.BUFFER_SIZE, SimpleFSDirectory.DEFAULT_READ_CHUNK_SIZE)
- {
- }
-
- /// <deprecated> Please use ctor taking chunkSize
- /// </deprecated>
- [Obsolete("Please use ctor taking chunkSize ")]
- public SimpleFSIndexInput(System.IO.FileInfo path, int bufferSize):this(path, bufferSize, SimpleFSDirectory.DEFAULT_READ_CHUNK_SIZE)
- {
- }
-
- public SimpleFSIndexInput(System.IO.FileInfo path, int bufferSize, int chunkSize):base(bufferSize)
- {
- file = new Descriptor(path, System.IO.FileAccess.Read);
- this.chunkSize = chunkSize;
- }
-
- /// <summary>IndexInput methods </summary>
+
+ public SimpleFSIndexInput(System.IO.FileInfo path, int bufferSize, int chunkSize)
+ : base(bufferSize)
+ {
+ file = new Descriptor(path, System.IO.FileAccess.Read);
+ this.chunkSize = chunkSize;
+ }
+
+ /// <summary>IndexInput methods </summary>
public override void ReadInternal(byte[] b, int offset, int len)
{
lock (file)
@@ -223,15 +189,24 @@ namespace Lucene.Net.Store
}
}
}
-
- public override void Close()
- {
- // only close the file if this is not a clone
- if (!isClone)
- file.Close();
- }
-
- public override void SeekInternal(long position)
+
+ protected override void Dispose(bool disposing)
+ {
+ if (isDisposed) return;
+ if (disposing)
+ {
+ // only close the file if this is not a clone
+ if (!isClone && file != null)
+ {
+ file.Close();
+ file = null;
+ }
+ }
+
+ isDisposed = true;
+ }
+
+ public override void SeekInternal(long position)
{
}
@@ -268,6 +243,8 @@ namespace Lucene.Net.Store
// remember if the file is open, so that we don't try to close it
// more than once
private volatile bool isOpen;
+
+ private bool isDisposed;
public SimpleFSIndexOutput(System.IO.FileInfo path)
{
@@ -291,36 +268,37 @@ namespace Lucene.Net.Store
// Can there be a indexing-performance problem?
file.Flush();
}
- public override void Close()
- {
- // only close the file if it has not been closed yet
- if (isOpen)
- {
- bool success = false;
- try
- {
- base.Close();
- success = true;
- }
- finally
- {
- isOpen = false;
- if (!success)
- {
- try
- {
- file.Close();
- }
- catch (System.Exception t)
- {
- // Suppress so we don't mask original exception
- }
- }
- else
- file.Close();
- }
- }
- }
+
+ protected override void Dispose(bool disposing)
+ {
+ // only close the file if it has not been closed yet
+ if (isOpen)
+ {
+ bool success = false;
+ try
+ {
+ base.Dispose(disposing);
+ success = true;
+ }
+ finally
+ {
+ isOpen = false;
+ if (!success)
+ {
+ try
+ {
+ file.Dispose();
+ }
+ catch (System.Exception t)
+ {
+ // Suppress so we don't mask original exception
+ }
+ }
+ else
+ file.Dispose();
+ }
+ }
+ }
/// <summary>Random-access methods </summary>
public override void Seek(long pos)
Modified: incubator/lucene.net/trunk/src/core/Store/SimpleFSLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/SimpleFSLockFactory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/SimpleFSLockFactory.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/SimpleFSLockFactory.cs Tue Feb 28 22:43:08 2012
@@ -35,8 +35,8 @@ namespace Lucene.Net.Store
/// <p/>When this happens, a <see cref="LockObtainFailedException" />
/// is hit when trying to create a writer, in which case you
/// need to explicitly clear the lock file first. You can
- /// either manually remove the file, or use the <see cref="Lucene.Net.Index.IndexReader.Unlock(Directory)" />
- ///
+ /// either manually remove the file, or use the
+ /// <see cref="Lucene.Net.Index.IndexWriter.Unlock(Directory)" />
/// API. But, first be certain that no writer is in fact
/// writing to the index otherwise you can easily corrupt
/// your index.<p/>
@@ -62,15 +62,6 @@ namespace Lucene.Net.Store
public SimpleFSLockFactory():this((System.IO.DirectoryInfo) null)
{
}
-
- /// <summary> Instantiate using the provided directory (as a File instance).</summary>
- /// <param name="lockDir">where lock files should be created.
- /// </param>
- [System.Obsolete("Use the constructor that takes a DirectoryInfo, this will be removed in the 3.0 release")]
- public SimpleFSLockFactory(System.IO.FileInfo lockDir)
- {
- SetLockDir(new System.IO.DirectoryInfo(lockDir.FullName));
- }
/// <summary> Instantiate using the provided directory (as a File instance).</summary>
/// <param name="lockDir">where lock files should be created.
@@ -84,9 +75,8 @@ namespace Lucene.Net.Store
/// <param name="lockDirName">where lock files should be created.
/// </param>
public SimpleFSLockFactory(System.String lockDirName)
+ : this(new System.IO.DirectoryInfo(lockDirName))
{
- lockDir = new System.IO.DirectoryInfo(lockDirName);
- SetLockDir(lockDir);
}
public override Lock MakeLock(System.String lockName)
Modified: incubator/lucene.net/trunk/src/core/Store/SingleInstanceLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/SingleInstanceLockFactory.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/SingleInstanceLockFactory.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/SingleInstanceLockFactory.cs Tue Feb 28 22:43:08 2012
@@ -34,7 +34,7 @@ namespace Lucene.Net.Store
public class SingleInstanceLockFactory:LockFactory
{
- private System.Collections.Hashtable locks = new System.Collections.Hashtable();
+ private System.Collections.Generic.HashSet<string> locks = new System.Collections.Generic.HashSet<string>();
public override Lock MakeLock(System.String lockName)
{
@@ -61,9 +61,9 @@ namespace Lucene.Net.Store
{
internal System.String lockName;
- private System.Collections.Hashtable locks;
-
- public SingleInstanceLock(System.Collections.Hashtable locks, System.String lockName)
+ private System.Collections.Generic.HashSet<string> locks;
+
+ public SingleInstanceLock(System.Collections.Generic.HashSet<string> locks, System.String lockName)
{
this.locks = locks;
this.lockName = lockName;
@@ -75,7 +75,7 @@ namespace Lucene.Net.Store
{
if (locks.Contains(lockName) == false)
{
- locks.Add(lockName, lockName);
+ locks.Add(lockName);
return true;
}
Modified: incubator/lucene.net/trunk/src/core/Util/AttributeSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/AttributeSource.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/AttributeSource.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/AttributeSource.cs Tue Feb 28 22:43:08 2012
@@ -17,6 +17,8 @@
using System;
using System.Collections.Generic;
+using System.Linq;
+using Lucene.Net.Support;
using TokenStream = Lucene.Net.Analysis.TokenStream;
namespace Lucene.Net.Util
@@ -35,10 +37,8 @@ namespace Lucene.Net.Util
/// <summary> An AttributeFactory creates instances of <see cref="AttributeImpl" />s.</summary>
public abstract class AttributeFactory
{
- /// <summary> returns an <see cref="AttributeImpl" /> for the supplied <see cref="Attribute" /> interface class.
- /// <p/>Signature for Java 1.5: <c>public AttributeImpl createAttributeInstance(Class%lt;? extends Attribute> attClass)</c>
- /// </summary>
- public abstract AttributeImpl CreateAttributeInstance(System.Type attClass);
+ /// <summary> returns an <see cref="AttributeImpl" /> for the supplied <see cref="Attribute" /> interface class.</summary>
+ public abstract AttributeImpl CreateAttributeInstance<T>() where T : Attribute;
/// <summary> This is the default factory that creates <see cref="AttributeImpl" />s using the
/// class name of the supplied <see cref="Attribute" /> interface class by appending <c>Impl</c> to it.
@@ -47,42 +47,45 @@ namespace Lucene.Net.Util
private sealed class DefaultAttributeFactory:AttributeFactory
{
- private static readonly SupportClass.WeakHashTable attClassImplMap = new SupportClass.WeakHashTable();
+ // This should be WeakDictionary<T, WeakReference<TImpl>> where typeof(T) is Attribute and TImpl is typeof(AttributeImpl)
+ private static readonly WeakDictionary<Type, WeakReference> attClassImplMap =
+ new WeakDictionary<Type, WeakReference>();
internal DefaultAttributeFactory()
{
}
- public override AttributeImpl CreateAttributeInstance(System.Type attClass)
+ public override AttributeImpl CreateAttributeInstance<TAttImpl>()
{
try
{
- return (AttributeImpl) System.Activator.CreateInstance(GetClassForInterface(attClass));
+ return (AttributeImpl)System.Activator.CreateInstance(GetClassForInterface<TAttImpl>());
}
catch (System.UnauthorizedAccessException e)
{
- throw new System.ArgumentException("Could not instantiate implementing class for " + attClass.FullName);
- }
- catch (System.Exception e)
- {
- throw new System.ArgumentException("Could not instantiate implementing class for " + attClass.FullName);
+ throw new System.ArgumentException("Could not instantiate implementing class for " + typeof(TAttImpl).FullName);
}
+ //catch (System.Exception e)
+ //{
+ // throw new System.ArgumentException("Could not instantiate implementing class for " + typeof(TAttImpl).FullName);
+ //}
}
-
- private static System.Type GetClassForInterface(System.Type attClass)
+
+ private static System.Type GetClassForInterface<T>() where T : Attribute
{
lock (attClassImplMap)
{
- WeakReference refz = (WeakReference) attClassImplMap[attClass];
+ var attClass = typeof (T);
+ WeakReference refz = attClassImplMap[attClass];
System.Type clazz = (refz == null) ? null : ((System.Type) refz.Target);
if (clazz == null)
{
try
{
- string name = attClass.FullName + "Impl," + attClass.Assembly.FullName;
+ string name = attClass.FullName + "Impl, " + attClass.Assembly.FullName;
attClassImplMap.Add(attClass, new WeakReference( clazz = System.Type.GetType(name, true))); //OK
}
- catch (System.Exception e)
+ catch (System.TypeLoadException e) // was System.Exception
{
throw new System.ArgumentException("Could not find implementing class for " + attClass.FullName);
}
@@ -93,13 +96,13 @@ namespace Lucene.Net.Util
}
}
- // These two maps must always be in sync!!!
+ // These two maps must always be in sync!!!
// So they are private, final and read-only from the outside (read-only iterators)
- private SupportClass.GeneralKeyedCollection<Type, SupportClass.AttributeImplItem> attributes;
- private SupportClass.GeneralKeyedCollection<Type, SupportClass.AttributeImplItem> attributeImpls;
- private State[] currentState = null;
+ private GeneralKeyedCollection<Type, AttributeImplItem> attributes;
+ private GeneralKeyedCollection<Type, AttributeImplItem> attributeImpls;
- private AttributeFactory factory;
+ private State[] currentState = null;
+ private AttributeFactory factory;
/// <summary> An AttributeSource using the default attribute factory <see cref="AttributeSource.AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY" />.</summary>
public AttributeSource():this(AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY)
@@ -122,16 +125,23 @@ namespace Lucene.Net.Util
/// <summary> An AttributeSource using the supplied <see cref="AttributeFactory" /> for creating new <see cref="Attribute" /> instances.</summary>
public AttributeSource(AttributeFactory factory)
{
- this.attributes = new SupportClass.GeneralKeyedCollection<Type, SupportClass.AttributeImplItem>(att => att.Key);
- this.attributeImpls = new SupportClass.GeneralKeyedCollection<Type, SupportClass.AttributeImplItem>(att => att.Key);
- this.currentState = new State[1];
+ this.attributes = new GeneralKeyedCollection<Type, AttributeImplItem>(att => att.Key);
+ this.attributeImpls = new GeneralKeyedCollection<Type, AttributeImplItem>(att => att.Key);
+ this.currentState = new State[1];
this.factory = factory;
}
-
+
+ /// <summary> returns the used AttributeFactory.</summary>
+ public virtual AttributeFactory Factory
+ {
+ get { return this.factory; }
+ }
+
/// <summary> returns the used AttributeFactory.</summary>
+ [Obsolete("Use Factory property instead")]
public virtual AttributeFactory GetAttributeFactory()
{
- return this.factory;
+ return Factory;
}
/// <summary>Returns a new iterator that iterates the attribute classes
@@ -141,124 +151,84 @@ namespace Lucene.Net.Util
/// Note that this return value is different from Java in that it enumerates over the values
/// and not the keys
/// </summary>
+ [Obsolete("Use AttributeClasses property instead")]
public virtual IEnumerable<Type> GetAttributeClassesIterator()
{
- foreach (SupportClass.AttributeImplItem item in this.attributes)
- {
- yield return item.Key;
- }
+ return AttributeClasses;
}
+
+ /// <summary>Returns a new iterator that iterates the attribute classes
+ /// in the same order they were added in.
+ /// Signature for Java 1.5: <c>public Iterator<Class<? extends Attribute>> getAttributeClassesIterator()</c>
+ ///
+ /// Note that this return value is different from Java in that it enumerates over the values
+ /// and not the keys
+ /// </summary>
+ public virtual IEnumerable<Type> AttributeClasses
+ {
+ get
+ {
+ return this.attributes.Select(item => item.Key);
+ }
+ }
/// <summary>Returns a new iterator that iterates all unique Attribute implementations.
/// This iterator may contain less entries that <see cref="GetAttributeClassesIterator" />,
/// if one instance implements more than one Attribute interface.
/// Signature for Java 1.5: <c>public Iterator<AttributeImpl> getAttributeImplsIterator()</c>
/// </summary>
+ [Obsolete("Use AttributeImpls property instead")]
public virtual IEnumerable<AttributeImpl> GetAttributeImplsIterator()
{
- State initState = GetCurrentState();
- if (initState != null)
- {
- return new AnonymousEnumerable(initState);
- }
- else
- {
- return new List<AttributeImpl>();
- }
+ return AttributeImpls;
}
-
- class AnonymousEnumerable : IEnumerable<AttributeImpl>
- {
- State state;
- public AnonymousEnumerable(State state)
- {
- this.state = state;
- }
- public IEnumerator<AttributeImpl> GetEnumerator()
- {
- return new AnonymousEnumerator(state);
- }
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return new AnonymousEnumerator(state);
- }
- }
-
- class AnonymousEnumerator : IEnumerator<AttributeImpl>
- {
- State state;
- public AnonymousEnumerator(State state)
- {
- this.state = state;
- }
- AttributeImpl InternalCurrent
- {
- get
+ /// <summary>Returns a new iterator that iterates all unique Attribute implementations.
+ /// This iterator may contain less entries that <see cref="GetAttributeClassesIterator" />,
+ /// if one instance implements more than one Attribute interface.
+ /// Signature for Java 1.5: <c>public Iterator<AttributeImpl> getAttributeImplsIterator()</c>
+ /// </summary>
+ public virtual IEnumerable<AttributeImpl> AttributeImpls
+ {
+ get
+ {
+ var initState = GetCurrentState();
+ while (initState != null)
{
- if (state == null)
- throw new KeyNotFoundException();
-
- AttributeImpl att = state.attribute;
- state = state.next;
- return att;
+ var att = initState.attribute;
+ initState = initState.next;
+ yield return att;
}
- }
-
- public AttributeImpl Current
- {
- get { return InternalCurrent; }
- }
-
- public void Dispose()
- {}
-
- object System.Collections.IEnumerator.Current
- {
- get { return InternalCurrent; }
- }
-
- public bool MoveNext()
- {
- return state != null;
- }
-
- public void Reset()
- {
-
- }
- }
-
- /// <summary>a cache that stores all interfaces for known implementation classes for performance (slow reflection) </summary>
- private static readonly SupportClass.WeakHashTable knownImplClasses = new SupportClass.WeakHashTable();
+ }
+ }
- // {{Aroush-2.9 Port issue, need to mimic java's IdentityHashMap
- /*
- * From Java docs:
- * This class implements the Map interface with a hash table, using
- * reference-equality in place of object-equality when comparing keys
- * (and values). In other words, in an IdentityHashMap, two keys k1 and k2
- * are considered equal if and only if (k1==k2). (In normal Map
- * implementations (like HashMap) two keys k1 and k2 are considered
- * equal if and only if (k1==null ? k2==null : k1.equals(k2)).)
- */
- // Aroush-2.9}}
-
- /// <summary>Adds a custom AttributeImpl instance with one or more Attribute interfaces. </summary>
+ /// <summary>a cache that stores all interfaces for known implementation classes for performance (slow reflection) </summary>
+ private static readonly WeakDictionary<Type, System.Collections.Generic.LinkedList<WeakReference>>
+ knownImplClasses = new WeakDictionary<Type, System.Collections.Generic.LinkedList<WeakReference>>();
+
+ /// <summary>
+ /// <b>Expert:</b> Adds a custom AttributeImpl instance with one or more Attribute interfaces.
+ /// <p><font color="red"><b>Please note:</b> It is not guaranteed, that <code>att</code> is added to
+ /// the <code>AttributeSource</code>, because the provided attributes may already exist.
+ /// You should always retrieve the wanted attributes using <see cref="GetAttribute{T}"/> after adding
+ /// with this method and cast to your class.
+ /// The recommended way to use custom implementations is using an <see cref="AttributeFactory"/>
+ /// </font></p>
+ /// </summary>
public virtual void AddAttributeImpl(AttributeImpl att)
{
System.Type clazz = att.GetType();
if (attributeImpls.Contains(clazz))
return ;
- System.Collections.ArrayList foundInterfaces;
+ System.Collections.Generic.LinkedList<WeakReference> foundInterfaces;
lock (knownImplClasses)
{
- foundInterfaces = (System.Collections.ArrayList) knownImplClasses[clazz];
+ foundInterfaces = knownImplClasses[clazz];
if (foundInterfaces == null)
{
// we have a strong reference to the class instance holding all interfaces in the list (parameter "att"),
// so all WeakReferences are never evicted by GC
- knownImplClasses.Add(clazz, foundInterfaces = new System.Collections.ArrayList());
+ knownImplClasses.Add(clazz, foundInterfaces = new LinkedList<WeakReference>());
// find all interfaces that this attribute instance implements
// and that extend the Attribute interface
System.Type actClazz = clazz;
@@ -270,7 +240,7 @@ namespace Lucene.Net.Util
System.Type curInterface = interfaces[i];
if (curInterface != typeof(Attribute) && typeof(Attribute).IsAssignableFrom(curInterface))
{
- foundInterfaces.Add(new WeakReference(curInterface));
+ foundInterfaces.AddLast(new WeakReference(curInterface));
}
}
actClazz = actClazz.BaseType;
@@ -280,20 +250,20 @@ namespace Lucene.Net.Util
}
// add all interfaces of this AttributeImpl to the maps
- for (System.Collections.IEnumerator it = foundInterfaces.GetEnumerator(); it.MoveNext(); )
+ foreach(var curInterfaceRef in foundInterfaces)
{
- WeakReference curInterfaceRef = (WeakReference)it.Current;
System.Type curInterface = (System.Type) curInterfaceRef.Target;
- System.Diagnostics.Debug.Assert(curInterface != null,"We have a strong reference on the class holding the interfaces, so they should never get evicted");
+ System.Diagnostics.Debug.Assert(curInterface != null,
+ "We have a strong reference on the class holding the interfaces, so they should never get evicted");
// Attribute is a superclass of this interface
if (!attributes.ContainsKey(curInterface))
{
// invalidate state to force recomputation in captureState()
this.currentState[0] = null;
- attributes.Add(new SupportClass.AttributeImplItem(curInterface, att));
+ attributes.Add(new AttributeImplItem(curInterface, att));
if (!attributeImpls.ContainsKey(clazz))
{
- attributeImpls.Add(new SupportClass.AttributeImplItem(clazz, att));
+ attributeImpls.Add(new AttributeImplItem(clazz, att));
}
}
}
@@ -303,10 +273,11 @@ namespace Lucene.Net.Util
/// This method first checks if an instance of that class is
/// already in this AttributeSource and returns it. Otherwise a
/// new instance is created, added to this AttributeSource and returned.
- /// Signature for Java 1.5: <c>public <T extends Attribute> T addAttribute(Class<T>)</c>
/// </summary>
- public virtual Attribute AddAttribute(System.Type attClass)
+ // NOTE: Java has Class<T>, .NET has no Type<T>, this is not a perfect port
+ public virtual T AddAttribute<T>() where T : Attribute
{
+ var attClass = typeof (T);
if (!attributes.ContainsKey(attClass))
{
if (!(attClass.IsInterface && typeof(Attribute).IsAssignableFrom(attClass)))
@@ -317,14 +288,10 @@ namespace Lucene.Net.Util
);
}
- AttributeImpl attImpl = this.factory.CreateAttributeInstance(attClass);
- AddAttributeImpl(attImpl);
- return attImpl;
- }
- else
- {
- return attributes[attClass].Value;
+ AddAttributeImpl(this.factory.CreateAttributeInstance<T>());
}
+
+ return (T)(Attribute)attributes[attClass].Value;
}
/// <summary>Returns true, iff this AttributeSource has any attributes </summary>
@@ -335,34 +302,35 @@ namespace Lucene.Net.Util
/// <summary> The caller must pass in a Class<? extends Attribute> value.
/// Returns true, iff this AttributeSource contains the passed-in Attribute.
- /// Signature for Java 1.5: <c>public boolean hasAttribute(Class<? extends Attribute>)</c>
- /// </summary>
- public virtual bool HasAttribute(System.Type attClass)
+ /// </summary>\
+ public virtual bool HasAttribute<T>() where T : Attribute
{
- return this.attributes.Contains(attClass);
+ return this.attributes.Contains(typeof(T));
}
- /// <summary> The caller must pass in a Class<? extends Attribute> value.
+ /// <summary>
+ /// The caller must pass in a Class<? extends Attribute> value.
/// Returns the instance of the passed in Attribute contained in this AttributeSource
- /// Signature for Java 1.5: <c>public <T extends Attribute> T getAttribute(Class<T>)</c>
- ///
/// </summary>
- /// <throws> IllegalArgumentException if this AttributeSource does not contain the </throws>
- /// <summary> Attribute. It is recommended to always use <see cref="AddAttribute" /> even in consumers
+ /// <throws>
+ /// IllegalArgumentException if this AttributeSource does not contain the Attribute.
+ /// It is recommended to always use <see cref="AddAttribute{T}" /> even in consumers
/// of TokenStreams, because you cannot know if a specific TokenStream really uses
- /// a specific Attribute. <see cref="AddAttribute" /> will automatically make the attribute
+ /// a specific Attribute. <see cref="AddAttribute{T}" /> will automatically make the attribute
/// available. If you want to only use the attribute, if it is available (to optimize
- /// consuming), use <see cref="HasAttribute" />.
- /// </summary>
- public virtual Attribute GetAttribute(System.Type attClass)
+ /// consuming), use <see cref="HasAttribute" />.
+ /// </throws>
+ // NOTE: Java has Class<T>, .NET has no Type<T>, this is not a perfect port
+ public virtual T GetAttribute<T>() where T : Attribute
{
+ var attClass = typeof (T);
if (!this.attributes.ContainsKey(attClass))
{
throw new System.ArgumentException("This AttributeSource does not have the attribute '" + attClass.FullName + "'.");
}
else
{
- return this.attributes[attClass].Value;
+ return (T)(Attribute)this.attributes[attClass].Value;
}
}
@@ -389,19 +357,19 @@ namespace Lucene.Net.Util
return clone;
}
}
-
- private State GetCurrentState()
- {
- State s = currentState[0];
+
+ private State GetCurrentState()
+ {
+ var s = currentState[0];
if (s != null || !HasAttributes())
{
return s;
}
- State c = s = currentState[0] = new State();
- var it = attributeImpls.Values().GetEnumerator();
- it.MoveNext();
- c.attribute = it.Current.Value;
+ var c = s = currentState[0] = new State();
+ var it = attributeImpls.Values().GetEnumerator();
+ it.MoveNext();
+ c.attribute = it.Current.Value;
while (it.MoveNext())
{
@@ -410,27 +378,26 @@ namespace Lucene.Net.Util
c.attribute = it.Current.Value;
}
- return s;
-
- }
+ return s;
+ }
- /// <summary> Resets all Attributes in this AttributeSource by calling
+ /// <summary> Resets all Attributes in this AttributeSource by calling
/// <see cref="AttributeImpl.Clear()" /> on each Attribute implementation.
/// </summary>
public virtual void ClearAttributes()
{
- for (State state = GetCurrentState(); state != null; state = state.next)
- {
- state.attribute.Clear();
- }
- }
+ for (var state = GetCurrentState(); state != null; state = state.next)
+ {
+ state.attribute.Clear();
+ }
+ }
/// <summary> Captures the state of all Attributes. The return value can be passed to
/// <see cref="RestoreState" /> to restore the state of this or another AttributeSource.
/// </summary>
public virtual State CaptureState()
{
- State state = this.GetCurrentState();
+ var state = this.GetCurrentState();
return (state == null) ? null : (State) state.Clone();
}
@@ -467,14 +434,15 @@ namespace Lucene.Net.Util
public override int GetHashCode()
{
- int code = 0;
- for (State state = GetCurrentState(); state != null; state = state.next)
+ var code = 0;
+
+ for (var state = GetCurrentState(); state != null; state = state.next)
{
code = code*31 + state.attribute.GetHashCode();
}
- return code;
- }
+ return code;
+ }
public override bool Equals(System.Object obj)
{
@@ -500,9 +468,9 @@ namespace Lucene.Net.Util
}
// it is only equal if all attribute impls are the same in the same order
- State thisState = this.GetCurrentState();
- State otherState = other.GetCurrentState();
- while (thisState != null && otherState != null)
+ var thisState = this.GetCurrentState();
+ var otherState = other.GetCurrentState();
+ while (thisState != null && otherState != null)
{
if (otherState.attribute.GetType() != thisState.attribute.GetType() || !otherState.attribute.Equals(thisState.attribute))
{
@@ -524,24 +492,22 @@ namespace Lucene.Net.Util
public override System.String ToString()
{
- System.Text.StringBuilder sb = new System.Text.StringBuilder();
- sb.Append('(');
+ System.Text.StringBuilder sb = new System.Text.StringBuilder().Append('(');
if (HasAttributes())
{
if (currentState[0] == null)
{
- currentState[0] = GetCurrentState();
+ currentState[0] = GetCurrentState();
}
- for (State state = currentState[0]; state != null; state = state.next)
+ for (var state = currentState[0]; state != null; state = state.next)
{
if (state != currentState[0])
sb.Append(',');
sb.Append(state.attribute.ToString());
}
}
- sb.Append(')');
- return sb.ToString();
+ return sb.Append(')').ToString();
}
/// <summary> Performs a clone of all <see cref="AttributeImpl" /> instances returned in a new
@@ -550,26 +516,26 @@ namespace Lucene.Net.Util
/// </summary>
public virtual AttributeSource CloneAttributes()
{
- AttributeSource clone = new AttributeSource(this.factory);
+ var clone = new AttributeSource(this.factory);
// first clone the impls
if (HasAttributes())
{
- for (State state = GetCurrentState() ; state != null; state = state.next)
- {
- AttributeImpl impl = (AttributeImpl) state.attribute.Clone();
+ for (var state = GetCurrentState(); state != null; state = state.next)
+ {
+ var impl = (AttributeImpl) state.attribute.Clone();
if (!clone.attributeImpls.ContainsKey(impl.GetType()))
{
- clone.attributeImpls.Add(new SupportClass.AttributeImplItem(impl.GetType(), impl));
+ clone.attributeImpls.Add(new AttributeImplItem(impl.GetType(), impl));
}
}
}
// now the interfaces
- foreach (SupportClass.AttributeImplItem att in this.attributes)
+ foreach (var att in this.attributes)
{
- clone.attributes.Add(new SupportClass.AttributeImplItem(att.Key, clone.attributeImpls[att.Value.GetType()].Value));
+ clone.attributes.Add(new AttributeImplItem(att.Key, clone.attributeImpls[att.Value.GetType()].Value));
}
return clone;
Modified: incubator/lucene.net/trunk/src/core/Util/AverageGuessMemoryModel.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/AverageGuessMemoryModel.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/AverageGuessMemoryModel.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/AverageGuessMemoryModel.cs Tue Feb 28 22:43:08 2012
@@ -25,64 +25,28 @@ namespace Lucene.Net.Util
/// </summary>
public class AverageGuessMemoryModel:MemoryModel
{
- public AverageGuessMemoryModel()
- {
- InitBlock();
- }
- internal class AnonymousClassIdentityHashMap : System.Collections.Hashtable /*IdentityHashMap*/ // {{Aroush-2.9.0}} Port issue? Will this do the trick to mimic java's IdentityHashMap?
- {
- public AnonymousClassIdentityHashMap(AverageGuessMemoryModel enclosingInstance)
- {
- InitBlock(enclosingInstance);
- }
- private void InitBlock(AverageGuessMemoryModel enclosingInstance)
- {
- this.enclosingInstance = enclosingInstance;
- Add(typeof(bool), 1);
- Add(typeof(byte), 1);
- Add(typeof(sbyte), 1);
- Add(typeof(char), 2);
- Add(typeof(short), 2);
- Add(typeof(int), 4);
- Add(typeof(float), 4);
- Add(typeof(double), 8);
- Add(typeof(long), 8);
- }
- private AverageGuessMemoryModel enclosingInstance;
- public AverageGuessMemoryModel Enclosing_Instance
- {
- get
- {
- return enclosingInstance;
- }
-
- }
- // {{Aroush-2.9.0}} Port issue? Will this do the trick to mimic java's IdentityHashMap?
- /*
- * From Java docs:
- * This class implements the Map interface with a hash table, using
- * reference-equality in place of object-equality when comparing keys
- * (and values). In other words, in an IdentityHashMap, two keys k1 and k2
- * are considered equal if and only if (k1==k2). (In normal Map
- * implementations (like HashMap) two keys k1 and k2 are considered
- * equal if and only if (k1==null ? k2==null : k1.equals(k2)).)
- */
- public new bool Equals(Object obj)
- {
- return this.GetHashCode() == obj.GetHashCode();
- }
- public new static bool Equals(Object objA, Object objB)
- {
- return objA.GetHashCode() == objB.GetHashCode();
- }
- // {{Aroush-2.9.0}} Port issue, need to mimic java's IdentityHashMap
- }
- private void InitBlock()
- {
- sizes = new AnonymousClassIdentityHashMap(this);
- }
+ public AverageGuessMemoryModel()
+ {
+ InitBlock();
+ }
+
+ private void InitBlock()
+ {
+ sizes = new IdentityDictionary<Type, int>()
+ {
+ {typeof (bool), 1},
+ {typeof (byte), 1},
+ {typeof(sbyte), 1},
+ {typeof (char), 2},
+ {typeof (short), 2},
+ {typeof (int), 4},
+ {typeof (float), 4},
+ {typeof (double), 8},
+ {typeof (long), 8}
+ };
+ }
// best guess primitive sizes
- private System.Collections.IDictionary sizes;
+ private System.Collections.Generic.Dictionary<Type, int> sizes;
/*
* (non-Javadoc)
@@ -109,7 +73,7 @@ namespace Lucene.Net.Util
*/
public override int GetPrimitiveSize(System.Type clazz)
{
- return ((System.Int32) sizes[clazz]);
+ return sizes[clazz];
}
/* (non-Javadoc)
Modified: incubator/lucene.net/trunk/src/core/Util/BitUtil.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/BitUtil.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/BitUtil.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/BitUtil.cs Tue Feb 28 22:43:08 2012
@@ -16,6 +16,7 @@
*/
using System;
+using Lucene.Net.Support;
namespace Lucene.Net.Util
{
@@ -46,12 +47,12 @@ namespace Lucene.Net.Util
***/
// 64 bit java version of the C function from above
- x = x - ((SupportClass.Number.URShift(x, 1)) & 0x5555555555555555L);
- x = (x & 0x3333333333333333L) + ((SupportClass.Number.URShift(x, 2)) & 0x3333333333333333L);
- x = (x + (SupportClass.Number.URShift(x, 4))) & 0x0F0F0F0F0F0F0F0FL;
- x = x + (SupportClass.Number.URShift(x, 8));
- x = x + (SupportClass.Number.URShift(x, 16));
- x = x + (SupportClass.Number.URShift(x, 32));
+ x = x - ((Number.URShift(x, 1)) & 0x5555555555555555L);
+ x = (x & 0x3333333333333333L) + ((Number.URShift(x, 2)) & 0x3333333333333333L);
+ x = (x + (Number.URShift(x, 4))) & 0x0F0F0F0F0F0F0F0FL;
+ x = x + (Number.URShift(x, 8));
+ x = x + (Number.URShift(x, 16));
+ x = x + (Number.URShift(x, 32));
return ((int) x) & 0x7F;
}
@@ -726,15 +727,15 @@ namespace Lucene.Net.Util
if (lower != 0)
{
- lowByte = (SupportClass.Number.URShift(lower, 8)) & 0xff;
+ lowByte = (Number.URShift(lower, 8)) & 0xff;
if (lowByte != 0)
return ntzTable[lowByte] + 8;
- lowByte = (SupportClass.Number.URShift(lower, 16)) & 0xff;
+ lowByte = (Number.URShift(lower, 16)) & 0xff;
if (lowByte != 0)
return ntzTable[lowByte] + 16;
// no need to mask off low byte for the last byte in the 32 bit word
// no need to check for zero on the last byte either.
- return ntzTable[SupportClass.Number.URShift(lower, 24)] + 24;
+ return ntzTable[Number.URShift(lower, 24)] + 24;
}
else
{
@@ -743,15 +744,15 @@ namespace Lucene.Net.Util
lowByte = upper & 0xff;
if (lowByte != 0)
return ntzTable[lowByte] + 32;
- lowByte = (SupportClass.Number.URShift(upper, 8)) & 0xff;
+ lowByte = (Number.URShift(upper, 8)) & 0xff;
if (lowByte != 0)
return ntzTable[lowByte] + 40;
- lowByte = (SupportClass.Number.URShift(upper, 16)) & 0xff;
+ lowByte = (Number.URShift(upper, 16)) & 0xff;
if (lowByte != 0)
return ntzTable[lowByte] + 48;
// no need to mask off low byte for the last byte in the 32 bit word
// no need to check for zero on the last byte either.
- return ntzTable[SupportClass.Number.URShift(upper, 24)] + 56;
+ return ntzTable[Number.URShift(upper, 24)] + 56;
}
}
@@ -765,15 +766,15 @@ namespace Lucene.Net.Util
int lowByte = val & 0xff;
if (lowByte != 0)
return ntzTable[lowByte];
- lowByte = (SupportClass.Number.URShift(val, 8)) & 0xff;
+ lowByte = (Number.URShift(val, 8)) & 0xff;
if (lowByte != 0)
return ntzTable[lowByte] + 8;
- lowByte = (SupportClass.Number.URShift(val, 16)) & 0xff;
+ lowByte = (Number.URShift(val, 16)) & 0xff;
if (lowByte != 0)
return ntzTable[lowByte] + 16;
// no need to mask off low byte for the last byte.
// no need to check for zero on the last byte either.
- return ntzTable[SupportClass.Number.URShift(val, 24)] + 24;
+ return ntzTable[Number.URShift(val, 24)] + 24;
}
/// <summary>returns 0 based index of first set bit
@@ -786,15 +787,15 @@ namespace Lucene.Net.Util
int y = (int) x;
if (y == 0)
{
- n += 32; y = (int) (SupportClass.Number.URShift(x, 32));
+ n += 32; y = (int) (Number.URShift(x, 32));
} // the only 64 bit shift necessary
if ((y & 0x0000FFFF) == 0)
{
- n += 16; y = SupportClass.Number.URShift(y, 16);
+ n += 16; y = Number.URShift(y, 16);
}
if ((y & 0x000000FF) == 0)
{
- n += 8; y = SupportClass.Number.URShift(y, 8);
+ n += 8; y = Number.URShift(y, 8);
}
return (ntzTable[y & 0xff]) + n;
}
@@ -813,23 +814,23 @@ namespace Lucene.Net.Util
int y = (int) x;
if (y == 0)
{
- n += 32; y = (int) (SupportClass.Number.URShift(x, 32));
+ n += 32; y = (int) (Number.URShift(x, 32));
}
if ((y & 0x0000FFFF) == 0)
{
- n += 16; y = SupportClass.Number.URShift(y, 16);
+ n += 16; y = Number.URShift(y, 16);
}
if ((y & 0x000000FF) == 0)
{
- n += 8; y = SupportClass.Number.URShift(y, 8);
+ n += 8; y = Number.URShift(y, 8);
}
if ((y & 0x0000000F) == 0)
{
- n += 4; y = SupportClass.Number.URShift(y, 4);
+ n += 4; y = Number.URShift(y, 4);
}
if ((y & 0x00000003) == 0)
{
- n += 2; y = SupportClass.Number.URShift(y, 2);
+ n += 2; y = Number.URShift(y, 2);
}
return n - (y & 1);
}
Modified: incubator/lucene.net/trunk/src/core/Util/BitVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/BitVector.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/BitVector.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/BitVector.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
*/
using System;
-
+using Lucene.Net.Support;
using Directory = Lucene.Net.Store.Directory;
using IndexInput = Lucene.Net.Store.IndexInput;
using IndexOutput = Lucene.Net.Store.IndexOutput;
@@ -33,9 +33,7 @@ namespace Lucene.Net.Util
/// <item>store and load, as bit set or d-gaps, depending on sparseness;</item>
/// </list>
/// </summary>
- /// <version> $Id: BitVector.java 765649 2009-04-16 14:29:26Z mikemccand $
- /// </version>
- public sealed class BitVector : System.ICloneable
+ public sealed class BitVector : ICloneable
{
private byte[] bits;
@@ -300,13 +298,13 @@ namespace Lucene.Net.Util
// Special case -- return empty vector is start == end
if (end == start)
return new BitVector(0);
- byte[] bits = new byte[(SupportClass.Number.URShift((end - start - 1), 3)) + 1];
- int s = SupportClass.Number.URShift(start, 3);
+ byte[] bits = new byte[(Number.URShift((end - start - 1), 3)) + 1];
+ int s = Number.URShift(start, 3);
for (int i = 0; i < bits.Length; i++)
{
int cur = 0xFF & this.bits[i + s];
int next = i + s + 1 >= this.bits.Length?0:0xFF & this.bits[i + s + 1];
- bits[i] = (byte) ((SupportClass.Number.URShift(cur, (start & 7))) | ((next << (8 - (start & 7)))));
+ bits[i] = (byte) ((Number.URShift(cur, (start & 7))) | ((next << (8 - (start & 7)))));
}
int bitsToClear = (bits.Length * 8 - (end - start)) % 8;
bits[bits.Length - 1] &= (byte) (~ (0xFF << (8 - bitsToClear)));
Modified: incubator/lucene.net/trunk/src/core/Util/Cache/Cache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/Cache/Cache.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/Cache/Cache.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/Cache/Cache.cs Tue Feb 28 22:43:08 2012
@@ -22,30 +22,30 @@ namespace Lucene.Net.Util.Cache
/// <summary> Base class for cache implementations.</summary>
- public abstract class Cache
+ public abstract class Cache<TKey, TValue> : IDisposable
{
/// <summary> Simple Cache wrapper that synchronizes all
/// calls that access the cache.
/// </summary>
- internal class SynchronizedCache_Renamed_Class:Cache
+ internal class SynchronizedCache_Renamed_Class : Cache<TKey, TValue>
{
internal System.Object mutex;
- internal Cache cache;
-
- internal SynchronizedCache_Renamed_Class(Cache cache)
+ internal Cache<TKey,TValue> cache;
+
+ internal SynchronizedCache_Renamed_Class(Cache<TKey, TValue> cache)
{
this.cache = cache;
this.mutex = this;
}
-
- internal SynchronizedCache_Renamed_Class(Cache cache, System.Object mutex)
+
+ internal SynchronizedCache_Renamed_Class(Cache<TKey, TValue> cache, System.Object mutex)
{
this.cache = cache;
this.mutex = mutex;
}
- public override void Put(System.Object key, System.Object value_Renamed)
+ public override void Put(TKey key, TValue value_Renamed)
{
lock (mutex)
{
@@ -53,7 +53,7 @@ namespace Lucene.Net.Util.Cache
}
}
- public override System.Object Get(System.Object key)
+ public override TValue Get(System.Object key)
{
lock (mutex)
{
@@ -69,15 +69,15 @@ namespace Lucene.Net.Util.Cache
}
}
- public override void Close()
- {
- lock (mutex)
- {
- cache.Close();
- }
- }
+ protected override void Dispose(bool disposing)
+ {
+ lock (mutex)
+ {
+ cache.Dispose();
+ }
+ }
- internal override Cache GetSynchronizedCache()
+ internal override Cache<TKey,TValue> GetSynchronizedCache()
{
return this;
}
@@ -87,32 +87,43 @@ namespace Lucene.Net.Util.Cache
/// In order to guarantee thread-safety, all access to the backed cache must
/// be accomplished through the returned cache.
/// </summary>
- public static Cache SynchronizedCache(Cache cache)
+ public static Cache<TKey, TValue> SynchronizedCache(Cache<TKey, TValue> cache)
{
return cache.GetSynchronizedCache();
}
- /// <summary> Called by <see cref="SynchronizedCache(Cache)" />. This method
+ /// <summary> Called by <see cref="SynchronizedCache(Cache{TKey,TValue})" />. This method
/// returns a <see cref="SynchronizedCache" /> instance that wraps
/// this instance by default and can be overridden to return
/// e. g. subclasses of <see cref="SynchronizedCache" /> or this
/// in case this cache is already synchronized.
/// </summary>
- internal virtual Cache GetSynchronizedCache()
+ internal virtual Cache<TKey, TValue> GetSynchronizedCache()
{
- return new SynchronizedCache_Renamed_Class(this);
+ return new SynchronizedCache_Renamed_Class(this);
}
/// <summary> Puts a (key, value)-pair into the cache. </summary>
- public abstract void Put(System.Object key, System.Object value_Renamed);
+ public abstract void Put(TKey key, TValue value_Renamed);
/// <summary> Returns the value for the given key. </summary>
- public abstract System.Object Get(System.Object key);
+ public abstract TValue Get(System.Object key);
/// <summary> Returns whether the given key is in this cache. </summary>
public abstract bool ContainsKey(System.Object key);
-
- /// <summary> Closes the cache.</summary>
- public abstract void Close();
+
+ /// <summary> Closes the cache.</summary>
+ [Obsolete("Use Dispose() instead")]
+ public void Close()
+ {
+ Dispose();
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ protected abstract void Dispose(bool disposing);
}
}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/src/core/Util/Cache/SimpleLRUCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/Cache/SimpleLRUCache.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/Cache/SimpleLRUCache.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/Cache/SimpleLRUCache.cs Tue Feb 28 22:43:08 2012
@@ -20,7 +20,7 @@ using System.Collections.Generic;
namespace Lucene.Net.Util.Cache
{
- public class SimpleLRUCache : SimpleMapCache
+ public class SimpleLRUCache<TKey, TValue> : SimpleMapCache<TKey, TValue>
{
/// <summary>
/// The maximum number of items to cache.
@@ -30,27 +30,27 @@ namespace Lucene.Net.Util.Cache
/// <summary>
/// The list to efficiently maintain the LRU state.
/// </summary>
- private LinkedList<ListValueEntry> list;
+ private LinkedList<ListValueEntry<TKey, TValue>> list;
/// <summary>
/// The dictionary to hash into any location in the list.
/// </summary>
- private Dictionary<object, LinkedListNode<ListValueEntry>> lookup;
+ private Dictionary<TKey, LinkedListNode<ListValueEntry<TKey, TValue>>> lookup;
/// <summary>
/// The node instance to use/re-use when adding an item to the cache.
/// </summary>
- private LinkedListNode<ListValueEntry> openNode;
+ private LinkedListNode<ListValueEntry<TKey, TValue>> openNode;
public SimpleLRUCache(int Capacity)
{
this.capacity = Capacity;
- this.list = new LinkedList<ListValueEntry>();
- this.lookup = new Dictionary<object, LinkedListNode<ListValueEntry>>(Capacity + 1);
- this.openNode = new LinkedListNode<ListValueEntry>(new ListValueEntry(null, null));
+ this.list = new LinkedList<ListValueEntry<TKey, TValue>>();
+ this.lookup = new Dictionary<TKey, LinkedListNode<ListValueEntry<TKey, TValue>>>(Capacity + 1);
+ this.openNode = new LinkedListNode<ListValueEntry<TKey, TValue>>(new ListValueEntry<TKey, TValue>(default(TKey), default(TValue)));
}
- public override void Put(object Key, object Value)
+ public override void Put(TKey Key, TValue Value)
{
if (Get(Key) == null)
{
@@ -71,17 +71,17 @@ namespace Lucene.Net.Util.Cache
else
{
// still filling the cache, create a new open node for the next time
- this.openNode = new LinkedListNode<ListValueEntry>(new ListValueEntry(null, null));
+ this.openNode = new LinkedListNode<ListValueEntry<TKey, TValue>>(new ListValueEntry<TKey, TValue>(default(TKey), default(TValue)));
}
}
}
- public override object Get(object Key)
+ public override TValue Get(object Key)
{
- LinkedListNode<ListValueEntry> node = null;
- if(!this.lookup.TryGetValue(Key, out node))
+ LinkedListNode<ListValueEntry<TKey, TValue>> node = null;
+ if (!this.lookup.TryGetValue((TKey)Key, out node))
{
- return null;
+ return default(TValue);
}
this.list.Remove(node);
this.list.AddFirst(node);
@@ -92,12 +92,13 @@ namespace Lucene.Net.Util.Cache
/// Container to hold the key and value to aid in removal from
/// the <see cref="lookup"/> dictionary when an item is removed from cache.
/// </summary>
- class ListValueEntry
+ class ListValueEntry<K, V> where K : TKey
+ where V : TValue
{
- internal object ItemValue;
- internal object ItemKey;
+ internal V ItemValue;
+ internal K ItemKey;
- internal ListValueEntry(object key, object value)
+ internal ListValueEntry(K key, V value)
{
this.ItemKey = key;
this.ItemValue = value;
Modified: incubator/lucene.net/trunk/src/core/Util/Cache/SimpleMapCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/Cache/SimpleMapCache.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/Cache/SimpleMapCache.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/Cache/SimpleMapCache.cs Tue Feb 28 22:43:08 2012
@@ -16,6 +16,7 @@
*/
using System;
+using System.Collections.Generic;
namespace Lucene.Net.Util.Cache
{
@@ -24,62 +25,66 @@ namespace Lucene.Net.Util.Cache
/// This cache is not synchronized, use <see cref="Cache.SynchronizedCache(Cache)" />
/// if needed.
/// </summary>
- public class SimpleMapCache:Cache
+ public class SimpleMapCache<TKey, TValue> : Cache<TKey, TValue>
{
- internal System.Collections.IDictionary map;
-
- public SimpleMapCache():this(new System.Collections.Hashtable())
+ internal System.Collections.Generic.Dictionary<TKey, TValue> map;
+
+ public SimpleMapCache()
+ : this(new System.Collections.Generic.Dictionary<TKey, TValue>())
{
}
-
- public SimpleMapCache(System.Collections.IDictionary map)
+
+ public SimpleMapCache(System.Collections.Generic.Dictionary<TKey, TValue> map)
{
this.map = map;
}
- public override System.Object Get(System.Object key)
+ public override TValue Get(System.Object key)
{
- return map[key];
+ return map[(TKey)key];
}
- public override void Put(System.Object key, System.Object value_Renamed)
+ public override void Put(TKey key, TValue value_Renamed)
{
map[key] = value_Renamed;
}
- public override void Close()
- {
- // NOOP
- }
-
public override bool ContainsKey(System.Object key)
{
- return map.Contains(key);
+ return map.ContainsKey((TKey)key);
}
-
- /// <summary> Returns a Set containing all keys in this cache.</summary>
- public virtual System.Collections.ICollection KeySet()
+
+ protected override void Dispose(bool disposing)
+ {
+ // do nothing
+ }
+
+ /// <summary> Returns a Set containing all keys in this cache.</summary>
+ public virtual System.Collections.Generic.HashSet<TKey> KeySet()
{
- return map.Keys;
+ return new HashSet<TKey>(map.Keys);
}
- internal override Cache GetSynchronizedCache()
+ internal override Cache<TKey, TValue> GetSynchronizedCache()
{
return new SynchronizedSimpleMapCache(this);
}
- private class SynchronizedSimpleMapCache:SimpleMapCache
+ // Why does does this use both inheritance and composition?
+ private class SynchronizedSimpleMapCache : SimpleMapCache<TKey, TValue>
{
- internal System.Object mutex;
- internal SimpleMapCache cache;
-
- internal SynchronizedSimpleMapCache(SimpleMapCache cache)
+ private System.Object mutex;
+ private SimpleMapCache<TKey, TValue> cache;
+
+ private bool isDisposed;
+
+ internal SynchronizedSimpleMapCache(SimpleMapCache<TKey, TValue> cache)
{
this.cache = cache;
this.mutex = this;
}
- public override void Put(System.Object key, System.Object value_Renamed)
+ public override void Put(TKey key, TValue value_Renamed)
{
lock (mutex)
{
@@ -87,7 +92,7 @@ namespace Lucene.Net.Util.Cache
}
}
- public override System.Object Get(System.Object key)
+ public override TValue Get(System.Object key)
{
lock (mutex)
{
@@ -103,15 +108,23 @@ namespace Lucene.Net.Util.Cache
}
}
- public override void Close()
+ protected override void Dispose(bool disposing)
{
lock (mutex)
{
- cache.Close();
+ if (isDisposed) return;
+
+ if (disposing)
+ {
+ cache.Dispose(disposing);
+ }
+
+ isDisposed = true;
+ base.Dispose(disposing);
}
}
- public override System.Collections.ICollection KeySet()
+ public override HashSet<TKey> KeySet()
{
lock (mutex)
{
@@ -119,7 +132,7 @@ namespace Lucene.Net.Util.Cache
}
}
- internal override Cache GetSynchronizedCache()
+ internal override Cache<TKey, TValue> GetSynchronizedCache()
{
return this;
}
Modified: incubator/lucene.net/trunk/src/core/Util/CloseableThreadLocal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/CloseableThreadLocal.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/CloseableThreadLocal.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/CloseableThreadLocal.cs Tue Feb 28 22:43:08 2012
@@ -17,7 +17,9 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Threading;
+using Lucene.Net.Support;
namespace Lucene.Net.Util
{
@@ -44,24 +46,26 @@ namespace Lucene.Net.Util
/// </summary>
///
- public class CloseableThreadLocal
+ public class CloseableThreadLocal<T> : IDisposable where T : class
{
+ // NOTE: Java has WeakReference<T>. This isn't available for .Net until 4.5 (according to msdn docs)
private ThreadLocal<WeakReference> t = new ThreadLocal<WeakReference>();
- private Dictionary<Thread, object> hardRefs = new Dictionary<Thread, object>();
+ private IDictionary<Thread, T> hardRefs = new HashMap<Thread, T>();
+ private bool isDisposed;
- public virtual object InitialValue()
+ public virtual T InitialValue()
{
return null;
}
- public virtual object Get()
+ public virtual T Get()
{
WeakReference weakRef = t.Get();
if (weakRef == null)
{
- object iv = InitialValue();
+ T iv = InitialValue();
if (iv != null)
{
Set(iv);
@@ -72,18 +76,18 @@ namespace Lucene.Net.Util
}
else
{
- return weakRef.Get();
+ return (T)weakRef.Get();
}
}
- public virtual void Set(object @object)
+ public virtual void Set(T @object)
{
//+-- For Debuging
- if (SupportClass.CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler == true)
+ if (CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler == true)
{
- lock (SupportClass.CloseableThreadLocalProfiler.Instances)
+ lock (CloseableThreadLocalProfiler.Instances)
{
- SupportClass.CloseableThreadLocalProfiler.Instances.Add(new WeakReference(@object));
+ CloseableThreadLocalProfiler.Instances.Add(new WeakReference(@object));
}
}
//+--
@@ -94,30 +98,48 @@ namespace Lucene.Net.Util
{
//hardRefs[Thread.CurrentThread] = @object;
hardRefs.Add(Thread.CurrentThread, @object);
-
+
+ // Java's iterator can remove, .NET's cannot
+ var threadsToRemove = hardRefs.Keys.Where(thread => !thread.IsAlive).ToList();
// Purge dead threads
- foreach (var thread in new List<Thread>(hardRefs.Keys))
+ foreach (var thread in threadsToRemove)
{
- if (!thread.IsAlive)
- hardRefs.Remove(thread);
+ hardRefs.Remove(thread);
}
-
}
}
+ [Obsolete("Use Dispose() instead")]
public virtual void Close()
{
- // Clear the hard refs; then, the only remaining refs to
- // all values we were storing are weak (unless somewhere
- // else is still using them) and so GC may reclaim them:
- hardRefs = null;
- // Take care of the current thread right now; others will be
- // taken care of via the WeakReferences.
- if (t != null)
+ Dispose();
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (isDisposed) return;
+
+ if (disposing)
{
- t.Remove();
+ // Clear the hard refs; then, the only remaining refs to
+ // all values we were storing are weak (unless somewhere
+ // else is still using them) and so GC may reclaim them:
+ hardRefs = null;
+ // Take care of the current thread right now; others will be
+ // taken care of via the WeakReferences.
+ if (t != null)
+ {
+ t.Remove();
+ }
+ t = null;
}
- t = null;
+
+ isDisposed = true;
}
}
Modified: incubator/lucene.net/trunk/src/core/Util/Constants.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Util/Constants.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Util/Constants.cs (original)
+++ incubator/lucene.net/trunk/src/core/Util/Constants.cs Tue Feb 28 22:43:08 2012
@@ -16,20 +16,13 @@
*/
using System;
-
+using Lucene.Net.Support;
using LucenePackage = Lucene.Net.LucenePackage;
namespace Lucene.Net.Util
{
- /// <summary> Some useful constants.
- ///
- ///
- /// </summary>
- /// <version> $Id: Constants.java 828327 2009-10-22 06:47:40Z uschindler $
- ///
- /// </version>
-
+ /// <summary> Some useful constants.</summary>
public sealed class Constants
{
private Constants()
@@ -37,7 +30,7 @@ namespace Lucene.Net.Util
} // can't construct
/// <summary>The value of <tt>System.getProperty("java.version")</tt>. *</summary>
- public static readonly System.String JAVA_VERSION = SupportClass.AppSettings.Get("java.version", "");
+ public static readonly System.String JAVA_VERSION = AppSettings.Get("java.version", "");
/// <summary>True iff this is Java version 1.1. </summary>
public static readonly bool JAVA_1_1 = JAVA_VERSION.StartsWith("1.1.");
/// <summary>True iff this is Java version 1.2. </summary>
@@ -56,7 +49,7 @@ namespace Lucene.Net.Util
public static readonly System.String OS_ARCH = GetEnvironmentVariable("PROCESSOR_ARCHITECTURE","x86");
public static readonly System.String OS_VERSION = GetEnvironmentVariable("OS_VERSION", "?");
- public static readonly System.String JAVA_VENDOR = SupportClass.AppSettings.Get("java.vendor", "");
+ public static readonly System.String JAVA_VENDOR = AppSettings.Get("java.vendor", "");
// NOTE: this logic may not be correct; if you know of a
// more reliable approach please raise it on java-dev!
@@ -70,7 +63,7 @@ namespace Lucene.Net.Util
return s.ToString();
}
- public static readonly System.String LUCENE_MAIN_VERSION = Ident("2.9.4");
+ public static readonly System.String LUCENE_MAIN_VERSION = Ident("3.0.3");
public static System.String LUCENE_VERSION="8.8.8.8";
static Constants()