This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 5c9f5127ea1e0cf8e1f4adece74ce8b28cc0c190 Author: Shad Storhaug <[email protected]> AuthorDate: Mon Dec 16 02:36:06 2019 +0700 Lucene.Net.Support.IO: Factored out Int64Buffer and replaced with the implementation from J2N.IO --- src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs | 117 ++--- src/Lucene.Net.Tests/Support/IO/TestByteBuffer2.cs | 20 +- src/Lucene.Net.Tests/Support/IO/TestLongBuffer.cs | 540 --------------------- src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs | 9 +- src/Lucene.Net/Support/IO/ByteBuffer.cs | 30 +- src/Lucene.Net/Support/IO/HeapByteBuffer.cs | 8 +- src/Lucene.Net/Support/IO/LongArrayBuffer.cs | 106 ---- src/Lucene.Net/Support/IO/LongBuffer.cs | 277 ----------- .../Support/IO/LongToByteBufferAdapter.cs | 234 --------- .../Support/IO/MemoryMappedFileByteBuffer.cs | 14 +- .../Support/IO/ReadWriteLongArrayBuffer.cs | 144 ------ 11 files changed, 100 insertions(+), 1399 deletions(-) diff --git a/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs b/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs index a2e782b..77769e8 100644 --- a/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs +++ b/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs @@ -1369,69 +1369,70 @@ namespace Lucene.Net.Support.IO // buf.SetOrder(ByteOrder.BIG_ENDIAN); //} - [Test, LuceneNetSpecific] - public virtual void TestAsLongBuffer() - { - Int64Buffer longBuffer; - byte[] bytes = new byte[8]; - long value; + // LUCENENET NOTE: Not supported + //[Test, LuceneNetSpecific] + //public virtual void TestAsLongBuffer() + //{ + // Int64Buffer longBuffer; + // byte[] bytes = new byte[8]; + // long value; - // test BIG_ENDIAN long buffer, read - buf.Clear(); - buf.SetOrder(ByteOrder.BIG_ENDIAN); - longBuffer = buf.AsInt64Buffer(); - assertSame(ByteOrder.BIG_ENDIAN, longBuffer.Order); - while (longBuffer.Remaining > 0) - { - buf.Get(bytes); - value = longBuffer.Get(); - assertEquals(bytes2long(bytes, buf.Order), value); - } + // // test BIG_ENDIAN long buffer, read + // buf.Clear(); + // buf.SetOrder(ByteOrder.BIG_ENDIAN); + // longBuffer = buf.AsInt64Buffer(); + // assertSame(ByteOrder.BIG_ENDIAN, longBuffer.Order); + // while (longBuffer.Remaining > 0) + // { + // buf.Get(bytes); + // value = longBuffer.Get(); + // assertEquals(bytes2long(bytes, buf.Order), value); + // } - // test LITTLE_ENDIAN long buffer, read - buf.Clear(); - buf.SetOrder(ByteOrder.LITTLE_ENDIAN); - longBuffer = buf.AsInt64Buffer(); - assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.Order); - while (longBuffer.Remaining > 0) - { - buf.Get(bytes); - value = longBuffer.Get(); - assertEquals(bytes2long(bytes, buf.Order), value); - } + // // test LITTLE_ENDIAN long buffer, read + // buf.Clear(); + // buf.SetOrder(ByteOrder.LITTLE_ENDIAN); + // longBuffer = buf.AsInt64Buffer(); + // assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.Order); + // while (longBuffer.Remaining > 0) + // { + // buf.Get(bytes); + // value = longBuffer.Get(); + // assertEquals(bytes2long(bytes, buf.Order), value); + // } - if (!buf.IsReadOnly) - { - // test BIG_ENDIAN long buffer, write - buf.Clear(); - buf.SetOrder(ByteOrder.BIG_ENDIAN); - longBuffer = buf.AsInt64Buffer(); - assertSame(ByteOrder.BIG_ENDIAN, longBuffer.Order); - while (longBuffer.Remaining > 0) - { - value = (long)longBuffer.Remaining; - longBuffer.Put(value); - buf.Get(bytes); - assertTrue(Arrays.Equals(bytes, long2bytes(value, buf.Order))); - } + // if (!buf.IsReadOnly) + // { + // // test BIG_ENDIAN long buffer, write + // buf.Clear(); + // buf.SetOrder(ByteOrder.BIG_ENDIAN); + // longBuffer = buf.AsInt64Buffer(); + // assertSame(ByteOrder.BIG_ENDIAN, longBuffer.Order); + // while (longBuffer.Remaining > 0) + // { + // value = (long)longBuffer.Remaining; + // longBuffer.Put(value); + // buf.Get(bytes); + // assertTrue(Arrays.Equals(bytes, long2bytes(value, buf.Order))); + // } - // test LITTLE_ENDIAN long buffer, write - buf.Clear(); - buf.SetOrder(ByteOrder.LITTLE_ENDIAN); - longBuffer = buf.AsInt64Buffer(); - assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.Order); - while (longBuffer.Remaining > 0) - { - value = (long)longBuffer.Remaining; - longBuffer.Put(value); - buf.Get(bytes); - assertTrue(Arrays.Equals(bytes, long2bytes(value, buf.Order))); - } - } + // // test LITTLE_ENDIAN long buffer, write + // buf.Clear(); + // buf.SetOrder(ByteOrder.LITTLE_ENDIAN); + // longBuffer = buf.AsInt64Buffer(); + // assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.Order); + // while (longBuffer.Remaining > 0) + // { + // value = (long)longBuffer.Remaining; + // longBuffer.Put(value); + // buf.Get(bytes); + // assertTrue(Arrays.Equals(bytes, long2bytes(value, buf.Order))); + // } + // } - buf.Clear(); - buf.SetOrder(ByteOrder.BIG_ENDIAN); - } + // buf.Clear(); + // buf.SetOrder(ByteOrder.BIG_ENDIAN); + //} // LUCENENET NOTE: Not supported //[Test, LuceneNetSpecific] diff --git a/src/Lucene.Net.Tests/Support/IO/TestByteBuffer2.cs b/src/Lucene.Net.Tests/Support/IO/TestByteBuffer2.cs index 87ed5b4..aab8805 100644 --- a/src/Lucene.Net.Tests/Support/IO/TestByteBuffer2.cs +++ b/src/Lucene.Net.Tests/Support/IO/TestByteBuffer2.cs @@ -198,10 +198,10 @@ namespace Lucene.Net.Support.IO //checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) }); //checkInvalidMarkException(ib); - Int64Buffer lb = b.AsInt64Buffer(); - TestLongBuffer.test(level, lb, direct); - checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)Ic(0) }); - checkInvalidMarkException(lb); + //Int64Buffer lb = b.AsInt64Buffer(); + //TestLongBuffer.test(level, lb, direct); + //checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)Ic(0) }); + //checkInvalidMarkException(lb); //FloatBuffer fb = b.asFloatBuffer(); //BasicFloat.test(level, fb, direct); @@ -270,14 +270,14 @@ namespace Lucene.Net.Support.IO ck(b, b.GetInt64(), long.MaxValue); output.Write(" long"); - ck(b, (long)b.GetSingle(), 1); - ck(b, (long)b.GetSingle(), unchecked((long)float.MinValue)); - ck(b, (long)b.GetSingle(), unchecked((long)float.MaxValue)); + ck(b, b.GetSingle(), 1); + ck(b, b.GetSingle(), float.MinValue); + ck(b, b.GetSingle(), float.MaxValue); output.Write(" float"); - ck(b, (long)b.GetDouble(), 1); - ck(b, (long)b.GetDouble(), unchecked((long)double.MinValue)); - ck(b, (long)b.GetDouble(), unchecked((long)double.MaxValue)); + ck(b, b.GetDouble(), 1); + ck(b, b.GetDouble(), double.MinValue); + ck(b, b.GetDouble(), double.MaxValue); output.Write(" double"); output.WriteLine(); diff --git a/src/Lucene.Net.Tests/Support/IO/TestLongBuffer.cs b/src/Lucene.Net.Tests/Support/IO/TestLongBuffer.cs deleted file mode 100644 index 5a64656..0000000 --- a/src/Lucene.Net.Tests/Support/IO/TestLongBuffer.cs +++ /dev/null @@ -1,540 +0,0 @@ -using Lucene.Net.Attributes; -using NUnit.Framework; -using System; -using System.Reflection; - -namespace Lucene.Net.Support.IO -{ - /* - * 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. - */ - - /// <summary> - /// Tests from JDK/nio/BasicLong.java - /// </summary> - public class TestLongBuffer : BaseBufferTestCase - { - private static readonly long[] VALUES = { - long.MinValue, - (long) -1, - (long) 0, - (long) 1, - long.MaxValue, - }; - - - private static void relGet(Int64Buffer b) - { - int n = b.Capacity; - //long v; // LUCENENET: Not used - for (int i = 0; i < n; i++) - ck(b, (long)b.Get(), (long)((long)Ic(i))); - b.Rewind(); - } - - private static void relGet(Int64Buffer b, int start) - { - int n = b.Remaining; - //long v; // LUCENENET: Not used - for (int i = start; i < n; i++) - ck(b, (long)b.Get(), (long)((long)Ic(i))); - b.Rewind(); - } - - private static void absGet(Int64Buffer b) - { - int n = b.Capacity; - //long v; // LUCENENET: Not used - for (int i = 0; i < n; i++) - ck(b, (long)b.Get(), (long)((long)Ic(i))); - b.Rewind(); - } - - private static void bulkGet(Int64Buffer b) - { - int n = b.Capacity; - long[] a = new long[n + 7]; - b.Get(a, 7, n); - for (int i = 0; i < n; i++) - ck(b, (long)a[i + 7], (long)((long)Ic(i))); - } - - private static void relPut(Int64Buffer b) - { - int n = b.Capacity; - b.Clear(); - for (int i = 0; i < n; i++) - b.Put((long)Ic(i)); - b.Flip(); - } - - private static void absPut(Int64Buffer b) - { - int n = b.Capacity; - b.Clear(); - for (int i = 0; i < n; i++) - b.Put(i, (long)Ic(i)); - b.Limit = (n); - b.Position = (0); - } - - private static void bulkPutArray(Int64Buffer b) - { - int n = b.Capacity; - b.Clear(); - long[] a = new long[n + 7]; - for (int i = 0; i < n; i++) - a[i + 7] = (long)Ic(i); - b.Put(a, 7, n); - b.Flip(); - } - - private static void bulkPutBuffer(Int64Buffer b) - { - int n = b.Capacity; - b.Clear(); - Int64Buffer c = Int64Buffer.Allocate(n + 7); - c.Position = (7); - for (int i = 0; i < n; i++) - c.Put((long)Ic(i)); - c.Flip(); - c.Position = (7); - b.Put(c); - b.Flip(); - } - - //6231529 - private static void callReset(Int64Buffer b) - { - b.Position = (0); - b.Mark(); - - b.Duplicate().Reset(); - - // LUCENENET: AsReadOnlyBuffer() not implemented - //b.AsReadOnlyBuffer().Reset(); - } - - - - // 6221101-6234263 - - private static void putBuffer() - { - int cap = 10; - - // LUCENENET: AllocateDirect not implemented - - //LongBuffer direct1 = ByteBuffer.AllocateDirect(cap).AsLongBuffer(); - Int64Buffer nondirect1 = ByteBuffer.Allocate(cap).AsInt64Buffer(); - //direct1.Put(nondirect1); - - //LongBuffer direct2 = ByteBuffer.AllocateDirect(cap).AsLongBuffer(); - Int64Buffer nondirect2 = ByteBuffer.Allocate(cap).AsInt64Buffer(); - //nondirect2.Put(direct2); - - //LongBuffer direct3 = ByteBuffer.AllocateDirect(cap).AsLongBuffer(); - //LongBuffer direct4 = ByteBuffer.AllocateDirect(cap).AsLongBuffer(); - //direct3.Put(direct4); - - Int64Buffer nondirect3 = ByteBuffer.Allocate(cap).AsInt64Buffer(); - Int64Buffer nondirect4 = ByteBuffer.Allocate(cap).AsInt64Buffer(); - nondirect3.Put(nondirect4); - } - - private static void checkSlice(Int64Buffer b, Int64Buffer slice) - { - ck(slice, 0, slice.Position); - ck(slice, b.Remaining, slice.Limit); - ck(slice, b.Remaining, slice.Capacity); - if (b.IsDirect != slice.IsDirect) - fail("Lost direction", slice); - if (b.IsReadOnly != slice.IsReadOnly) - fail("Lost read-only", slice); - } - - private static void fail(string problem, - Int64Buffer xb, Int64Buffer yb, - long x, long y) - { - fail(problem + string.Format(": x={0} y={1}", x, y), xb, yb); - } - - private static void tryCatch(IO.Buffer b, Type ex, Action thunk) - { - bool caught = false; - try - { - thunk(); - } - catch (Exception x) - { - if (ex.GetTypeInfo().IsAssignableFrom(x.GetType())) - { - caught = true; - } - else - { - fail(x.Message + " not expected"); - } - } - if (!caught) - fail(ex.Name + " not thrown", b); - } - - private static void tryCatch(long[] t, Type ex, Action thunk) - { - tryCatch(Int64Buffer.Wrap(t), ex, thunk); - } - - public static void test(int level, Int64Buffer b, bool direct) - { - - Show(level, b); - - if (direct != b.IsDirect) - fail("Wrong direction", b); - - // Gets and puts - - relPut(b); - relGet(b); - absGet(b); - bulkGet(b); - - absPut(b); - relGet(b); - absGet(b); - bulkGet(b); - - bulkPutArray(b); - relGet(b); - - bulkPutBuffer(b); - relGet(b); - - // Compact - - relPut(b); - b.Position = (13); - b.Compact(); - b.Flip(); - relGet(b, 13); - - // Exceptions - - relPut(b); - b.Limit = (b.Capacity / 2); - b.Position = (b.Limit); - - tryCatch(b, typeof(BufferUnderflowException), () => - { - b.Get(); - }); - - tryCatch(b, typeof(BufferOverflowException), () => - { - b.Put((long)42); - }); - - // The index must be non-negative and lesss than the buffer's limit. - tryCatch(b, typeof(IndexOutOfRangeException), () => - { - b.Get(b.Limit); - }); - tryCatch(b, typeof(IndexOutOfRangeException), () => - { - b.Get(-1); - }); - - tryCatch(b, typeof(IndexOutOfRangeException), () => - { - b.Put(b.Limit, (long)42); - }); - - tryCatch(b, typeof(InvalidMarkException), () => - { - b.Position = (0); - b.Mark(); - b.Compact(); - b.Reset(); - }); - - // Values - - b.Clear(); - b.Put((long)0); - b.Put((long)-1); - b.Put((long)1); - b.Put(long.MaxValue); - b.Put(long.MinValue); - - //long v; // LUCENENET: Not used - b.Flip(); - ck(b, b.Get(), 0); - ck(b, b.Get(), (long)-1); - ck(b, b.Get(), 1); - ck(b, b.Get(), long.MaxValue); - ck(b, b.Get(), long.MinValue); - - - // Comparison - b.Rewind(); - Int64Buffer b2 = Int64Buffer.Allocate(b.Capacity); - b2.Put(b); - b2.Flip(); - b.Position = (2); - b2.Position = (2); - if (!b.equals(b2)) - { - for (int i = 2; i < b.Limit; i++) - { - long x = b.Get(i); - long y = b2.Get(i); - if (x != y) - output.WriteLine("[" + i + "] " + x + " != " + y); - } - fail("Identical buffers not equal", b, b2); - } - if (b.CompareTo(b2) != 0) - fail("Comparison to identical buffer != 0", b, b2); - - b.Limit = (b.Limit + 1); - b.Position = (b.Limit - 1); - b.Put((long)99); - b.Rewind(); - b2.Rewind(); - if (b.Equals(b2)) - fail("Non-identical buffers equal", b, b2); - if (b.CompareTo(b2) <= 0) - fail("Comparison to shorter buffer <= 0", b, b2); - b.Limit = (b.Limit - 1); - - b.Put(2, (long)42); - if (b.equals(b2)) - fail("Non-identical buffers equal", b, b2); - if (b.CompareTo(b2) <= 0) - fail("Comparison to lesser buffer <= 0", b, b2); - - // Check equals and compareTo with interesting values - foreach (long x in VALUES) - { - Int64Buffer xb = Int64Buffer.Wrap(new long[] { x }); - if (xb.CompareTo(xb) != 0) - { - fail("compareTo not reflexive", xb, xb, x, x); - } - if (!xb.equals(xb)) - { - fail("equals not reflexive", xb, xb, x, x); - } - foreach (long y in VALUES) - { - Int64Buffer yb = Int64Buffer.Wrap(new long[] { y }); - if (xb.CompareTo(yb) != -yb.CompareTo(xb)) - { - fail("compareTo not anti-symmetric", - xb, yb, x, y); - } - if ((xb.CompareTo(yb) == 0) != xb.equals(yb)) - { - fail("compareTo inconsistent with equals", - xb, yb, x, y); - } - // from Long.compare(x, y) - if (xb.CompareTo(yb) != ((x < y) ? -1 : ((x == y) ? 0 : 1))) - { - - fail("Incorrect results for LongBuffer.compareTo", - xb, yb, x, y); - } - if (xb.equals(yb) != ((x == y) /*|| (x != x) && (y != y)*/)) - { - fail("Incorrect results for LongBuffer.equals", - xb, yb, x, y); - } - } - } - - // Sub, dup - - relPut(b); - relGet(b.Duplicate()); - b.Position = (13); - relGet(b.Duplicate(), 13); - relGet(b.Duplicate().Slice(), 13); - relGet(b.Slice(), 13); - relGet(b.Slice().Duplicate(), 13); - - // Slice - - b.Position = (5); - Int64Buffer sb = b.Slice(); - checkSlice(b, sb); - b.Position = (0); - Int64Buffer sb2 = sb.Slice(); - checkSlice(sb, sb2); - - if (!sb.equals(sb2)) - fail("Sliced slices do not match", sb, sb2); - if ((sb.HasArray) && (sb.ArrayOffset != sb2.ArrayOffset)) - fail("Array offsets do not match: " - + sb.ArrayOffset + " != " + sb2.ArrayOffset, sb, sb2); - - - // Read-only views - - b.Rewind(); - - // LUCENENET: AsReadOnlyBuffer() not implemented - tryCatch(b, typeof(NotImplementedException), () => - { - b.AsReadOnlyBuffer(); - }); - - //// LUCENENET: AsReadOnlyBuffer() not implemented - //Int64Buffer rb = b.AsReadOnlyBuffer(); - //if (!b.Equals(rb)) - // fail("Buffer not equal to read-only view", b, rb); - //Show(level + 1, rb); - - //tryCatch(b, typeof(ReadOnlyBufferException), () => - //{ - // relPut(rb); - //}); - - //tryCatch(b, typeof(ReadOnlyBufferException), () => - //{ - // absPut(rb); - //}); - - //tryCatch(b, typeof(ReadOnlyBufferException), () => - //{ - // bulkPutArray(rb); - //}); - - //tryCatch(b, typeof(ReadOnlyBufferException), () => - //{ - // bulkPutBuffer(rb); - //}); - - //// put(LongBuffer) should not change source position - //Int64Buffer src = Int64Buffer.Allocate(1); - //tryCatch(b, typeof(ReadOnlyBufferException), () => - //{ - // rb.Put(src); - //}); - //ck(src, src.Position, 0); - - //tryCatch(b, typeof(ReadOnlyBufferException), () => - //{ - // rb.Compact(); - //}); - - - //if (rb.GetType().Name.StartsWith("Heap", StringComparison.Ordinal)) - //{ - - // tryCatch(b, typeof(ReadOnlyBufferException), () => - // { - // var x = rb.Array; - // }); - - // tryCatch(b, typeof(ReadOnlyBufferException), () => - // { - // var x = rb.ArrayOffset; - // }); - - // if (rb.HasArray) - // fail("Read-only heap buffer's backing array is accessible", - // rb); - - //} - - // Bulk puts from read-only buffers - - b.Clear(); - //rb.Rewind(); - //b.Put(rb); - - relPut(b); // Required by testViews - - } - - - public static void test(long[] ba) - { - int offset = 47; - int length = 900; - Int64Buffer b = Int64Buffer.Wrap(ba, offset, length); - Show(0, b); - ck(b, b.Capacity, ba.Length); - ck(b, b.Position, offset); - ck(b, b.Limit, offset + length); - - // The offset must be non-negative and no larger than <array.length>. - tryCatch(ba, typeof(ArgumentOutOfRangeException), () => - { - Int64Buffer.Wrap(ba, -1, ba.Length); - }); - tryCatch(ba, typeof(ArgumentOutOfRangeException), () => - { - Int64Buffer.Wrap(ba, ba.Length + 1, ba.Length); - }); - tryCatch(ba, typeof(ArgumentOutOfRangeException), () => - { - Int64Buffer.Wrap(ba, 0, -1); - }); - tryCatch(ba, typeof(ArgumentOutOfRangeException), () => - { - Int64Buffer.Wrap(ba, 0, ba.Length + 1); - }); - - // A NullPointerException will be thrown if the array is null. - tryCatch(ba, typeof(NullReferenceException), () => - { - Int64Buffer.Wrap((long[])null, 0, 5); - }); - tryCatch(ba, typeof(NullReferenceException), () => - { - Int64Buffer.Wrap((long[])null); - }); - } - - - public static void TestAllocate() - { - // An IllegalArgumentException will be thrown for negative capacities. - tryCatch((Buffer)null, typeof(ArgumentException), () => - { - Int64Buffer.Allocate(-1); - }); - } - - [Test, LuceneNetSpecific] - public static void Test() - { - TestAllocate(); - test(0, Int64Buffer.Allocate(7 * 1024), false); - test(0, Int64Buffer.Wrap(new long[7 * 1024], 0, 7 * 1024), false); - test(new long[1024]); - - callReset(Int64Buffer.Allocate(10)); - putBuffer(); - - } - } -} diff --git a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs index 67da5fc..28b4fd3 100644 --- a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs +++ b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs @@ -1,11 +1,12 @@ +using J2N.IO; +using Lucene.Net.Randomized.Generators; +using Lucene.Net.Support; +using NUnit.Framework; using System; using System.Collections.Generic; using System.Globalization; using System.IO; -using Lucene.Net.Randomized.Generators; -using Lucene.Net.Support; -using Lucene.Net.Support.IO; -using NUnit.Framework; + using Console = Lucene.Net.Support.SystemConsole; namespace Lucene.Net.Util.Packed diff --git a/src/Lucene.Net/Support/IO/ByteBuffer.cs b/src/Lucene.Net/Support/IO/ByteBuffer.cs index e1c576d..fc56f69 100644 --- a/src/Lucene.Net/Support/IO/ByteBuffer.cs +++ b/src/Lucene.Net/Support/IO/ByteBuffer.cs @@ -154,21 +154,21 @@ namespace Lucene.Net.Support.IO //public abstract FloatBuffer AsSingleBuffer(); //public abstract IntBuffer AsInt32Buffer(); - /// <summary> - /// Returns a long buffer which is based on the remaining content of this - /// byte buffer. - /// <para/> - /// The new buffer's position is zero, its limit and capacity is the number - /// of remaining bytes divided by eight, and its mark is not set. The new - /// buffer's read-only property and byte order are the same as this buffer's. - /// The new buffer is direct if this byte buffer is direct. - /// <para/> - /// The new buffer shares its content with this buffer, which means either - /// buffer's change of content will be visible to the other. The two buffer's - /// position, limit and mark are independent. - /// </summary> - /// <returns>a long buffer which is based on the content of this byte buffer.</returns> - public abstract Int64Buffer AsInt64Buffer(); + ///// <summary> + ///// Returns a long buffer which is based on the remaining content of this + ///// byte buffer. + ///// <para/> + ///// The new buffer's position is zero, its limit and capacity is the number + ///// of remaining bytes divided by eight, and its mark is not set. The new + ///// buffer's read-only property and byte order are the same as this buffer's. + ///// The new buffer is direct if this byte buffer is direct. + ///// <para/> + ///// The new buffer shares its content with this buffer, which means either + ///// buffer's change of content will be visible to the other. The two buffer's + ///// position, limit and mark are independent. + ///// </summary> + ///// <returns>a long buffer which is based on the content of this byte buffer.</returns> + //public abstract Int64Buffer AsInt64Buffer(); /// <summary> /// Returns a read-only buffer that shares its content with this buffer. diff --git a/src/Lucene.Net/Support/IO/HeapByteBuffer.cs b/src/Lucene.Net/Support/IO/HeapByteBuffer.cs index 7e1c3cc..3e29db2 100644 --- a/src/Lucene.Net/Support/IO/HeapByteBuffer.cs +++ b/src/Lucene.Net/Support/IO/HeapByteBuffer.cs @@ -346,10 +346,10 @@ namespace Lucene.Net.Support.IO // } - public override sealed Int64Buffer AsInt64Buffer() - { - return Int64ToByteBufferAdapter.Wrap(this); - } + //public override sealed Int64Buffer AsInt64Buffer() + //{ + // return Int64ToByteBufferAdapter.Wrap(this); + //} //public override sealed Int16Buffer AsInt16Buffer() diff --git a/src/Lucene.Net/Support/IO/LongArrayBuffer.cs b/src/Lucene.Net/Support/IO/LongArrayBuffer.cs deleted file mode 100644 index baebf23..0000000 --- a/src/Lucene.Net/Support/IO/LongArrayBuffer.cs +++ /dev/null @@ -1,106 +0,0 @@ -// This class was sourced from the Apache Harmony project -// https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/ - -using System; - -namespace Lucene.Net.Support.IO -{ - /* - * 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. - */ - - /// <summary> - /// LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose - /// the implementation of array based long buffers. - /// <para/> - /// LongArrayBuffer implements all the shared readonly methods and is extended by - /// the other two classes. - /// <para/> - /// All methods are marked final for runtime performance. - /// </summary> - internal abstract class Int64ArrayBuffer : Int64Buffer - { - protected internal readonly long[] backingArray; - - protected internal readonly int offset; - - internal Int64ArrayBuffer(long[] array) - : this(array.Length, array, 0) - { - } - - internal Int64ArrayBuffer(int capacity) - : this(capacity, new long[capacity], 0) - { - } - - internal Int64ArrayBuffer(int capacity, long[] backingArray, int offset) - : base(capacity) - { - this.backingArray = backingArray; - this.offset = offset; - } - - - public override sealed long Get() - { - if (position == limit) - { - throw new BufferUnderflowException(); - } - return backingArray[offset + position++]; - } - - - public override sealed long Get(int index) - { - if (index < 0 || index >= limit) - { - throw new IndexOutOfRangeException(); - } - return backingArray[offset + index]; - } - - - public override sealed Int64Buffer Get(long[] dest, int off, int len) - { - int length = dest.Length; - if (off < 0 || len < 0 || (long)len + (long)off > length) - { - throw new IndexOutOfRangeException(); - } - if (len > Remaining) - { - throw new BufferUnderflowException(); - } - System.Array.Copy(backingArray, offset + position, dest, off, len); - position += len; - return this; - } - - - public override sealed bool IsDirect - { - get { return false; } - } - - - public override sealed ByteOrder Order - { - get { return ByteOrder.NativeOrder; } - } - } -} diff --git a/src/Lucene.Net/Support/IO/LongBuffer.cs b/src/Lucene.Net/Support/IO/LongBuffer.cs deleted file mode 100644 index b77d2fe..0000000 --- a/src/Lucene.Net/Support/IO/LongBuffer.cs +++ /dev/null @@ -1,277 +0,0 @@ -// This class was sourced from the Apache Harmony project -// https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/ - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using System.Text; - -namespace Lucene.Net.Support.IO -{ - /* - * 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. - */ - - /// <summary> - /// A buffer of longs. - /// <para/> - /// A long buffer can be created in either of the following ways: - /// <list type="bullet"> - /// <item><description><see cref="Allocate(int)"/> a new long array and create a buffer - /// based on it</description></item> - /// <item><description><see cref="Wrap(long[])"/> an existing long array to create a new - /// buffer</description></item> - /// </list> - /// </summary> - public abstract class Int64Buffer : Buffer, IComparable<Int64Buffer> - { - /// <summary> - /// Creates a long buffer based on a newly allocated long array. - /// </summary> - /// <param name="capacity">the capacity of the new buffer.</param> - /// <returns>the created long buffer.</returns> - /// <exception cref="ArgumentException">if <paramref name="capacity"/> is less than zero.</exception> - public static Int64Buffer Allocate(int capacity) - { - if (capacity < 0) - { - throw new ArgumentException(); - } - return new ReadWriteInt64ArrayBuffer(capacity); - } - - /// <summary> - /// Creates a new long buffer by wrapping the given long array. - /// <para/> - /// Calling this method has the same effect as - /// <c>Wrap(array, 0, array.Length)</c>. - /// </summary> - /// <param name="array">the long array which the new buffer will be based on.</param> - /// <returns>the created long buffer.</returns> - public static Int64Buffer Wrap(long[] array) - { - return Wrap(array, 0, array != null ? array.Length : 0); - } - - public static Int64Buffer Wrap(long[] array, int start, int len) - { - if (array == null) - { - throw new NullReferenceException(); - } - if (start < 0 || len < 0 || (long)len + (long)start > array.Length) - { - throw new ArgumentOutOfRangeException(); - } - - Int64Buffer buf = new ReadWriteInt64ArrayBuffer(array); - buf.position = start; - buf.limit = start + len; - - return buf; - } - - - /// <summary> - /// Constructs a <see cref="Int64Buffer"/> with given capacity. - /// </summary> - internal Int64Buffer(int capacity) - : base(capacity) - { - } - - [WritableArray] - [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")] - public long[] Array - { - get { return ProtectedArray; } - } - - public int ArrayOffset - { - get { return ProtectedArrayOffset; } - } - - public abstract Int64Buffer AsReadOnlyBuffer(); - - public abstract Int64Buffer Compact(); - - public int CompareTo(Int64Buffer otherBuffer) - { - int compareRemaining = (Remaining < otherBuffer.Remaining) ? Remaining - : otherBuffer.Remaining; - int thisPos = position; - int otherPos = otherBuffer.position; - long thisByte, otherByte; - while (compareRemaining > 0) - { - thisByte = Get(thisPos); - otherByte = otherBuffer.Get(otherPos); - if (thisByte != otherByte) - { - return thisByte < otherByte ? -1 : 1; - } - thisPos++; - otherPos++; - compareRemaining--; - } - return Remaining - otherBuffer.Remaining; - } - - public abstract Int64Buffer Duplicate(); - - public override bool Equals(object other) - { - if (!(other is Int64Buffer)) - { - return false; - } - Int64Buffer otherBuffer = (Int64Buffer)other; - - if (Remaining != otherBuffer.Remaining) - { - return false; - } - - int myPosition = position; - int otherPosition = otherBuffer.position; - bool equalSoFar = true; - while (equalSoFar && (myPosition < limit)) - { - equalSoFar = Get(myPosition++) == otherBuffer.Get(otherPosition++); - } - - return equalSoFar; - } - - public abstract long Get(); - - public virtual Int64Buffer Get(long[] dest) - { - return Get(dest, 0, dest.Length); - } - - public virtual Int64Buffer Get(long[] dest, int off, int len) - { - int length = dest.Length; - if (off < 0 || len < 0 || (long)len + (long)off > length) - { - throw new IndexOutOfRangeException(); - } - - if (len > Remaining) - { - throw new BufferUnderflowException(); - } - for (int i = off; i < off + len; i++) - { - dest[i] = Get(); - } - return this; - } - - public abstract long Get(int index); - - public bool HasArray - { - get { return ProtectedHasArray; } - } - - public override int GetHashCode() - { - int myPosition = position; - int hash = 0; - long l; - while (myPosition < limit) - { - l = Get(myPosition++); - hash = hash + ((int)l) ^ ((int)(l >> 32)); - } - return hash; - } - - public abstract bool IsDirect { get; } - - public abstract ByteOrder Order { get; } - - [WritableArray] - [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")] - protected abstract long[] ProtectedArray { get; } - - protected abstract int ProtectedArrayOffset { get; } - - protected abstract bool ProtectedHasArray { get; } - - public abstract Int64Buffer Put(long l); - - public Int64Buffer Put(long[] src) - { - return Put(src, 0, src.Length); - } - - public virtual Int64Buffer Put(long[] src, int off, int len) - { - int length = src.Length; - if (off < 0 || len < 0 || (long)len + (long)off > length) - { - throw new IndexOutOfRangeException(); - } - - if (len > Remaining) - { - throw new BufferOverflowException(); - } - for (int i = off; i < off + len; i++) - { - Put(src[i]); - } - return this; - } - - public virtual Int64Buffer Put(Int64Buffer src) - { - if (src == this) - { - throw new ArgumentException(); - } - if (src.Remaining > Remaining) - { - throw new BufferOverflowException(); - } - long[] contents = new long[src.Remaining]; - src.Get(contents); - Put(contents); - return this; - } - - public abstract Int64Buffer Put(int index, long l); - - public abstract Int64Buffer Slice(); - - public override string ToString() - { - StringBuilder buf = new StringBuilder(); - buf.Append(GetType().GetTypeInfo().Name); - buf.Append(", status: capacity="); //$NON-NLS-1$ - buf.Append(Capacity); - buf.Append(" position="); //$NON-NLS-1$ - buf.Append(Position); - buf.Append(" limit="); //$NON-NLS-1$ - buf.Append(Limit); - return buf.ToString(); - } - } -} \ No newline at end of file diff --git a/src/Lucene.Net/Support/IO/LongToByteBufferAdapter.cs b/src/Lucene.Net/Support/IO/LongToByteBufferAdapter.cs deleted file mode 100644 index ca5f4d7..0000000 --- a/src/Lucene.Net/Support/IO/LongToByteBufferAdapter.cs +++ /dev/null @@ -1,234 +0,0 @@ -// This class was sourced from the Apache Harmony project -// https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/ - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace Lucene.Net.Support.IO -{ - /* - * 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. - */ - - /// <summary> - /// This class wraps a byte buffer to be a long buffer. - /// <para/> - /// Implementation notice: - /// <list type="bullet"> - /// <item><description>After a byte buffer instance is wrapped, it becomes privately owned by - /// the adapter. It must NOT be accessed outside the adapter any more.</description></item> - /// <item><description>The byte buffer's position and limit are NOT linked with the adapter. - /// The adapter extends Buffer, thus has its own position and limit.</description></item> - /// </list> - /// </summary> - internal sealed class Int64ToByteBufferAdapter : Int64Buffer - { - internal static Int64Buffer Wrap(ByteBuffer byteBuffer) - { - return new Int64ToByteBufferAdapter(byteBuffer.Slice()); - } - - private readonly ByteBuffer byteBuffer; - - internal Int64ToByteBufferAdapter(ByteBuffer byteBuffer) - : base((byteBuffer.Capacity >> 3)) - { - this.byteBuffer = byteBuffer; - this.byteBuffer.Clear(); - } - - //public int GetByteCapacity() - //{ - // if (byteBuffer is DirectBuffer) { - // return ((DirectBuffer)byteBuffer).GetByteCapacity(); - // } - // return -1; - //} - - //public PlatformAddress getEffectiveAddress() - //{ - // if (byteBuffer is DirectBuffer) { - // return ((DirectBuffer)byteBuffer).getEffectiveAddress(); - // } - // assert false : byteBuffer; - // return null; - //} - - //public PlatformAddress getBaseAddress() - //{ - // if (byteBuffer instanceof DirectBuffer) { - // return ((DirectBuffer)byteBuffer).getBaseAddress(); - // } - // assert false : byteBuffer; - // return null; - //} - - //public boolean isAddressValid() - //{ - // if (byteBuffer instanceof DirectBuffer) { - // return ((DirectBuffer)byteBuffer).isAddressValid(); - // } - // assert false : byteBuffer; - // return false; - //} - - //public void addressValidityCheck() - //{ - // if (byteBuffer instanceof DirectBuffer) { - // ((DirectBuffer)byteBuffer).addressValidityCheck(); - // } else { - // assert false : byteBuffer; - // } - //} - - //public void free() - //{ - // if (byteBuffer instanceof DirectBuffer) { - // ((DirectBuffer)byteBuffer).free(); - // } else { - // assert false : byteBuffer; - // } - //} - - public override Int64Buffer AsReadOnlyBuffer() - { - throw new NotImplementedException(); - //Int64ToByteBufferAdapter buf = new Int64ToByteBufferAdapter(byteBuffer - // .AsReadOnlyBuffer()); - //buf.limit = limit; - //buf.position = position; - //buf.mark = mark; - //return buf; - } - - public override Int64Buffer Compact() - { - if (byteBuffer.IsReadOnly) - { - throw new ReadOnlyBufferException(); - } - byteBuffer.SetLimit(limit << 3); - byteBuffer.SetPosition(position << 3); - byteBuffer.Compact(); - byteBuffer.Clear(); - position = limit - position; - limit = capacity; - mark = UNSET_MARK; - return this; - } - - - public override Int64Buffer Duplicate() - { - Int64ToByteBufferAdapter buf = new Int64ToByteBufferAdapter(byteBuffer - .Duplicate()); - buf.limit = limit; - buf.position = position; - buf.mark = mark; - return buf; - } - - - public override long Get() - { - if (position == limit) - { - throw new BufferUnderflowException(); - } - return byteBuffer.GetInt64(position++ << 3); - } - - - public override long Get(int index) - { - if (index < 0 || index >= limit) - { - throw new IndexOutOfRangeException(); - } - return byteBuffer.GetInt64(index << 3); - } - - - public override bool IsDirect - { - get { return byteBuffer.IsDirect; } - } - - - public override bool IsReadOnly - { - get { return byteBuffer.IsReadOnly; } - } - - - public override ByteOrder Order - { - get { return byteBuffer.Order; } - } - - - [WritableArray] - [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")] - protected override long[] ProtectedArray - { - get { throw new NotSupportedException(); } - } - - - protected override int ProtectedArrayOffset - { - get { throw new NotSupportedException(); } - } - - - protected override bool ProtectedHasArray - { - get { return false; } - } - - - public override Int64Buffer Put(long c) - { - if (position == limit) - { - throw new BufferOverflowException(); - } - byteBuffer.PutInt64(position++ << 3, c); - return this; - } - - - public override Int64Buffer Put(int index, long c) - { - if (index < 0 || index >= limit) - { - throw new IndexOutOfRangeException(); - } - byteBuffer.PutInt64(index << 3, c); - return this; - } - - - public override Int64Buffer Slice() - { - byteBuffer.SetLimit(limit << 3); - byteBuffer.SetPosition(position << 3); - Int64Buffer result = new Int64ToByteBufferAdapter(byteBuffer.Slice()); - byteBuffer.Clear(); - return result; - } - } -} diff --git a/src/Lucene.Net/Support/IO/MemoryMappedFileByteBuffer.cs b/src/Lucene.Net/Support/IO/MemoryMappedFileByteBuffer.cs index d458c19..ccd2a85 100644 --- a/src/Lucene.Net/Support/IO/MemoryMappedFileByteBuffer.cs +++ b/src/Lucene.Net/Support/IO/MemoryMappedFileByteBuffer.cs @@ -328,13 +328,13 @@ namespace Lucene.Net.Support.IO } } - /// <summary> - /// NOTE: This was asLongBuffer() in the JDK - /// </summary> - public override Int64Buffer AsInt64Buffer() - { - throw new NotSupportedException(); - } + ///// <summary> + ///// NOTE: This was asLongBuffer() in the JDK + ///// </summary> + //public override Int64Buffer AsInt64Buffer() + //{ + // throw new NotSupportedException(); + //} protected override byte[] ProtectedArray { diff --git a/src/Lucene.Net/Support/IO/ReadWriteLongArrayBuffer.cs b/src/Lucene.Net/Support/IO/ReadWriteLongArrayBuffer.cs deleted file mode 100644 index 6bbdcbf..0000000 --- a/src/Lucene.Net/Support/IO/ReadWriteLongArrayBuffer.cs +++ /dev/null @@ -1,144 +0,0 @@ -// This class was sourced from the Apache Harmony project -// https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/ - -using System; - -namespace Lucene.Net.Support.IO -{ - /* - * 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. - */ - - /// <summary> - /// LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose - /// the implementation of array based long buffers. - /// <para/> - /// ReadWriteLongArrayBuffer extends LongArrayBuffer with all the write methods. - /// <para/> - /// This class is marked final for runtime performance. - /// </summary> - internal sealed class ReadWriteInt64ArrayBuffer : Int64ArrayBuffer - { - internal static ReadWriteInt64ArrayBuffer Copy(Int64ArrayBuffer other, int markOfOther) - { - ReadWriteInt64ArrayBuffer buf = new ReadWriteInt64ArrayBuffer(other - .Capacity, other.backingArray, other.offset); - buf.limit = other.Limit; - buf.position = other.Position; - buf.mark = markOfOther; - return buf; - } - - internal ReadWriteInt64ArrayBuffer(long[] array) - : base(array) - { - } - - internal ReadWriteInt64ArrayBuffer(int capacity) - : base(capacity) - { - } - - internal ReadWriteInt64ArrayBuffer(int capacity, long[] backingArray, int arrayOffset) - : base(capacity, backingArray, arrayOffset) - { - } - - - public override Int64Buffer AsReadOnlyBuffer() - { - throw new NotImplementedException(); - //return ReadOnlyLongArrayBuffer.copy(this, mark); - } - - public override Int64Buffer Compact() - { - System.Array.Copy(backingArray, position + offset, backingArray, offset, - Remaining); - position = limit - position; - limit = capacity; - mark = UNSET_MARK; - return this; - } - - public override Int64Buffer Duplicate() - { - return Copy(this, mark); - } - - public override bool IsReadOnly - { - get { return false; } - } - - protected override long[] ProtectedArray - { - get { return backingArray; } - } - - protected override int ProtectedArrayOffset - { - get { return offset; } - } - - protected override bool ProtectedHasArray - { - get { return true; } - } - - public override Int64Buffer Put(long c) - { - if (position == limit) - { - throw new BufferOverflowException(); - } - backingArray[offset + position++] = c; - return this; - } - - public override Int64Buffer Put(int index, long c) - { - if (index < 0 || index >= limit) - { - throw new IndexOutOfRangeException(); - } - backingArray[offset + index] = c; - return this; - } - - public override Int64Buffer Put(long[] src, int off, int len) - { - int length = src.Length; - if (off < 0 || len < 0 || (long)off + (long)len > length) - { - throw new IndexOutOfRangeException(); - } - if (len > Remaining) - { - throw new BufferOverflowException(); - } - System.Array.Copy(src, off, backingArray, offset + position, len); - position += len; - return this; - } - - public override Int64Buffer Slice() - { - return new ReadWriteInt64ArrayBuffer(Remaining, backingArray, offset - + position); - } - } -}
