lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnas...@apache.org
Subject [1/5] Most of Lucene.Net.Codecs/SimpleText ported - still a little bit of work around DecimalFormat conversion
Date Sun, 28 Sep 2014 02:32:07 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 5506faf0c -> 3b226e8bf


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/07150be0/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
index 6f2c9ea..dc8e318 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
@@ -20,6 +20,7 @@ namespace Lucene.Net.Codecs.SimpleText
 
     using System;
     using System.Diagnostics;
+    using Support;
 
 	using FieldInfo = Index.FieldInfo;
 	using FieldInfos = Index.FieldInfos;
@@ -39,239 +40,238 @@ namespace Lucene.Net.Codecs.SimpleText
 	using StringHelper = Util.StringHelper;
 	using UnicodeUtil = Util.UnicodeUtil;
 
-//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted
to .NET:
-	import static Lucene.Net.Codecs.SimpleText.SimpleTextStoredFieldsWriter.*;
+    /// <summary>
+    /// reads plaintext stored fields
+    /// <para>
+    /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+    /// @lucene.experimental
+    /// </para>
+    /// </summary>
+    public class SimpleTextStoredFieldsReader : StoredFieldsReader
+    {
+        private long[] _offsets; // docid -> offset in .fld file
+        private IndexInput _input;
+        private readonly BytesRef _scratch = new BytesRef();
+        private readonly CharsRef _scratchUtf16 = new CharsRef();
+        private readonly FieldInfos _fieldInfos;
 
-	/// <summary>
-	/// reads plaintext stored fields
-	/// <para>
-	/// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
-	/// @lucene.experimental
-	/// </para>
-	/// </summary>
-	public class SimpleTextStoredFieldsReader : StoredFieldsReader
-	{
-	  private long[] offsets; // docid -> offset in .fld file
-	  private IndexInput @in;
-	  private BytesRef scratch = new BytesRef();
-	  private CharsRef scratchUTF16 = new CharsRef();
-	  private readonly FieldInfos fieldInfos;
+        public SimpleTextStoredFieldsReader(Directory directory, SegmentInfo si, FieldInfos
fn, IOContext context)
+        {
+            _fieldInfos = fn;
+            var success = false;
+            try
+            {
+                _input =
+                    directory.OpenInput(
+                        IndexFileNames.SegmentFileName(si.Name, "", SimpleTextStoredFieldsWriter.FIELDS_EXTENSION),
+                        context);
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    try
+                    {
+                        Dispose();
+                    } 
+                    catch
+                    {
+                        // ensure we throw our original exception
+                    }
+                }
+            }
+            ReadIndex(si.DocCount);
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public SimpleTextStoredFieldsReader(store.Directory directory, index.SegmentInfo
si, index.FieldInfos fn, store.IOContext context) throws java.io.IOException
-	  public SimpleTextStoredFieldsReader(Directory directory, SegmentInfo si, FieldInfos fn,
IOContext context)
-	  {
-		this.fieldInfos = fn;
-		bool success = false;
-		try
-		{
-		  @in = directory.openInput(IndexFileNames.segmentFileName(si.name, "", SimpleTextStoredFieldsWriter.FIELDS_EXTENSION),
context);
-		  success = true;
-		}
-		finally
-		{
-		  if (!success)
-		  {
-			try
-			{
-			  close();
-			} // ensure we throw our original exception
-			catch (Exception)
-			{
-			}
-		  }
-		}
-		readIndex(si.DocCount);
-	  }
+        /// <remarks>Used by clone</remarks>
+        internal SimpleTextStoredFieldsReader(long[] offsets, IndexInput input, FieldInfos
fieldInfos)
+        {
+            _offsets = offsets;
+            _input = input;
+            _fieldInfos = fieldInfos;
+        }
 
-	  // used by clone
-	  internal SimpleTextStoredFieldsReader(long[] offsets, IndexInput @in, FieldInfos fieldInfos)
-	  {
-		this.offsets = offsets;
-		this.@in = @in;
-		this.fieldInfos = fieldInfos;
-	  }
+        /// <remarks>
+        /// we don't actually write a .fdx-like index, instead we read the 
+        /// stored fields file in entirety up-front and save the offsets 
+        /// so we can seek to the documents later.
+        /// </remarks>
+        private void ReadIndex(int size)
+        {
+            ChecksumIndexInput input = new BufferedChecksumIndexInput(_input);
+            _offsets = new long[size];
+            var upto = 0;
+            while (!_scratch.Equals(SimpleTextStoredFieldsWriter.END))
+            {
+                SimpleTextUtil.ReadLine(input, _scratch);
+                if (StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.DOC))
+                {
+                    _offsets[upto] = input.FilePointer;
+                    upto++;
+                }
+            }
+            SimpleTextUtil.CheckFooter(input);
+            Debug.Assert(upto == _offsets.Length);
+        }
 
-	  // we don't actually write a .fdx-like index, instead we read the 
-	  // stored fields file in entirety up-front and save the offsets 
-	  // so we can seek to the documents later.
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private void readIndex(int size) throws java.io.IOException
-	  private void readIndex(int size)
-	  {
-		ChecksumIndexInput input = new BufferedChecksumIndexInput(@in);
-		offsets = new long[size];
-		int upto = 0;
-		while (!scratch.Equals(END))
-		{
-		  SimpleTextUtil.ReadLine(input, scratch);
-		  if (StringHelper.StartsWith(scratch, DOC))
-		  {
-			offsets[upto] = input.FilePointer;
-			upto++;
-		  }
-		}
-		SimpleTextUtil.CheckFooter(input);
-		Debug.Assert(upto == offsets.Length);
-	  }
+        public override void VisitDocument(int n, StoredFieldVisitor visitor)
+        {
+            _input.Seek(_offsets[n]);
+            ReadLine();
+            Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.NUM));
+            var numFields = ParseIntAt(SimpleTextStoredFieldsWriter.NUM.Length);
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void visitDocument(int n, index.StoredFieldVisitor visitor)
throws java.io.IOException
-	  public override void visitDocument(int n, StoredFieldVisitor visitor)
-	  {
-		@in.seek(offsets[n]);
-		readLine();
-		Debug.Assert(StringHelper.StartsWith(scratch, NUM));
-		int numFields = parseIntAt(NUM.length);
+            for (var i = 0; i < numFields; i++)
+            {
+                ReadLine();
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.FIELD));
+                int fieldNumber = ParseIntAt(SimpleTextStoredFieldsWriter.FIELD.Length);
+                FieldInfo fieldInfo = _fieldInfos.FieldInfo(fieldNumber);
+                ReadLine();
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.NAME));
+                ReadLine();
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.TYPE));
 
-		for (int i = 0; i < numFields; i++)
-		{
-		  readLine();
-		  Debug.Assert(StringHelper.StartsWith(scratch, FIELD));
-		  int fieldNumber = parseIntAt(FIELD.length);
-		  FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldNumber);
-		  readLine();
-		  Debug.Assert(StringHelper.StartsWith(scratch, NAME));
-		  readLine();
-		  Debug.Assert(StringHelper.StartsWith(scratch, TYPE));
+                BytesRef type;
+                if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_STRING, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
+                {
+                    type = SimpleTextStoredFieldsWriter.TYPE_STRING;
+                }
+                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_BINARY, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
+                {
+                    type = SimpleTextStoredFieldsWriter.TYPE_BINARY;
+                }
+                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_INT, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
+                {
+                    type = SimpleTextStoredFieldsWriter.TYPE_INT;
+                }
+                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_LONG, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
+                {
+                    type = SimpleTextStoredFieldsWriter.TYPE_LONG;
+                }
+                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_FLOAT, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
+                {
+                    type = SimpleTextStoredFieldsWriter.TYPE_FLOAT;
+                }
+                else if (EqualsAt(SimpleTextStoredFieldsWriter.TYPE_DOUBLE, _scratch, SimpleTextStoredFieldsWriter.TYPE.Length))
+                {
+                    type = SimpleTextStoredFieldsWriter.TYPE_DOUBLE;
+                }
+                else
+                {
+                    throw new Exception("unknown field type");
+                }
 
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final util.BytesRef type;
-		  BytesRef type;
-		  if (equalsAt(TYPE_STRING, scratch, TYPE.length))
-		  {
-			type = TYPE_STRING;
-		  }
-		  else if (equalsAt(TYPE_BINARY, scratch, TYPE.length))
-		  {
-			type = TYPE_BINARY;
-		  }
-		  else if (equalsAt(TYPE_INT, scratch, TYPE.length))
-		  {
-			type = TYPE_INT;
-		  }
-		  else if (equalsAt(TYPE_LONG, scratch, TYPE.length))
-		  {
-			type = TYPE_LONG;
-		  }
-		  else if (equalsAt(TYPE_FLOAT, scratch, TYPE.length))
-		  {
-			type = TYPE_FLOAT;
-		  }
-		  else if (equalsAt(TYPE_DOUBLE, scratch, TYPE.length))
-		  {
-			type = TYPE_DOUBLE;
-		  }
-		  else
-		  {
-			throw new Exception("unknown field type");
-		  }
+                switch (visitor.NeedsField(fieldInfo))
+                {
+                    case StoredFieldVisitor.Status.YES:
+                        ReadField(type, fieldInfo, visitor);
+                        break;
+                    case StoredFieldVisitor.Status.NO:
+                        ReadLine();
+                        Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.VALUE));
+                        break;
+                    case StoredFieldVisitor.Status.STOP:
+                        return;
+                }
+            }
+        }
 
-		  switch (visitor.needsField(fieldInfo))
-		  {
-			case YES:
-			  readField(type, fieldInfo, visitor);
-			  break;
-			case NO:
-			  readLine();
-			  Debug.Assert(StringHelper.StartsWith(scratch, VALUE));
-			  break;
-			case STOP:
-				return;
-		  }
-		}
-	  }
+        private void ReadField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor)
+        {
+            ReadLine();
+            Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextStoredFieldsWriter.VALUE));
+            if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_STRING))
+            {
+                visitor.StringField(fieldInfo,
+                    _scratch.Bytes.SubList(_scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
+                        _scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length).ToString());
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private void readField(util.BytesRef type, index.FieldInfo fieldInfo, index.StoredFieldVisitor
visitor) throws java.io.IOException
-	  private void readField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor)
-	  {
-		readLine();
-		Debug.Assert(StringHelper.StartsWith(scratch, VALUE));
-		if (type == TYPE_STRING)
-		{
-		  visitor.stringField(fieldInfo, new string(scratch.bytes, scratch.offset + VALUE.length,
scratch.length - VALUE.length, StandardCharsets.UTF_8));
-		}
-		else if (type == TYPE_BINARY)
-		{
-		  sbyte[] copy = new sbyte[scratch.length - VALUE.length];
-		  Array.Copy(scratch.bytes, scratch.offset + VALUE.length, copy, 0, copy.Length);
-		  visitor.binaryField(fieldInfo, copy);
-		}
-		else if (type == TYPE_INT)
-		{
-		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length
- VALUE.length, scratchUTF16);
-		  visitor.intField(fieldInfo, Convert.ToInt32(scratchUTF16.ToString()));
-		}
-		else if (type == TYPE_LONG)
-		{
-		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length
- VALUE.length, scratchUTF16);
-		  visitor.longField(fieldInfo, Convert.ToInt64(scratchUTF16.ToString()));
-		}
-		else if (type == TYPE_FLOAT)
-		{
-		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length
- VALUE.length, scratchUTF16);
-		  visitor.floatField(fieldInfo, Convert.ToSingle(scratchUTF16.ToString()));
-		}
-		else if (type == TYPE_DOUBLE)
-		{
-		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length
- VALUE.length, scratchUTF16);
-		  visitor.doubleField(fieldInfo, Convert.ToDouble(scratchUTF16.ToString()));
-		}
-	  }
+                   // new string(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
+                   //     Encoding.UTF8));
+            }
+            else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_BINARY))
+            {
+                var copy = new sbyte[_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length];
+                Array.Copy(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
copy, 0, copy.Length);
+                visitor.BinaryField(fieldInfo, copy);
+            }
+            else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_INT))
+            {
+                UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
+                    _scratchUtf16);
+                visitor.IntField(fieldInfo, Convert.ToInt32(_scratchUtf16.ToString()));
+            }
+            else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_LONG))
+            {
+                UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
+                    _scratchUtf16);
+                visitor.LongField(fieldInfo, Convert.ToInt64(_scratchUtf16.ToString()));
+            }
+            else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_FLOAT))
+            {
+                UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
+                    _scratchUtf16);
+                visitor.FloatField(fieldInfo, Convert.ToSingle(_scratchUtf16.ToString()));
+            }
+            else if (Equals(type, SimpleTextStoredFieldsWriter.TYPE_DOUBLE))
+            {
+                UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + SimpleTextStoredFieldsWriter.VALUE.Length,
_scratch.Length - SimpleTextStoredFieldsWriter.VALUE.Length,
+                    _scratchUtf16);
+                visitor.DoubleField(fieldInfo, Convert.ToDouble(_scratchUtf16.ToString()));
+            }
+        }
 
-	  public override StoredFieldsReader clone()
-	  {
-		if (@in == null)
-		{
-		  throw new AlreadyClosedException("this FieldsReader is closed");
-		}
-		return new SimpleTextStoredFieldsReader(offsets, @in.clone(), fieldInfos);
-	  }
+        public override object Clone()
+        {
+            if (_input == null)
+            {
+                throw new AlreadyClosedException("this FieldsReader is closed");
+            }
+            return new SimpleTextStoredFieldsReader(_offsets, (IndexInput) _input.Clone(),
_fieldInfos);
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void close() throws java.io.IOException
-	  public override void close()
-	  {
-		try
-		{
-		  IOUtils.close(@in);
-		}
-		finally
-		{
-		  @in = null;
-		  offsets = null;
-		}
-	  }
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing) return;
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private void readLine() throws java.io.IOException
-	  private void readLine()
-	  {
-		SimpleTextUtil.ReadLine(@in, scratch);
-	  }
+            try
+            {
+                IOUtils.Close(_input);
+            }
+            finally
+            {
+                _input = null;
+                _offsets = null;
+            }
+        }
 
-	  private int parseIntAt(int offset)
-	  {
-		UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + offset, scratch.length - offset,
scratchUTF16);
-		return ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-	  }
+        private void ReadLine()
+        {
+            SimpleTextUtil.ReadLine(_input, _scratch);
+        }
 
-	  private bool equalsAt(BytesRef a, BytesRef b, int bOffset)
-	  {
-		return a.length == b.length - bOffset && ArrayUtil.Equals(a.bytes, a.offset, b.bytes,
b.offset + bOffset, b.length - bOffset);
-	  }
+        private int ParseIntAt(int offset)
+        {
+            UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + offset, _scratch.Length
- offset, _scratchUtf16);
+            return ArrayUtil.ParseInt(_scratchUtf16.Chars, 0, _scratchUtf16.length);
+        }
 
-	  public override long ramBytesUsed()
-	  {
-		return 0;
-	  }
+        private bool EqualsAt(BytesRef a, BytesRef b, int bOffset)
+        {
+            return a.Length == b.Length - bOffset &&
+                   ArrayUtil.Equals(a.Bytes, a.Offset, b.Bytes, b.Offset + bOffset, b.Length
- bOffset);
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void checkIntegrity() throws java.io.IOException
-	  public override void checkIntegrity()
-	  {
-	  }
-	}
+        public override long RamBytesUsed()
+        {
+            return 0;
+        }
+
+        public override void CheckIntegrity()
+        {
+        }
+    }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/07150be0/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
index 79d943f..80a55c2 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
@@ -106,9 +106,8 @@ namespace Lucene.Net.Codecs.SimpleText
             NewLine();
 
             Write(TYPE);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final Number n = field.numericValue();
-            Number n = field.NumericValue;
+
+            var n = field.NumericValue;
 
             if (n != null)
             {
@@ -150,12 +149,12 @@ namespace Lucene.Net.Codecs.SimpleText
                 }
                 else
                 {
-                    throw new System.ArgumentException("cannot store numeric type " + n.GetType());
+                    throw new ArgumentException("cannot store numeric type " + n.GetType());
                 }
             }
             else
             {
-                BytesRef bytes = field.binaryValue();
+                BytesRef bytes = field.BinaryValue();
                 if (bytes != null)
                 {
                     Write(TYPE_BINARY);
@@ -165,7 +164,7 @@ namespace Lucene.Net.Codecs.SimpleText
                     Write(bytes);
                     NewLine();
                 }
-                else if (field.stringValue() == null)
+                else if (field.StringValue == null)
                 {
                     throw new ArgumentException("field " + field.Name() +
                                                        " is stored but does not have binaryValue,
stringValue nor numericValue");
@@ -176,7 +175,7 @@ namespace Lucene.Net.Codecs.SimpleText
                     NewLine();
 
                     Write(VALUE);
-                    Write(field.StringValue());
+                    Write(field.StringValue);
                     NewLine();
                 }
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/07150be0/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
index 09e4a30..c77b8ae 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
@@ -15,6 +15,9 @@
 * limitations under the License.
 */
 
+using System.Linq;
+using Lucene.Net.Support;
+
 namespace Lucene.Net.Codecs.SimpleText
 {
     
@@ -43,9 +46,6 @@ namespace Lucene.Net.Codecs.SimpleText
 	using StringHelper = Util.StringHelper;
 	using UnicodeUtil = Util.UnicodeUtil;
 
-    //JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted
to .NET:
-	//import static Lucene.Net.Codecs.SimpleText.SimpleTextTermVectorsWriter.*;
-
     /// <summary>
     /// Reads plain-text term vectors.
     /// <para>
@@ -65,7 +65,7 @@ namespace Lucene.Net.Codecs.SimpleText
             bool success = false;
             try
             {
-                _input = directory.OpenInput(IndexFileNames.SegmentFileName(si.Name, "",
VECTORS_EXTENSION), context);
+                _input = directory.OpenInput(IndexFileNames.SegmentFileName(si.Name, "",
SimpleTextTermVectorsWriter.VECTORS_EXTENSION), context);
                 success = true;
             }
             finally
@@ -75,9 +75,10 @@ namespace Lucene.Net.Codecs.SimpleText
                     try
                     {
                         Dispose();
-                    } // ensure we throw our original exception
+                    } 
                     catch (Exception)
                     {
+                        // ensure we throw our original exception
                     }
                 }
             }
@@ -85,10 +86,10 @@ namespace Lucene.Net.Codecs.SimpleText
         }
 
         // used by clone
-        internal SimpleTextTermVectorsReader(long[] offsets, IndexInput @in)
+        internal SimpleTextTermVectorsReader(long[] offsets, IndexInput input)
         {
-            this._offsets = offsets;
-            _input = @in;
+            _offsets = offsets;
+            _input = input;
         }
 
         // we don't actually write a .tvx-like index, instead we read the 
@@ -99,10 +100,10 @@ namespace Lucene.Net.Codecs.SimpleText
             ChecksumIndexInput input = new BufferedChecksumIndexInput(_input);
             _offsets = new long[maxDoc];
             int upto = 0;
-            while (!_scratch.Equals(END))
+            while (!_scratch.Equals(SimpleTextTermVectorsWriter.END))
             {
                 SimpleTextUtil.ReadLine(input, _scratch);
-                if (StringHelper.StartsWith(_scratch, DOC))
+                if (StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.DOC))
                 {
                     _offsets[upto] = input.FilePointer;
                     upto++;
@@ -114,128 +115,127 @@ namespace Lucene.Net.Codecs.SimpleText
 
         public override Fields Get(int doc)
         {
-            SortedMap<string, SimpleTVTerms> fields = new SortedDictionary<string,
SimpleTVTerms>();
+            var fields = new SortedDictionary<string, SimpleTVTerms>();
+
             _input.Seek(_offsets[doc]);
             ReadLine();
-            Debug.Assert(StringHelper.StartsWith(_scratch, NUMFIELDS));
-            int numFields = ParseIntAt(NUMFIELDS.length);
+            Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.NUMFIELDS));
+            var numFields = ParseIntAt(SimpleTextTermVectorsWriter.NUMFIELDS.Length);
             if (numFields == 0)
             {
                 return null; // no vectors for this doc
             }
-            for (int i = 0; i < numFields; i++)
+            for (var i = 0; i < numFields; i++)
             {
                 ReadLine();
-                Debug.Assert(StringHelper.StartsWith(_scratch, FIELD));
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.FIELD));
                 // skip fieldNumber:
-                ParseIntAt(FIELD.length);
+                ParseIntAt(SimpleTextTermVectorsWriter.FIELD.Length);
 
                 ReadLine();
-                Debug.Assert(StringHelper.StartsWith(_scratch, FIELDNAME));
-                string fieldName = ReadString(FIELDNAME.length, _scratch);
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.FIELDNAME));
+                var fieldName = ReadString(SimpleTextTermVectorsWriter.FIELDNAME.Length,
_scratch);
 
                 ReadLine();
-                Debug.Assert(StringHelper.StartsWith(_scratch, FIELDPOSITIONS));
-                bool positions = Convert.ToBoolean(ReadString(FIELDPOSITIONS.length, _scratch));
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.FIELDPOSITIONS));
+                var positions = Convert.ToBoolean(ReadString(SimpleTextTermVectorsWriter.FIELDPOSITIONS.Length,
_scratch));
 
                 ReadLine();
-                Debug.Assert(StringHelper.StartsWith(_scratch, FIELDOFFSETS));
-                bool offsets = Convert.ToBoolean(ReadString(FIELDOFFSETS.length, _scratch));
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.FIELDOFFSETS));
+                var offsets = Convert.ToBoolean(ReadString(SimpleTextTermVectorsWriter.FIELDOFFSETS.Length,
_scratch));
 
                 ReadLine();
-                Debug.Assert(StringHelper.StartsWith(_scratch, FIELDPAYLOADS));
-                bool payloads = Convert.ToBoolean(ReadString(FIELDPAYLOADS.length, _scratch));
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.FIELDPAYLOADS));
+                var payloads = Convert.ToBoolean(ReadString(SimpleTextTermVectorsWriter.FIELDPAYLOADS.Length,
_scratch));
 
                 ReadLine();
-                Debug.Assert(StringHelper.StartsWith(_scratch, FIELDTERMCOUNT));
-                int termCount = ParseIntAt(FIELDTERMCOUNT.length);
+                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.FIELDTERMCOUNT));
+                var termCount = ParseIntAt(SimpleTextTermVectorsWriter.FIELDTERMCOUNT.Length);
 
-                SimpleTVTerms terms = new SimpleTVTerms(offsets, positions, payloads);
-                fields.put(fieldName, terms);
+                var terms = new SimpleTVTerms(offsets, positions, payloads);
+                fields.Add(fieldName, terms);
 
-                for (int j = 0; j < termCount; j++)
+                for (var j = 0; j < termCount; j++)
                 {
                     ReadLine();
-                    Debug.Assert(StringHelper.StartsWith(_scratch, TERMTEXT));
-                    BytesRef term = new BytesRef();
-                    int termLength = _scratch.length - TERMTEXT.length;
-                    term.grow(termLength);
-                    term.length = termLength;
-                    Array.Copy(_scratch.bytes, _scratch.offset + TERMTEXT.length, term.bytes,
term.offset, termLength);
+                    Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.TERMTEXT));
+                    var term = new BytesRef();
+                    var termLength = _scratch.Length - SimpleTextTermVectorsWriter.TERMTEXT.Length;
+                    term.Grow(termLength);
+                    term.Length = termLength;
+                    Array.Copy(_scratch.Bytes, _scratch.Offset + SimpleTextTermVectorsWriter.TERMTEXT.Length,
term.Bytes, term.Offset, termLength);
 
-                    SimpleTVPostings postings = new SimpleTVPostings();
-                    terms.TERMS.put(term, postings);
+                    var postings = new SimpleTVPostings();
+                    terms.TERMS.Add(term, postings);
 
                     ReadLine();
-                    Debug.Assert(StringHelper.StartsWith(_scratch, TERMFREQ));
-                    postings.FREQ = ParseIntAt(TERMFREQ.length);
+                    Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.TERMFREQ));
+                    postings.FREQ = ParseIntAt(SimpleTextTermVectorsWriter.TERMFREQ.Length);
 
-                    if (positions || offsets)
+                    if (!positions && !offsets) continue;
+
+                    if (positions)
                     {
-                        if (positions)
+                        postings.POSITIONS = new int[postings.FREQ];
+                        if (payloads)
                         {
-                            postings.POSITIONS = new int[postings.FREQ];
-                            if (payloads)
-                            {
-                                postings.PAYLOADS = new BytesRef[postings.FREQ];
-                            }
+                            postings.PAYLOADS = new BytesRef[postings.FREQ];
                         }
+                    }
 
-                        if (offsets)
-                        {
-                            postings.START_OFFSETS = new int[postings.FREQ];
-                            postings.END_OFFSETS = new int[postings.FREQ];
-                        }
+                    if (offsets)
+                    {
+                        postings.START_OFFSETS = new int[postings.FREQ];
+                        postings.END_OFFSETS = new int[postings.FREQ];
+                    }
 
-                        for (int k = 0; k < postings.FREQ; k++)
+                    for (var k = 0; k < postings.FREQ; k++)
+                    {
+                        if (positions)
                         {
-                            if (positions)
+                            ReadLine();
+                            Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.POSITION));
+                            postings.POSITIONS[k] = ParseIntAt(SimpleTextTermVectorsWriter.POSITION.Length);
+                            if (payloads)
                             {
                                 ReadLine();
-                                Debug.Assert(StringHelper.StartsWith(_scratch, POSITION));
-                                postings.POSITIONS[k] = ParseIntAt(POSITION.length);
-                                if (payloads)
+                                Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.PAYLOAD));
+                                if (_scratch.Length - SimpleTextTermVectorsWriter.PAYLOAD.Length
== 0)
                                 {
-                                    ReadLine();
-                                    Debug.Assert(StringHelper.StartsWith(_scratch, PAYLOAD));
-                                    if (_scratch.length - PAYLOAD.length == 0)
-                                    {
-                                        postings.PAYLOADS[k] = null;
-                                    }
-                                    else
-                                    {
-                                        sbyte[] payloadBytes = new sbyte[_scratch.length
- PAYLOAD.length];
-                                        Array.Copy(_scratch.bytes, _scratch.offset + PAYLOAD.length,
payloadBytes, 0,
-                                            payloadBytes.Length);
-                                        postings.PAYLOADS[k] = new BytesRef(payloadBytes);
-                                    }
+                                    postings.PAYLOADS[k] = null;
+                                }
+                                else
+                                {
+                                    var payloadBytes = new sbyte[_scratch.Length - SimpleTextTermVectorsWriter.PAYLOAD.Length];
+                                    Array.Copy(_scratch.Bytes, _scratch.Offset + SimpleTextTermVectorsWriter.PAYLOAD.Length,
payloadBytes, 0,
+                                        payloadBytes.Length);
+                                    postings.PAYLOADS[k] = new BytesRef(payloadBytes);
                                 }
                             }
+                        }
 
-                            if (offsets)
-                            {
-                                ReadLine();
-                                Debug.Assert(StringHelper.StartsWith(_scratch, STARTOFFSET));
-                                postings.START_OFFSETS[k] = ParseIntAt(STARTOFFSET.length);
+                        if (!offsets) continue;
 
-                                ReadLine();
-                                Debug.Assert(StringHelper.StartsWith(_scratch, ENDOFFSET));
-                                postings.END_OFFSETS[k] = ParseIntAt(ENDOFFSET.length);
-                            }
-                        }
+                        ReadLine();
+                        Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.STARTOFFSET));
+                        postings.START_OFFSETS[k] = ParseIntAt(SimpleTextTermVectorsWriter.STARTOFFSET.Length);
+
+                        ReadLine();
+                        Debug.Assert(StringHelper.StartsWith(_scratch, SimpleTextTermVectorsWriter.ENDOFFSET));
+                        postings.END_OFFSETS[k] = ParseIntAt(SimpleTextTermVectorsWriter.ENDOFFSET.Length);
                     }
                 }
             }
             return new SimpleTVFields(this, fields);
         }
 
-        public override TermVectorsReader Clone()
+        public override object Clone()
         {
             if (_input == null)
             {
                 throw new AlreadyClosedException("this TermVectorsReader is closed");
             }
-            return new SimpleTextTermVectorsReader(_offsets, _input.Clone());
+            return new SimpleTextTermVectorsReader(_offsets, (IndexInput)_input.Clone());
         }
 
         protected override void Dispose(bool disposing)
@@ -301,9 +301,9 @@ namespace Lucene.Net.Codecs.SimpleText
                 return _fields[field];
             }
 
-            public override int Size()
+            public override int Size
             {
-                return _fields.Count;
+                get { return _fields.Count; }
             }
         }
 
@@ -385,27 +385,32 @@ namespace Lucene.Net.Codecs.SimpleText
 
         private class SimpleTVTermsEnum : TermsEnum
         {
-            internal SortedMap<BytesRef, SimpleTVPostings> terms;
+            private readonly SortedDictionary<BytesRef, SimpleTVPostings> _terms;
             private IEnumerator<KeyValuePair<BytesRef, SimpleTVPostings>> _iterator;
             private KeyValuePair<BytesRef, SimpleTVPostings> _current;
 
-            internal SimpleTVTermsEnum(SortedMap<BytesRef, SimpleTVPostings> terms)
+            internal SimpleTVTermsEnum(SortedDictionary<BytesRef, SimpleTVPostings>
terms)
             {
-                this.terms = terms;
-                this._iterator = terms.EntrySet().GetEnumerator();
+                _terms = terms;
+                _iterator = terms.EntrySet().GetEnumerator();
             }
 
             public override SeekStatus SeekCeil(BytesRef text)
             {
-                _iterator = terms.TailMap(text).entrySet().GetEnumerator();
-                //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within
the context of 'while' and 'for' loops:
-                if (!_iterator.HasNext())
+                var newTerms = new SortedDictionary<BytesRef, SimpleTVPostings>();
+                foreach (var p in _terms.Where(p => p.Key.CompareTo(text) >= 0))
+                    newTerms.Add(p.Key, p.Value);
+
+                _iterator = newTerms.EntrySet().GetEnumerator();
+
+                try
                 {
-                    return SeekStatus.END;
+                    _iterator.MoveNext();
+                    return _iterator.Current.Key.Equals(text) ? SeekStatus.FOUND : SeekStatus.NOT_FOUND;
                 }
-                else
+                catch
                 {
-                    return Next().Equals(text) ? SeekStatus.FOUND : SeekStatus.NOT_FOUND;
+                    return SeekStatus.END;
                 }
             }
 
@@ -416,16 +421,15 @@ namespace Lucene.Net.Codecs.SimpleText
 
             public override BytesRef Next()
             {
-                //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within
the context of 'while' and 'for' loops:
-                if (!_iterator.HasNext())
+                try
                 {
-                    return null;
+                    _iterator.MoveNext();
+                    _current = _iterator.Current;
+                    return _current.Key;
                 }
-                else
+                catch
                 {
-                    //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within
the context of 'while' and 'for' loops:
-                    _current = _iterator.Next();
-                    return _current.Key;
+                    return null;
                 }
             }
 
@@ -459,7 +463,7 @@ namespace Lucene.Net.Codecs.SimpleText
 
             public override DocsAndPositionsEnum DocsAndPositions(Bits liveDocs, DocsAndPositionsEnum
reuse, int flags)
             {
-                SimpleTVPostings postings = _current.Value;
+                var postings = _current.Value;
                 if (postings.POSITIONS == null && postings.START_OFFSETS == null)
                     return null;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/07150be0/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
index 67cc4e2..4dd1265 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
@@ -193,7 +193,7 @@ namespace Lucene.Net.Codecs.SimpleText
             if (numDocsWritten != numDocs)
             {
                 throw new Exception("mergeVectors produced an invalid result: mergedDocs
is " + numDocs +
-                                    " but vec numDocs is " + numDocsWritten + " file=" +
_output.ToString() +
+                                    " but vec numDocs is " + numDocsWritten + " file=" +
_output +
                                     "; now aborting this merge to prevent index corruption");
             }
             Write(END);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/07150be0/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
index 447b1bb..3f9a49a 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
@@ -18,7 +18,7 @@
 namespace Lucene.Net.Codecs.SimpleText
 {
 
-    using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+    using CorruptIndexException = Index.CorruptIndexException;
     using ChecksumIndexInput = Store.ChecksumIndexInput;
     using DataInput = Store.DataInput;
     using DataOutput = Store.DataOutput;
@@ -77,10 +77,8 @@ namespace Lucene.Net.Codecs.SimpleText
                     {
                         break;
                     }
-                    else
-                    {
-                        scratch.Bytes[upto++] = b;
-                    }
+                    
+                    scratch.Bytes[upto++] = b;
                 }
             }
             scratch.Offset = 0;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/07150be0/src/Lucene.Net.Core/Codecs/Lucene41/Lucene41PostingsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene41/Lucene41PostingsWriter.cs b/src/Lucene.Net.Core/Codecs/Lucene41/Lucene41PostingsWriter.cs
index e75309f..1a8da9c 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene41/Lucene41PostingsWriter.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene41/Lucene41PostingsWriter.cs
@@ -1,36 +1,36 @@
-using System;
-using System.Diagnostics;
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
 namespace Lucene.Net.Codecs.Lucene41
 {
-    using ArrayUtil = Lucene.Net.Util.ArrayUtil;
-    using BytesRef = Lucene.Net.Util.BytesRef;
-    using DataOutput = Lucene.Net.Store.DataOutput;
-
-    /*
-         * Licensed to the Apache Software Foundation (ASF) under one or more
-         * contributor license agreements.  See the NOTICE file distributed with
-         * this work for additional information regarding copyright ownership.
-         * The ASF licenses this file to You under the Apache License, Version 2.0
-         * (the "License"); you may not use this file except in compliance with
-         * the License.  You may obtain a copy of the License at
-         *
-         *     http://www.apache.org/licenses/LICENSE-2.0
-         *
-         * Unless required by applicable law or agreed to in writing, software
-         * distributed under the License is distributed on an "AS IS" BASIS,
-         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-         * See the License for the specific language governing permissions and
-         * limitations under the License.
-         */
-
-    using FieldInfo = Lucene.Net.Index.FieldInfo;
-    using IndexFileNames = Lucene.Net.Index.IndexFileNames;
-    using IndexOutput = Lucene.Net.Store.IndexOutput;
-    using IOUtils = Lucene.Net.Util.IOUtils;
-    using PackedInts = Lucene.Net.Util.Packed.PackedInts;
-    using SegmentWriteState = Lucene.Net.Index.SegmentWriteState;
-    using TermState = Lucene.Net.Index.TermState;
+
+    using System;
+    using System.Diagnostics;
+
+    using ArrayUtil = Util.ArrayUtil;
+    using BytesRef = Util.BytesRef;
+    using DataOutput = Store.DataOutput;
+    using FieldInfo = Index.FieldInfo;
+    using IndexFileNames = Index.IndexFileNames;
+    using IndexOutput = Store.IndexOutput;
+    using IOUtils = Util.IOUtils;
+    using PackedInts = Util.Packed.PackedInts;
+    using SegmentWriteState = Index.SegmentWriteState;
+    using TermState = Index.TermState;
 
     /// <summary>
     /// Concrete class that writes docId(maybe frq,pos,offset,payloads) list
@@ -286,7 +286,7 @@ namespace Lucene.Net.Codecs.Lucene41
             SkipWriter.ResetSkip();
         }
 
-        public override void StartDoc(int docID, int termDocFreq)
+        public override void StartDoc(int docId, int termDocFreq)
         {
             // if (DEBUG) {
             //   System.out.println("FPW.startDoc docID["+docBufferUpto+"]=" + docID);
@@ -302,11 +302,11 @@ namespace Lucene.Net.Codecs.Lucene41
                 SkipWriter.BufferSkip(LastBlockDocID, DocCount, LastBlockPosFP, LastBlockPayFP,
LastBlockPosBufferUpto, LastBlockPayloadByteUpto);
             }
 
-            int docDelta = docID - LastDocID;
+            int docDelta = docId - LastDocID;
 
-            if (docID < 0 || (DocCount > 0 && docDelta <= 0))
+            if (docId < 0 || (DocCount > 0 && docDelta <= 0))
             {
-                throw new Exception("docs out of order (" + docID + " <= " + LastDocID
+ " ) (docOut: " + DocOut + ")");
+                throw new Exception("docs out of order (" + docId + " <= " + LastDocID
+ " ) (docOut: " + DocOut + ")");
             }
 
             DocDeltaBuffer[DocBufferUpto] = docDelta;
@@ -338,7 +338,7 @@ namespace Lucene.Net.Codecs.Lucene41
                 // the block was filled so it can save skip data)
             }
 
-            LastDocID = docID;
+            LastDocID = docId;
             LastPosition = 0;
             LastStartOffset = 0;
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/07150be0/src/Lucene.Net.Core/Index/CorruptIndexException.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/CorruptIndexException.cs b/src/Lucene.Net.Core/Index/CorruptIndexException.cs
index c17857e..b4a617b 100644
--- a/src/Lucene.Net.Core/Index/CorruptIndexException.cs
+++ b/src/Lucene.Net.Core/Index/CorruptIndexException.cs
@@ -31,5 +31,10 @@ namespace Lucene.Net.Index
             : base(message)
         {
         }
+
+        public CorruptIndexException(string message, Exception ex) 
+            : base(message, ex)
+        {
+        }
     }
 }
\ No newline at end of file


Mime
View raw message