diff --git a/jre/src/main/java/com/azure/data/cosmos/core/Utf8String.java b/jre/src/main/java/com/azure/data/cosmos/core/Utf8String.java index 16755af..0f61788 100644 --- a/jre/src/main/java/com/azure/data/cosmos/core/Utf8String.java +++ b/jre/src/main/java/com/azure/data/cosmos/core/Utf8String.java @@ -7,7 +7,6 @@ package com.azure.data.cosmos.core; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; @@ -17,7 +16,6 @@ import com.fasterxml.jackson.databind.node.JsonNodeType; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.google.common.base.Utf8; import io.netty.buffer.ByteBuf; -import io.netty.buffer.PooledByteBufAllocator; import io.netty.buffer.Unpooled; import javax.annotation.Nonnull; @@ -44,7 +42,6 @@ public final class Utf8String implements CharSequence, Comparable { public static final Utf8String EMPTY = new Utf8String(Unpooled.EMPTY_BUFFER, 0); public static final Utf8String NULL = new Utf8String(); - private static final PooledByteBufAllocator allocator = PooledByteBufAllocator.DEFAULT; private final ByteBuf buffer; private final int length; @@ -303,7 +300,7 @@ public final class Utf8String implements CharSequence, Comparable { } final int length = Utf8.encodedLength(string); - final ByteBuf buffer = allocator.buffer(length, length); + final ByteBuf buffer = Unpooled.wrappedBuffer(new byte[length]); final int count = buffer.writeCharSequence(string, UTF_8); checkState(count == length, "count: %s, length: %s", count, length); @@ -400,24 +397,24 @@ public final class Utf8String implements CharSequence, Comparable { // 110xxxxx 10xxxxxx => 0x00000080 - 0x000007FF codePoint = ((leadingByte & 0b0001_1111) << 6) | - (buffer.getByte(this.index++) & 0b0011_1111); + (this.buffer.getByte(this.index++) & 0b0011_1111); } else if ((leadingByte & 0b1111_0000) == 0b1110_0000) { // 1110xxxx 10xxxxxx 10xxxxxx => 0x00000800 - 0x0000FFFF codePoint = ((leadingByte & 0b0000_1111) << 12) | - ((buffer.getByte(this.index++) & 0b0011_1111) << 6) | - ((buffer.getByte(this.index++) & 0b0011_1111)); + ((this.buffer.getByte(this.index++) & 0b0011_1111) << 6) | + ((this.buffer.getByte(this.index++) & 0b0011_1111)); } else if ((leadingByte & 0b1111_1000) == 0b1111_0000) { // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx => 0x00010000 - 0x001FFFFF codePoint = ((leadingByte & 0b0000_0111) << 18) | - ((buffer.getByte(this.index++) & 0b0011_1111) << 12) | - ((buffer.getByte(this.index++) & 0b0011_1111) << 6) | - ((buffer.getByte(this.index++) & 0b0011_1111)); + ((this.buffer.getByte(this.index++) & 0b0011_1111) << 12) | + ((this.buffer.getByte(this.index++) & 0b0011_1111) << 6) | + ((this.buffer.getByte(this.index++) & 0b0011_1111)); } else { // leading byte is improperly encoded and we'll detect that before returning @@ -460,8 +457,7 @@ public final class Utf8String implements CharSequence, Comparable { } @Override - public Utf8String deserialize(JsonParser parser, DeserializationContext context) throws IOException, - JsonProcessingException { + public Utf8String deserialize(JsonParser parser, DeserializationContext context) throws IOException { final JsonNode node = parser.getCodec().readTree(parser); final JsonNodeType type = node.getNodeType(); diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowHeader.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowHeader.java index b79a22d..ef0755c 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowHeader.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowHeader.java @@ -5,47 +5,39 @@ package com.azure.data.cosmos.serialization.hybridrow; /** - * Describes the header the precedes all valid Hybrid Rows. + * Describes the header that precedes all valid Hybrid Rows. */ -// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: -//ORIGINAL LINE: [StructLayout(LayoutKind.Sequential, Pack = 1)] public readonly struct HybridRowHeader -//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ -// from the original: -//ORIGINAL LINE: [StructLayout(LayoutKind.Sequential, Pack = 1)] public readonly struct HybridRowHeader -//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct: public final class HybridRowHeader { /** * Size (in bytes) of a serialized header. */ - public static final int SIZE = (HybridRowVersion.SIZE / Byte.SIZE) + com.azure.data.cosmos.serialization.hybridrow.SchemaId.SIZE; - /** - * The unique identifier of the schema whose layout was used to write this row. - */ - private SchemaId SchemaId = new SchemaId(); - /** - * The version of the HybridRow library used to write this row. - */ - private HybridRowVersion Version = HybridRowVersion.values()[0]; + public static final int SIZE = (HybridRowVersion.SIZE / Byte.SIZE) + SchemaId.SIZE; + + private SchemaId schemaId; + private HybridRowVersion version = HybridRowVersion.values()[0]; /** - * Initializes a new instance of the {@link HybridRowHeader} struct. + * Initializes a new instance of a {@link HybridRowHeader} * * @param version The version of the HybridRow library used to write this row. * @param schemaId The unique identifier of the schema whose layout was used to write this row. */ - public HybridRowHeader() { - } - public HybridRowHeader(HybridRowVersion version, SchemaId schemaId) { - this.Version = version; - this.SchemaId = schemaId.clone(); + this.version = version; + this.schemaId = new SchemaId(schemaId.id()); } - public SchemaId getSchemaId() { - return SchemaId; + /** + * The unique identifier of the schema whose layout was used to write this row. + */ + public SchemaId schemaId() { + return this.schemaId; } - public HybridRowVersion getVersion() { - return Version; + /** + * The version of the HybridRow library used to write this row. + */ + public HybridRowVersion version() { + return this.version; } } \ No newline at end of file diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowVersion.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowVersion.java index 42646be..d35685a 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowVersion.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/HybridRowVersion.java @@ -4,16 +4,15 @@ package com.azure.data.cosmos.serialization.hybridrow; -// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java: -///#pragma warning disable CA1028 // Enum Storage should be Int32 +import java.util.HashMap; /** - * Versions of HybridRow. + * Versions of HybridRow + *

* A version from this list MUST be inserted in the version BOM at the beginning of all rows. */ -//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: -//ORIGINAL LINE: public enum HybridRowVersion : byte public enum HybridRowVersion { + Invalid((byte)0), /** @@ -23,18 +22,18 @@ public enum HybridRowVersion { public static final int SIZE = java.lang.Byte.SIZE; private static java.util.HashMap mappings; - private byte byteValue; + private byte value; HybridRowVersion(byte value) { - byteValue = value; + this.value = value; getMappings().put(value, this); } - public byte getValue() { - return byteValue; + public byte value() { + return this.value; } - public static HybridRowVersion forValue(byte value) { + public static HybridRowVersion from(byte value) { return getMappings().get(value); } @@ -42,7 +41,7 @@ public enum HybridRowVersion { if (mappings == null) { synchronized (HybridRowVersion.class) { if (mappings == null) { - mappings = new java.util.HashMap(); + mappings = new HashMap<>(); } } } diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java index 8f18521..b987e03 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java @@ -6,6 +6,7 @@ package com.azure.data.cosmos.serialization.hybridrow; import com.azure.data.cosmos.core.Out; import com.azure.data.cosmos.core.Reference; +import com.azure.data.cosmos.core.Utf8String; import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutArray; @@ -39,6 +40,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedArray; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedMap; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedSet; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedTuple; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUDT; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt16; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt32; @@ -52,7 +54,10 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList; import com.azure.data.cosmos.serialization.hybridrow.layouts.UpdateOptions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; +import javax.annotation.Nonnull; import java.io.InputStream; import java.io.OutputStream; import java.math.BigDecimal; @@ -61,87 +66,71 @@ import java.util.Optional; import java.util.UUID; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Strings.lenientFormat; //import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType.MongoDbObjectId; +/** + * Manages a sequence of bytes representing a Hybrid Row + *

+ * A Hybrid Row begins in the 0-th byte of the {@link RowBuffer}. The sequence of bytes is defined by the Hybrid Row + * grammar. + */ public final class RowBuffer { - /** - * A sequence of bytes managed by this {@link RowBuffer}. - *

- * A Hybrid Row begins in the 0-th byte of the {@link RowBuffer}. Remaining byte - * sequence is defined by the Hybrid Row grammar. - */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: private Span buffer; - private Span buffer; - private int length; - /** - * Resizer for growing the memory buffer. - */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: private readonly ISpanResizer resizer; - private ISpanResizer resizer; - /** - * The resolver for UDTs. - */ + + private final ByteBuf buffer; private LayoutResolver resolver; /** - * Initializes a new instance of the {@link RowBuffer} struct. + * Initializes a new instance of a {@link RowBuffer} * * @param capacity Initial buffer capacity. - * @param resizer Optional memory resizer. */ - public RowBuffer(int capacity) { - this(capacity, null); + this(capacity, ByteBufAllocator.DEFAULT); } - public RowBuffer() { - } + /** + * Initializes a new instance of a {@link RowBuffer} + * + * @param capacity Initial buffer capacity + * @param allocator A buffer allocator + */ + public RowBuffer(final int capacity, @Nonnull final ByteBufAllocator allocator) { - public RowBuffer(int capacity, ISpanResizer resizer) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: this.resizer = resizer != null ? resizer : DefaultSpanResizer.Default; - this.resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default; - this.buffer = this.resizer.Resize(capacity); - this.length(0); + checkNotNull(allocator, "allocator"); + checkArgument(capacity > 0, "capacity: %s", capacity); + + this.buffer = allocator.buffer(capacity); this.resolver = null; } /** - * Initializes a new instance of the {@link RowBuffer} struct from an existing buffer. + * Initializes a new instance of a {@link RowBuffer} from an existing buffer * - * @param buffer The buffer. The row takes ownership of the buffer and the caller should not - * maintain a pointer or mutate the buffer after this call returns. - * @param version The version of the Hybrid Row format to used to encoding the buffer. + * @param buffer An existing {@link ByteBuf} containing a Hybrid Row. This instance takes ownership of the buffer. + * Hence, the caller should not maintain a reference to the buffer or mutate the buffer after this + * call returns. + * @param version The version of the Hybrid Row format to use for encoding the buffer. * @param resolver The resolver for UDTs. - * @param resizer Optional memory resizer. */ + public RowBuffer(@Nonnull final ByteBuf buffer, @Nonnull final HybridRowVersion version, @Nonnull final LayoutResolver resolver) { - public RowBuffer(Span buffer, HybridRowVersion version, LayoutResolver resolver) { - this(buffer, version, resolver, null); - } + checkNotNull(buffer, "buffer"); + checkNotNull(version, "version"); + checkNotNull(resolver, "resolver"); + checkArgument(buffer.isReadable(HybridRowHeader.SIZE)); - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public RowBuffer(Span buffer, HybridRowVersion version, LayoutResolver resolver, - // ISpanResizer resizer = default) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - public RowBuffer(Span buffer, HybridRowVersion version, LayoutResolver resolver, ISpanResizer resizer) { - checkArgument(buffer.Length >= HybridRowHeader.SIZE); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: this.resizer = resizer != null ? resizer : DefaultSpanResizer.Default; - this.resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default; - this.length(buffer.Length); this.buffer = buffer; this.resolver = resolver; - HybridRowHeader header = this.ReadHeader(0).clone(); - checkState(header.getVersion() == version); - Layout layout = resolver.Resolve(header.getSchemaId().clone()); - checkState(SchemaId.opEquals(header.getSchemaId().clone(), layout.schemaId().clone())); + HybridRowHeader header = this.readHeader(); + checkState(header.version() == version, "expected version %s, not %s", version, header.version()); + + Layout layout = resolver.resolve(header.schemaId()); + checkState(header.schemaId().equals(layout.schemaId())); checkState(HybridRowHeader.SIZE + layout.size() <= this.length()); } @@ -156,133 +145,21 @@ public final class RowBuffer { * default values. All variable columns are null. No sparse columns are present. The row is * valid. */ - public void InitLayout(HybridRowVersion version, Layout layout, LayoutResolver resolver) { - checkArgument(layout != null); - this.resolver = resolver; + public void initLayout(HybridRowVersion version, Layout layout, LayoutResolver resolver) { + + checkNotNull(version, "version"); + checkNotNull(layout, "layout"); + checkNotNull(resolver, "resolver"); // Ensure sufficient space for fixed schema fields. - this.Ensure(HybridRowHeader.SIZE + layout.size()); - this.length(HybridRowHeader.SIZE + layout.size()); + this.ensure(HybridRowHeader.SIZE + layout.size()); // Clear all presence bits. this.buffer.Slice(HybridRowHeader.SIZE, layout.size()).Fill(0); // Set the header. - this.WriteHeader(0, new HybridRowHeader(version, layout.schemaId().clone())); - } - - /** - * Compute the byte offsets from the beginning of the row for a given sparse field insertion - * into a set/map. - * - * @param scope The sparse scope to insert into. - * @param srcEdit The field to move into the set/map. - * @return The prepared edit context. - */ - public RowCursor PrepareSparseMove(Reference scope, Reference srcEdit) { - checkArgument(scope.get().scopeType().isUniqueScope()); - - checkArgument(scope.get().index() == 0); - RowCursor dstEdit; - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these - // cannot be converted using the 'Out' helper class unless the method is within the code being modified: - scope.get().Clone(out dstEdit); - - dstEdit.metaOffset(scope.get().valueOffset()); - int srcSize = this.SparseComputeSize(srcEdit); - int srcBytes = srcSize - (srcEdit.get().valueOffset() - srcEdit.get().metaOffset()); - while (dstEdit.index() < dstEdit.count()) { - Reference tempReference_dstEdit = - new Reference(dstEdit); - this.ReadSparseMetadata(tempReference_dstEdit); - dstEdit = tempReference_dstEdit.get(); - Contract.Assert(dstEdit.pathOffset == - default) - - int elmSize = -1; // defer calculating the full size until needed. - int cmp; - if (scope.get().scopeType() instanceof LayoutTypedMap) { - cmp = this.CompareKeyValueFieldValue(srcEdit.get().clone(), dstEdit); - } else { - Reference tempReference_dstEdit2 = - new Reference(dstEdit); - elmSize = this.SparseComputeSize(tempReference_dstEdit2); - dstEdit = tempReference_dstEdit2.get(); - int elmBytes = elmSize - (dstEdit.valueOffset() - dstEdit.metaOffset()); - cmp = this.CompareFieldValue(srcEdit.get().clone(), srcBytes, dstEdit, elmBytes); - } - - if (cmp <= 0) { - dstEdit.exists = cmp == 0; - return dstEdit; - } - - Reference tempReference_dstEdit3 = - new Reference(dstEdit); - elmSize = (elmSize == -1) ? this.SparseComputeSize(tempReference_dstEdit3) : elmSize; - dstEdit = tempReference_dstEdit3.get(); - dstEdit.index(dstEdit.index() + 1); - dstEdit.metaOffset(dstEdit.metaOffset() + elmSize); - } - - dstEdit.exists = false; - dstEdit.cellType = LayoutType.EndScope; - dstEdit.valueOffset(dstEdit.metaOffset()); - return dstEdit; - } - - /** - * Reads in the contents of the RowBuffer from an input stream and initializes the row buffer - * with the associated layout and rowVersion. - * - * @return true if the serialization succeeded. false if the input stream was corrupted. - */ - public boolean ReadFrom(InputStream inputStream, int bytesCount, HybridRowVersion rowVersion, - LayoutResolver resolver) { - checkArgument(inputStream != null); - checkState(bytesCount >= HybridRowHeader.SIZE); - - this.Reset(); + this.WriteHeader(0, new HybridRowHeader(version, layout.schemaId())); this.resolver = resolver; - this.Ensure(bytesCount); - checkState(this.buffer.Length >= bytesCount); - this.length(bytesCount); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Span active = this.buffer.Slice(0, bytesCount); - Span active = this.buffer.Slice(0, bytesCount); - int bytesRead; - do { - bytesRead = inputStream.Read(active); - active = active.Slice(bytesRead); - } while (bytesRead != 0); - - if (active.Length != 0) { - return false; - } - - return this.InitReadFrom(rowVersion); - } - - /** - * Reads in the contents of the RowBuffer from an existing block of memory and initializes - * the row buffer with the associated layout and rowVersion. - * - * @return true if the serialization succeeded. false if the input stream was corrupted. - */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public bool ReadFrom(ReadOnlySpan input, HybridRowVersion rowVersion, LayoutResolver - // resolver) - public boolean ReadFrom(ReadOnlySpan input, HybridRowVersion rowVersion, LayoutResolver resolver) { - int bytesCount = input.Length; - checkState(bytesCount >= HybridRowHeader.SIZE); - - this.Reset(); - this.resolver = resolver; - this.Ensure(bytesCount); - checkState(this.buffer.Length >= bytesCount); - input.CopyTo(this.buffer); - this.length(bytesCount); - return this.InitReadFrom(rowVersion); } /** @@ -300,8 +177,8 @@ public final class RowBuffer { while (value >= 0x80L) { i++; //C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift - // operator since the left operand was originally of an unsigned type, but you should confirm this - // replacement: + // operator since the left operand was originally of an unsigned type, but you should confirm this + // replacement: value >>>= 7; } @@ -309,6 +186,120 @@ public final class RowBuffer { return i; } + /** + * Reads in the contents of the RowBuffer from an input stream and initializes the row buffer + * with the associated layout and rowVersion. + * + * @return true if the serialization succeeded. false if the input stream was corrupted. + */ + public boolean readFrom(@Nonnull final InputStream inputStream, final int byteCount, @Nonnull final HybridRowVersion version, @Nonnull final LayoutResolver resolver) { + + checkNotNull(inputStream, "inputStream"); + checkNotNull(resolver, "resolver"); + checkNotNull(version, "version"); + checkState(byteCount >= HybridRowHeader.SIZE, "expected byteCount >= %s, not %s", HybridRowHeader.SIZE, byteCount); + + this.reset(); + this.ensure(byteCount); + this.resolver = resolver; + + Span active = this.buffer.Slice(0, byteCount); + int bytesRead; + + do { + bytesRead = inputStream.Read(active); + active = active.Slice(bytesRead); + } while (bytesRead != 0); + + if (active.Length != 0) { + return false; + } + + return this.InitReadFrom(version); + } + + /** + * Compute the byte offsets from the beginning of the row for a given sparse field insertion + * into a set/map. + * + * @param scope The sparse scope to insert into. + * @param srcEdit The field to move into the set/map. + * @return The prepared edit context. + */ + public RowCursor PrepareSparseMove(Reference scope, Reference srcEdit) { + checkArgument(scope.get().scopeType().isUniqueScope()); + + checkArgument(scope.get().index() == 0); + RowCursor dstEdit; + // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these + // cannot be converted using the 'Out' helper class unless the method is within the code being modified: + scope.get().Clone(out dstEdit); + + dstEdit.metaOffset(scope.get().valueOffset()); + int srcSize = this.sparseComputeSize(srcEdit); + int srcBytes = srcSize - (srcEdit.get().valueOffset() - srcEdit.get().metaOffset()); + while (dstEdit.index() < dstEdit.count()) { + Reference tempReference_dstEdit = + new Reference(dstEdit); + this.readSparseMetadata(tempReference_dstEdit); + dstEdit = tempReference_dstEdit.get(); + Contract.Assert(dstEdit.pathOffset() == + default) + + int elmSize = -1; // defer calculating the full size until needed. + int cmp; + if (scope.get().scopeType() instanceof LayoutTypedMap) { + cmp = this.CompareKeyValueFieldValue(srcEdit.get().clone(), dstEdit); + } else { + Reference tempReference_dstEdit2 = + new Reference(dstEdit); + elmSize = this.sparseComputeSize(tempReference_dstEdit2); + dstEdit = tempReference_dstEdit2.get(); + int elmBytes = elmSize - (dstEdit.valueOffset() - dstEdit.metaOffset()); + cmp = this.CompareFieldValue(srcEdit.get().clone(), srcBytes, dstEdit, elmBytes); + } + + if (cmp <= 0) { + dstEdit.exists = cmp == 0; + return dstEdit; + } + + Reference tempReference_dstEdit3 = + new Reference(dstEdit); + elmSize = (elmSize == -1) ? this.sparseComputeSize(tempReference_dstEdit3) : elmSize; + dstEdit = tempReference_dstEdit3.get(); + dstEdit.index(dstEdit.index() + 1); + dstEdit.metaOffset(dstEdit.metaOffset() + elmSize); + } + + dstEdit.exists = false; + dstEdit.cellType = LayoutType.EndScope; + dstEdit.valueOffset(dstEdit.metaOffset()); + return dstEdit; + } + + /** + * Reads in the contents of the RowBuffer from an existing block of memory and initializes + * the row buffer with the associated layout and rowVersion. + * + * @return true if the serialization succeeded. false if the input stream was corrupted. + */ + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: public bool ReadFrom(ReadOnlySpan input, HybridRowVersion rowVersion, LayoutResolver + // resolver) + public boolean readFrom(ReadOnlySpan input, HybridRowVersion rowVersion, LayoutResolver resolver) { + int bytesCount = input.Length; + checkState(bytesCount >= HybridRowHeader.SIZE); + + this.reset(); + this.resolver = resolver; + this.ensure(bytesCount); + checkState(this.buffer.Length >= bytesCount); + input.CopyTo(this.buffer); + this.length(bytesCount); + return this.InitReadFrom(rowVersion); + } + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: internal void DecrementUInt32(int offset, uint decrement) public void DecrementUInt32(int offset, int decrement) { @@ -317,59 +308,10 @@ public final class RowBuffer { MemoryMarshal.Cast(this.buffer.Slice(offset))[0] -= decrement; } - /** - * Delete the sparse field at the indicated path. - * - * @param edit The field to delete. - */ - public void deleteSparse(Reference edit) { - // If the field doesn't exist, then nothing to do. - if (!edit.get().exists) { - return; - } - - int numBytes = 0; - int _; - Out tempOut__ = new Out(); - int _; - Out tempOut__2 = new Out(); - int shift; - Out tempOut_shift = new Out(); - this.EnsureSparse(edit, edit.get().cellType, edit.get().cellTypeArgs.clone(), numBytes, - RowOptions.Delete, tempOut__, tempOut__2, tempOut_shift); - shift = tempOut_shift.get(); - _ = tempOut__2.get(); - _ = tempOut__.get(); - this.length(this.length() + shift); - } - - public void DeleteVariable(int offset, boolean isVarint) { - int spaceAvailable; - Out tempOut_spaceAvailable = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ulong existingValueBytes = this.Read7BitEncodedUInt(offset, out int spaceAvailable); - long existingValueBytes = this.Read7BitEncodedUInt(offset, tempOut_spaceAvailable); - spaceAvailable = tempOut_spaceAvailable.get(); - if (!isVarint) { - spaceAvailable += (int)existingValueBytes; // "size" already in spaceAvailable - } - - this.buffer.Slice(offset + spaceAvailable, this.length() - (offset + spaceAvailable)).CopyTo(this.buffer.Slice(offset)); - this.length(this.length() - spaceAvailable); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void IncrementUInt32(int offset, uint increment) - public void IncrementUInt32(int offset, int increment) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: MemoryMarshal.Cast(this.buffer.Slice(offset))[0] += increment; - MemoryMarshal.Cast(this.buffer.Slice(offset))[0] += increment; - } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: internal ReadOnlySpan ReadSparseBinary(ref RowCursor edit) public ReadOnlySpan ReadSparseBinary(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Binary); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Binary); int sizeLenInBytes; Out tempOut_sizeLenInBytes = new Out(); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @@ -380,45 +322,64 @@ public final class RowBuffer { return span; } - public boolean ReadSparseBool(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Boolean); - edit.get().endOffset = edit.get().valueOffset(); - return edit.get().cellType == LayoutType.Boolean; - } + public void deleteVariable(int offset, boolean isVarint) { - public long Read7BitEncodedInt(int offset, Out lenInBytes) { - return RowBuffer.RotateSignToMsb(this.Read7BitEncodedUInt(offset, lenInBytes)); + int start = this.buffer.readerIndex(); + this.read7BitEncodedUInt(); + + ByteBuf remainder = this.buffer.slice(this.buffer.readerIndex(), this.buffer.readableBytes()); + this.buffer.readerIndex(start); + this.buffer.setBytes(start, remainder); + this.buffer.writerIndex(start + remainder.readableBytes()); } //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ulong Read7BitEncodedUInt(int offset, out int lenInBytes) - public long Read7BitEncodedUInt(int offset, Out lenInBytes) { - // Read out an unsigned long 7 bits at a time. The high bit of the byte, - // when set, indicates there are more bytes. + //ORIGINAL LINE: internal void IncrementUInt32(int offset, uint increment) + public void IncrementUInt32(int offset, int increment) { //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ulong b = this.buffer[offset]; - long b = this.buffer[offset]; + //ORIGINAL LINE: MemoryMarshal.Cast(this.buffer.Slice(offset))[0] += increment; + MemoryMarshal.Cast(this.buffer.Slice(offset))[0] += increment; + } + + public boolean ReadSparseBool(Reference edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutType.Boolean); + edit.get().endOffset = edit.get().valueOffset(); + return edit.get().cellType() == LayoutType.Boolean; + } + + public LocalDateTime ReadSparseDateTime(Reference edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutType.DateTime); + edit.get().endOffset = edit.get().valueOffset() + 8; + return this.ReadDateTime(edit.get().valueOffset()); + } + + public long Read7BitEncodedInt(int offset, Out lenInBytes) { + return RowBuffer.RotateSignToMsb(this.read7BitEncodedUInt(offset, lenInBytes)); + } + + public long read7BitEncodedUInt() { + + long b = this.buffer.readByte() & 0xFFL; + if (b < 0x80L) { - lenInBytes.setAndGet(1); return b; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ulong retval = b & 0x7F; - long retval = b & 0x7F; + long result = b & 0x7FL; int shift = 7; + do { checkState(shift < 10 * 7); - b = this.buffer[++offset]; - retval |= (b & 0x7F) << shift; + b = this.buffer.readByte() & 0xFFL; + result |= (b & 0x7FL) << shift; shift += 7; } while (b >= 0x80L); - lenInBytes.setAndGet(shift / 7); - return retval; + return result; } public boolean ReadBit(int offset, LayoutBit bit) { + if (bit.getIsInvalid()) { return true; } @@ -459,25 +420,27 @@ public final class RowBuffer { return MemoryMarshal.Read(this.buffer.Slice(offset)); } - public LocalDateTime ReadSparseDateTime(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.DateTime); - edit.get().endOffset = edit.get().valueOffset() + 8; - return this.ReadDateTime(edit.get().valueOffset()); - } - public BigDecimal ReadSparseDecimal(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Decimal); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Decimal); // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'sizeof': edit.get().endOffset = edit.get().valueOffset() + sizeof(BigDecimal); return this.ReadDecimal(edit.get().valueOffset()); } + public Float128 ReadSparseFloat128(Reference edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutType.Float128); + edit.get().endOffset = edit.get().valueOffset() + Float128.Size; + return this.ReadFloat128(edit.get().valueOffset()).clone(); + } + public UUID ReadGuid(int offset) { return MemoryMarshal.Read(this.buffer.Slice(offset)); } - public HybridRowHeader ReadHeader(int offset) { - return MemoryMarshal.Read(this.buffer.Slice(offset)); + public float ReadSparseFloat32(Reference edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutType.Float32); + edit.get().endOffset = edit.get().valueOffset() + (Float.SIZE / Byte.SIZE); + return this.ReadFloat32(edit.get().valueOffset()); } public short ReadInt16(int offset) { @@ -506,121 +469,54 @@ public final class RowBuffer { return new SchemaId(this.ReadInt32(offset)); } - public Float128 ReadSparseFloat128(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Float128); - edit.get().endOffset = edit.get().valueOffset() + Float128.Size; - return this.ReadFloat128(edit.get().valueOffset()).clone(); - } - - public float ReadSparseFloat32(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Float32); - edit.get().endOffset = edit.get().valueOffset() + (Float.SIZE / Byte.SIZE); - return this.ReadFloat32(edit.get().valueOffset()); - } - public double ReadSparseFloat64(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Float64); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Float64); edit.get().endOffset = edit.get().valueOffset() + (Double.SIZE / Byte.SIZE); return this.ReadFloat64(edit.get().valueOffset()); } public UUID ReadSparseGuid(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Guid); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Guid); edit.get().endOffset = edit.get().valueOffset() + 16; return this.ReadGuid(edit.get().valueOffset()); } public short ReadSparseInt16(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Int16); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Int16); edit.get().endOffset = edit.get().valueOffset() + (Short.SIZE / Byte.SIZE); return this.ReadInt16(edit.get().valueOffset()); } public int ReadSparseInt32(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Int32); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Int32); edit.get().endOffset = edit.get().valueOffset() + (Integer.SIZE / Byte.SIZE); return this.ReadInt32(edit.get().valueOffset()); } public long ReadSparseInt64(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Int64); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Int64); edit.get().endOffset = edit.get().valueOffset() + (Long.SIZE / Byte.SIZE); return this.ReadInt64(edit.get().valueOffset()); } public byte ReadSparseInt8(Reference edit) { // TODO: Remove calls to ReadSparsePrimitiveTypeCode once moved to V2 read. - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Int8); + this.readSparsePrimitiveTypeCode(edit, LayoutType.Int8); edit.get().endOffset = edit.get().valueOffset() + (Byte.SIZE / Byte.SIZE); return this.ReadInt8(edit.get().valueOffset()); } public MongoDbObjectId ReadSparseMongoDbObjectId(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, MongoDbObjectId); + this.readSparsePrimitiveTypeCode(edit, MongoDbObjectId); edit.get().endOffset = edit.get().valueOffset() + MongoDbObjectId.Size; return this.ReadMongoDbObjectId(edit.get().valueOffset()).clone(); } - public NullValue ReadSparseNull(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Null); - edit.get().endOffset = edit.get().valueOffset(); - return NullValue.Default; - } - - public Utf8Span ReadSparsePath(Reference edit) { - Utf8String path; - Out tempOut_path = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: if (edit.layout.Tokenizer.TryFindString((ulong)edit.pathToken, out Utf8String path)) - if (edit.get().layout().getTokenizer().TryFindString(edit.get().longValue().pathToken, tempOut_path)) { - path = tempOut_path.get(); - return path.Span; - } else { - path = tempOut_path.get(); - } - - int numBytes = edit.get().pathToken - edit.get().layout().getTokenizer().getCount(); - return Utf8Span.UnsafeFromUtf8BytesNoValidation(this.buffer.Slice(edit.get().pathOffset, numBytes)); - } - - public Utf8Span ReadSparseString(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.Utf8); - int sizeLenInBytes; - Out tempOut_sizeLenInBytes = new Out(); - Utf8Span span = this.ReadString(edit.get().valueOffset(), tempOut_sizeLenInBytes); - sizeLenInBytes = tempOut_sizeLenInBytes.get(); - edit.get().endOffset = edit.get().valueOffset() + sizeLenInBytes + span.Length; - return span; - } - - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal LayoutType ReadSparseTypeCode(int - // offset) - public LayoutType ReadSparseTypeCode(int offset) { - return LayoutType.FromCode(LayoutCode.forValue(this.ReadUInt8(offset))); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ushort ReadSparseUInt16(ref RowCursor edit) - public short ReadSparseUInt16(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.UInt16); - edit.get().endOffset = edit.get().valueOffset() + (Short.SIZE / Byte.SIZE); - return this.ReadUInt16(edit.get().valueOffset()); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal uint ReadSparseUInt32(ref RowCursor edit) - public int ReadSparseUInt32(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.UInt32); - edit.get().endOffset = edit.get().valueOffset() + (Integer.SIZE / Byte.SIZE); - return this.ReadUInt32(edit.get().valueOffset()); - } - public int ReadSparsePathLen(Layout layout, int offset, Out pathLenInBytes, - Out pathOffset) { + Out pathOffset) { int sizeLenInBytes; Out tempOut_sizeLenInBytes = new Out(); - int token = (int)this.Read7BitEncodedUInt(offset, tempOut_sizeLenInBytes); + int token = (int)this.read7BitEncodedUInt(offset, tempOut_sizeLenInBytes); sizeLenInBytes = tempOut_sizeLenInBytes.get(); if (token < layout.getTokenizer().getCount()) { pathLenInBytes.setAndGet(sizeLenInBytes); @@ -634,30 +530,63 @@ public final class RowBuffer { return token; } + public Utf8Span ReadSparseString(Reference edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutType.Utf8); + int sizeLenInBytes; + Out tempOut_sizeLenInBytes = new Out(); + Utf8Span span = this.ReadString(edit.get().valueOffset(), tempOut_sizeLenInBytes); + sizeLenInBytes = tempOut_sizeLenInBytes.get(); + edit.get().endOffset = edit.get().valueOffset() + sizeLenInBytes + span.Length; + return span; + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: internal ushort ReadSparseUInt16(ref RowCursor edit) + public short ReadSparseUInt16(Reference edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt16); + edit.get().endOffset = edit.get().valueOffset() + (Short.SIZE / Byte.SIZE); + return this.ReadUInt16(edit.get().valueOffset()); + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: internal uint ReadSparseUInt32(ref RowCursor edit) + public int ReadSparseUInt32(Reference edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt32); + edit.get().endOffset = edit.get().valueOffset() + (Integer.SIZE / Byte.SIZE); + return this.ReadUInt32(edit.get().valueOffset()); + } + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: internal ulong ReadSparseUInt64(ref RowCursor edit) public long ReadSparseUInt64(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.UInt64); + this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt64); edit.get().endOffset = edit.get().valueOffset() + (Long.SIZE / Byte.SIZE); return this.ReadUInt64(edit.get().valueOffset()); } + // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: + //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal LayoutType ReadSparseTypeCode(int + // offset) + public LayoutType ReadSparseTypeCode(int offset) { + return LayoutType.FromCode(LayoutCode.forValue(this.ReadUInt8(offset))); + } + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: internal byte ReadSparseUInt8(ref RowCursor edit) public byte ReadSparseUInt8(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.UInt8); + this.readSparsePrimitiveTypeCode(edit, LayoutType.UInt8); edit.get().endOffset = edit.get().valueOffset() + 1; return this.ReadUInt8(edit.get().valueOffset()); } public UnixDateTime ReadSparseUnixDateTime(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.UnixDateTime); + this.readSparsePrimitiveTypeCode(edit, LayoutType.UnixDateTime); edit.get().endOffset = edit.get().valueOffset() + 8; return this.ReadUnixDateTime(edit.get().valueOffset()).clone(); } public long ReadSparseVarInt(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.VarInt); + this.readSparsePrimitiveTypeCode(edit, LayoutType.VarInt); int sizeLenInBytes; Out tempOut_sizeLenInBytes = new Out(); long value = this.Read7BitEncodedInt(edit.get().valueOffset(), tempOut_sizeLenInBytes); @@ -666,78 +595,65 @@ public final class RowBuffer { return value; } + /** + * Rotates the sign bit of a two's complement value to the least significant bit. + * + * @param value A signed value. + * @return An unsigned value encoding the same value but with the sign bit in the LSB. + *

+ * Moves the signed bit of a two's complement value to the least significant bit (LSB) by: + * + * + * If negative, take the two's complement. + * + * Left shift the value by 1 bit. + * + * If negative, set the LSB to 1. + * + * + */ + // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: + //ORIGINAL LINE: [SuppressMessage("StyleCop.CSharp.DocumentationRules", + // "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Colon.")] internal static ulong RotateSignToLsb + // (long value) //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ulong ReadSparseVarUInt(ref RowCursor edit) - public long ReadSparseVarUInt(Reference edit) { - this.ReadSparsePrimitiveTypeCode(edit, LayoutType.VarUInt); - int sizeLenInBytes; - Out tempOut_sizeLenInBytes = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ulong value = this.Read7BitEncodedUInt(edit.valueOffset, out int sizeLenInBytes); - long value = this.Read7BitEncodedUInt(edit.get().valueOffset(), tempOut_sizeLenInBytes); - sizeLenInBytes = tempOut_sizeLenInBytes.get(); - edit.get().endOffset = edit.get().valueOffset() + sizeLenInBytes; - return value; + //ORIGINAL LINE: [SuppressMessage("StyleCop.CSharp.DocumentationRules", + // "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Colon.")] internal static ulong RotateSignToLsb + // (long value) + public static long RotateSignToLsb(long value) { + // Rotate sign to LSB + // TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java: + unchecked + { + boolean isNegative = value < 0; + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: ulong uvalue = (ulong)value; + long uvalue = value; + uvalue = isNegative ? ((~uvalue + 1) << 1) + 1 : uvalue << 1; + return uvalue; + } } /** - * Move a sparse iterator to the next field within the same sparse scope. + * Undoes the rotation introduced by {@link RotateSignToLsb}. * - * @param edit The iterator to advance. - * - * - * On success, the path of the field at the given offset, otherwise - * undefined. - * - * - * If found, the offset to the metadata of the field, otherwise a - * location to insert the field. - * - * - * If found, the layout code of the matching field found, otherwise - * undefined. - * - * - * If found, the offset to the value of the field, otherwise - * undefined. - * . - * @return True if there is another field, false if there are no more. + * @param uvalue An unsigned value with the sign bit in the LSB. + * @return A signed two's complement value encoding the same value. */ - public boolean SparseIteratorMoveNext(Reference edit) { - if (edit.get().cellType != null) { - // Move to the next element of an indexed scope. - if (edit.get().scopeType().isIndexedScope()) { - edit.get().index(edit.get().index() + 1); - } - - // Skip forward to the end of the current value. - if (edit.get().endOffset != 0) { - edit.get().metaOffset(edit.get().endOffset); - edit.get().endOffset = 0; - } else { - edit.get().metaOffset(edit.get().metaOffset() + this.SparseComputeSize(edit)); - } + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: internal static long RotateSignToMsb(ulong uvalue) + public static long RotateSignToMsb(long uvalue) { + // Rotate sign to MSB + // TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java: + unchecked + { + boolean isNegative = uvalue % 2 != 0; + //C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift + // operator since the left operand was originally of an unsigned type, but you should confirm this + // replacement: + long value = isNegative ? (~(uvalue >>> 1) + 1) | 0x8000000000000000 : uvalue >>> 1; + return value; } - - // Check if reached end of buffer. - if (edit.get().metaOffset() < this.length()) { - // Check if reached end of sized scope. - if (!edit.get().scopeType().isSizedScope() || (edit.get().index() != edit.get().count())) { - // Read the metadata. - this.ReadSparseMetadata(edit); - - // Check if reached end of sparse scope. - if (!(edit.get().cellType instanceof LayoutEndScope)) { - edit.get().exists = true; - return true; - } - } - } - - edit.get().cellType = LayoutType.EndScope; - edit.get().exists = false; - edit.get().valueOffset(edit.get().metaOffset()); - return false; } /** @@ -749,12 +665,12 @@ public final class RowBuffer { */ public RowCursor SparseIteratorReadScope(Reference edit, boolean immutable) { - LayoutScope scopeType = edit.get().cellType instanceof LayoutScope ? (LayoutScope) edit.get().cellType : null; + LayoutScope scopeType = edit.get().cellType() instanceof LayoutScope ? (LayoutScope) edit.get().cellType() : null; if (scopeType instanceof LayoutObject || scopeType instanceof LayoutArray) { return new RowCursor() .scopeType(scopeType) - .scopeTypeArgs(edit.get().cellTypeArgs) + .scopeTypeArgs(edit.get().cellTypeArgs()) .start(edit.get().valueOffset()) .valueOffset(edit.get().valueOffset()) .metaOffset(edit.get().valueOffset()) @@ -768,7 +684,7 @@ public final class RowBuffer { return new RowCursor() .scopeType(scopeType) - .scopeTypeArgs(edit.get().cellTypeArgs) + .scopeTypeArgs(edit.get().cellTypeArgs()) .start(edit.get().valueOffset()) .valueOffset(valueOffset) .metaOffset(valueOffset) @@ -781,13 +697,13 @@ public final class RowBuffer { return new RowCursor() .scopeType(scopeType) - .scopeTypeArgs(edit.get().cellTypeArgs) + .scopeTypeArgs(edit.get().cellTypeArgs()) .start(edit.get().valueOffset()) .valueOffset(edit.get().valueOffset()) .metaOffset(edit.get().valueOffset()) .layout(edit.get().layout()) .immutable(immutable) - .count(edit.get().cellTypeArgs.count()); + .count(edit.get().cellTypeArgs().count()); } if (scopeType instanceof LayoutNullable) { @@ -801,7 +717,7 @@ public final class RowBuffer { return new RowCursor() .scopeType(scopeType) - .scopeTypeArgs(edit.get().cellTypeArgs) + .scopeTypeArgs(edit.get().cellTypeArgs()) .start(edit.get().valueOffset()) .valueOffset(valueOffset) .metaOffset(valueOffset) @@ -812,13 +728,13 @@ public final class RowBuffer { } else { // Start at the end of the scope, instead of at the T, so the T will be skipped. - final TypeArgument typeArg = edit.get().cellTypeArgs.get(0); + final TypeArgument typeArg = edit.get().cellTypeArgs().get(0); final int valueOffset = edit.get().valueOffset() + 1 + this.countDefaultValue(typeArg.type(), typeArg.typeArgs()); return new RowCursor() .scopeType(scopeType) - .scopeTypeArgs(edit.get().cellTypeArgs) + .scopeTypeArgs(edit.get().cellTypeArgs()) .start(edit.get().valueOffset()) .valueOffset(valueOffset) .metaOffset(valueOffset) @@ -831,12 +747,12 @@ public final class RowBuffer { if (scopeType instanceof LayoutUDT) { - final Layout udt = this.resolver.Resolve(edit.get().cellTypeArgs.schemaId()); + final Layout udt = this.resolver.resolve(edit.get().cellTypeArgs().schemaId()); final int valueOffset = this.computeVariableValueOffset(udt, edit.get().valueOffset(), udt.numVariable()); return new RowCursor() .scopeType(scopeType) - .scopeTypeArgs(edit.get().cellTypeArgs) + .scopeTypeArgs(edit.get().cellTypeArgs()) .start(edit.get().valueOffset()) .valueOffset(valueOffset) .metaOffset(valueOffset) @@ -848,8 +764,8 @@ public final class RowBuffer { } public void TypedCollectionMoveField(Reference dstEdit, Reference srcEdit - , RowOptions options) { - int encodedSize = this.SparseComputeSize(srcEdit); + , RowOptions options) { + int encodedSize = this.sparseComputeSize(srcEdit); int numBytes = encodedSize - (srcEdit.get().valueOffset() - srcEdit.get().metaOffset()); // Insert the field metadata into its new location. @@ -859,13 +775,13 @@ public final class RowBuffer { Out tempOut_spaceNeeded = new Out(); int shiftInsert; Out tempOut_shiftInsert = new Out(); - this.EnsureSparse(dstEdit, srcEdit.get().cellType, srcEdit.get().cellTypeArgs.clone(), numBytes, - options, tempOut_metaBytes, tempOut_spaceNeeded, tempOut_shiftInsert); + this.EnsureSparse(dstEdit, srcEdit.get().cellType(), srcEdit.get().cellTypeArgs().clone(), numBytes, + options, tempOut_metaBytes, tempOut_spaceNeeded, tempOut_shiftInsert); shiftInsert = tempOut_shiftInsert.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); - this.WriteSparseMetadata(dstEdit, srcEdit.get().cellType, srcEdit.get().cellTypeArgs.clone(), metaBytes); + this.WriteSparseMetadata(dstEdit, srcEdit.get().cellType(), srcEdit.get().cellTypeArgs().clone(), metaBytes); checkState(spaceNeeded == metaBytes + numBytes); if (srcEdit.get().metaOffset() >= dstEdit.get().metaOffset()) { srcEdit.get().metaOffset(srcEdit.get().metaOffset() + shiftInsert); @@ -881,8 +797,8 @@ public final class RowBuffer { Out tempOut_spaceNeeded2 = new Out(); int shiftDelete; Out tempOut_shiftDelete = new Out(); - this.EnsureSparse(srcEdit, srcEdit.get().cellType, srcEdit.get().cellTypeArgs.clone(), numBytes, - RowOptions.Delete, tempOut_metaBytes2, tempOut_spaceNeeded2, tempOut_shiftDelete); + this.EnsureSparse(srcEdit, srcEdit.get().cellType(), srcEdit.get().cellTypeArgs().clone(), numBytes, + RowOptions.Delete, tempOut_metaBytes2, tempOut_spaceNeeded2, tempOut_shiftDelete); shiftDelete = tempOut_shiftDelete.get(); spaceNeeded = tempOut_spaceNeeded2.get(); metaBytes = tempOut_metaBytes2.get(); @@ -925,7 +841,7 @@ public final class RowBuffer { checkArgument(scope.get().index() == 0); RowCursor dstEdit; // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these - // cannot be + // cannot be // converted using the 'Out' helper class unless the method is within the code being modified: scope.get().Clone(out dstEdit); if (dstEdit.count() <= 1) { @@ -940,18 +856,18 @@ public final class RowBuffer { dstEdit.metaOffset(scope.get().valueOffset()); for (; dstEdit.index() < dstEdit.count(); dstEdit.index(dstEdit.index() + 1)) { Reference tempReference_dstEdit = - new Reference(dstEdit); - this.ReadSparseMetadata(tempReference_dstEdit); + new Reference(dstEdit); + this.readSparseMetadata(tempReference_dstEdit); dstEdit = tempReference_dstEdit.get(); - Contract.Assert(dstEdit.pathOffset == + Contract.Assert(dstEdit.pathOffset() == default) - Reference tempReference_dstEdit2 = - new Reference(dstEdit); - int elmSize = this.SparseComputeSize(tempReference_dstEdit2); + Reference tempReference_dstEdit2 = + new Reference(dstEdit); + int elmSize = this.sparseComputeSize(tempReference_dstEdit2); dstEdit = tempReference_dstEdit2.get(); UniqueIndexItem tempVar = new UniqueIndexItem(); - tempVar.code(dstEdit.cellType.LayoutCode); + tempVar.code(dstEdit.cellType().LayoutCode); tempVar.metaOffset(dstEdit.metaOffset()); tempVar.valueOffset(dstEdit.valueOffset()); tempVar.size(elmSize); @@ -974,7 +890,7 @@ public final class RowBuffer { // unsafe // { // Span p = new Span(Unsafe.AsPointer(ref uniqueIndex - // .GetPinnableReference()), uniqueIndex.Length); + // .GetPinnableReference()), uniqueIndex.Length); // if (!this.InsertionSort(ref scope, ref dstEdit, p)) // { // return Result.Exists; @@ -983,7 +899,7 @@ public final class RowBuffer { // Move elements. int metaOffset = scope.get().valueOffset(); - this.Ensure(this.length() + shift); + this.ensure(this.length() + shift); this.buffer.Slice(metaOffset, this.length() - metaOffset).CopyTo(this.buffer.Slice(metaOffset + shift)); for (UniqueIndexItem x : uniqueIndex) { this.buffer.Slice(x.metaOffset() + shift, x.size()).CopyTo(this.buffer.Slice(metaOffset)); @@ -1004,6 +920,50 @@ public final class RowBuffer { return Result.Success; } + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: internal int Write7BitEncodedUInt(int offset, ulong value) + public int Write7BitEncodedUInt(int offset, long value) { + // Write out an unsigned long 7 bits at a time. The high bit of the byte, + // when set, indicates there are more bytes. + int i = 0; + while (value >= 0x80L) { + // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: + //ORIGINAL LINE: this.WriteUInt8(offset + i++, unchecked((byte)(value | 0x80))); + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + this.WriteUInt8(offset + i++, (byte)(value | 0x80)); + //C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift + // operator since the left operand was originally of an unsigned type, but you should confirm this + // replacement: + value >>>= 7; + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: this.WriteUInt8(offset + i++, (byte)value); + this.WriteUInt8(offset + i++, (byte)value); + return i; + } + + public void WriteFloat128(int offset, Float128 value) { + Reference tempReference_value = + new Reference(value); + MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); + value = tempReference_value.get(); + } + + public void WriteHeader(int offset, HybridRowHeader value) { + Reference tempReference_value = + new Reference(value); + MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); + value = tempReference_value.get(); + } + + public void WriteMongoDbObjectId(int offset, MongoDbObjectId value) { + Reference tempReference_value = + new Reference(value); + MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); + value = tempReference_value.get(); + } + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: internal ushort ReadUInt16(int offset) public short ReadUInt16(int offset) { @@ -1068,14 +1028,12 @@ public final class RowBuffer { return tempVar; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal ulong ReadVariableUInt(int offset) public long ReadVariableUInt(int offset) { int _; Out tempOut__ = new Out(); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: return this.Read7BitEncodedUInt(offset, out int _); - long tempVar = this.Read7BitEncodedUInt(offset, tempOut__); + long tempVar = this.read7BitEncodedUInt(); _ = tempOut__.get(); return tempVar; } @@ -1083,83 +1041,11 @@ public final class RowBuffer { /** * Clears all content from the row. The row is empty after this method. */ - public void Reset() { - this.length(0); + public void reset() { + this.buffer.clear(); this.resolver = null; } - /** - * Rotates the sign bit of a two's complement value to the least significant bit. - * - * @param value A signed value. - * @return An unsigned value encoding the same value but with the sign bit in the LSB. - *

- * Moves the signed bit of a two's complement value to the least significant bit (LSB) by: - * - * - * If negative, take the two's complement. - * - * Left shift the value by 1 bit. - * - * If negative, set the LSB to 1. - * - * - */ - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [SuppressMessage("StyleCop.CSharp.DocumentationRules", - // "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Colon.")] internal static ulong RotateSignToLsb - // (long value) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: [SuppressMessage("StyleCop.CSharp.DocumentationRules", - // "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Colon.")] internal static ulong RotateSignToLsb - // (long value) - public static long RotateSignToLsb(long value) { - // Rotate sign to LSB - // TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java: - unchecked - { - boolean isNegative = value < 0; - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ulong uvalue = (ulong)value; - long uvalue = value; - uvalue = isNegative ? ((~uvalue + 1) << 1) + 1 : uvalue << 1; - return uvalue; - } - } - - /** - * Undoes the rotation introduced by {@link RotateSignToLsb}. - * - * @param uvalue An unsigned value with the sign bit in the LSB. - * @return A signed two's complement value encoding the same value. - */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal static long RotateSignToMsb(ulong uvalue) - public static long RotateSignToMsb(long uvalue) { - // Rotate sign to MSB - // TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java: - unchecked - { - boolean isNegative = uvalue % 2 != 0; - //C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift - // operator since the left operand was originally of an unsigned type, but you should confirm this - // replacement: - long value = isNegative ? (~(uvalue >>> 1) + 1) | 0x8000000000000000 : uvalue >>> 1; - return value; - } - } - - public void SetBit(int offset, LayoutBit bit) { - if (bit.getIsInvalid()) { - return; - } - - // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: - //ORIGINAL LINE: this.buffer[bit.GetOffset(offset)] |= unchecked((byte)(1 << bit.GetBit())); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - this.buffer[bit.GetOffset(offset)] |= (byte)(1 << bit.GetBit()); - } - public void WriteNullable(Reference edit, LayoutScope scopeType, TypeArgumentList typeArgs, UpdateOptions options, boolean hasValue, Out newScope) { int numBytes = this.countDefaultValue(scopeType, typeArgs.clone()); @@ -1196,23 +1082,10 @@ public final class RowBuffer { this.length(this.length() + shift); Reference tempReference_this = new Reference(this); - RowCursorExtensions.MoveNext(newScope.get().clone(), tempReference_this); + RowCursors.moveNext(newScope.get().clone(), tempReference_this); this = tempReference_this.get(); } - /** - * The length of row in bytes. - */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public byte[] ToArray() - public byte[] ToArray() { - return this.buffer.Slice(0, this.length()).ToArray(); - } - - public void WriteSchemaId(int offset, SchemaId value) { - this.WriteInt32(offset, value.id()); - } - public void WriteSparseArray(Reference edit, LayoutScope scopeType, UpdateOptions options, Out newScope) { int numBytes = (LayoutCode.SIZE / Byte.SIZE); // end scope type code. @@ -1224,7 +1097,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1242,9 +1115,20 @@ public final class RowBuffer { this.length(this.length() + shift); } + public void SetBit(int offset, LayoutBit bit) { + if (bit.getIsInvalid()) { + return; + } + + // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: + //ORIGINAL LINE: this.buffer[bit.GetOffset(offset)] |= unchecked((byte)(1 << bit.GetBit())); + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + this.buffer[bit.GetOffset(offset)] |= (byte)(1 << bit.GetBit()); + } + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: internal void WriteSparseBinary(ref RowCursor edit, ReadOnlySpan value, UpdateOptions - // options) + // options) public void WriteSparseBinary(Reference edit, ReadOnlySpan value, UpdateOptions options) { int len = value.Length; //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @@ -1257,7 +1141,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Binary, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1268,6 +1152,66 @@ public final class RowBuffer { this.length(this.length() + shift); } + /** + * The length of row in bytes. + */ + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: public byte[] ToArray() + public byte[] ToArray() { + return this.buffer.Slice(0, this.length()).ToArray(); + } + + public void WriteSchemaId(int offset, SchemaId value) { + this.WriteInt32(offset, value.id()); + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: internal void WriteSparseBinary(ref RowCursor edit, ReadOnlySequence value, UpdateOptions + // options) + public void WriteSparseBinary(Reference edit, ReadOnlySequence value, + UpdateOptions options) { + int len = (int)value.Length; + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: int numBytes = len + RowBuffer.Count7BitEncodedUInt((ulong)len); + int numBytes = len + RowBuffer.Count7BitEncodedUInt(len); + int metaBytes; + Out tempOut_metaBytes = new Out(); + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + int shift; + Out tempOut_shift = new Out(); + this.EnsureSparse(edit, LayoutType.Binary, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, + tempOut_spaceNeeded, tempOut_shift); + shift = tempOut_shift.get(); + spaceNeeded = tempOut_spaceNeeded.get(); + metaBytes = tempOut_metaBytes.get(); + this.WriteSparseMetadata(edit, LayoutType.Binary, TypeArgumentList.EMPTY, metaBytes); + int sizeLenInBytes = this.WriteBinary(edit.get().valueOffset(), value); + checkState(spaceNeeded == metaBytes + len + sizeLenInBytes); + edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; + this.length(this.length() + shift); + } + + public void WriteSparseBool(Reference edit, boolean value, UpdateOptions options) { + int numBytes = 0; + int metaBytes; + Out tempOut_metaBytes = new Out(); + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + int shift; + Out tempOut_shift = new Out(); + this.EnsureSparse(edit, value ? LayoutType.Boolean : LayoutType.BooleanFalse, TypeArgumentList.EMPTY, + numBytes, options, tempOut_metaBytes, tempOut_spaceNeeded, tempOut_shift); + shift = tempOut_shift.get(); + spaceNeeded = tempOut_spaceNeeded.get(); + metaBytes = tempOut_metaBytes.get(); + this.WriteSparseMetadata(edit, value ? LayoutType.Boolean : LayoutType.BooleanFalse, TypeArgumentList.EMPTY, + metaBytes); + checkState(spaceNeeded == metaBytes); + edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; + this.length(this.length() + shift); + } + public void UnsetBit(int offset, LayoutBit bit) { checkState(LayoutBit.opNotEquals(bit.clone(), LayoutBit.Invalid)); // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: @@ -1280,27 +1224,24 @@ public final class RowBuffer { return this.Write7BitEncodedUInt(offset, RowBuffer.RotateSignToLsb(value)); } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal int Write7BitEncodedUInt(int offset, ulong value) - public int Write7BitEncodedUInt(int offset, long value) { - // Write out an unsigned long 7 bits at a time. The high bit of the byte, - // when set, indicates there are more bytes. - int i = 0; - while (value >= 0x80L) { - // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: - //ORIGINAL LINE: this.WriteUInt8(offset + i++, unchecked((byte)(value | 0x80))); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - this.WriteUInt8(offset + i++, (byte)(value | 0x80)); - //C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift - // operator since the left operand was originally of an unsigned type, but you should confirm this - // replacement: - value >>>= 7; - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: this.WriteUInt8(offset + i++, (byte)value); - this.WriteUInt8(offset + i++, (byte)value); - return i; + public void WriteSparseDateTime(Reference edit, LocalDateTime value, UpdateOptions options) { + int numBytes = 8; + int metaBytes; + Out tempOut_metaBytes = new Out(); + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + int shift; + Out tempOut_shift = new Out(); + this.EnsureSparse(edit, LayoutType.DateTime, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, + tempOut_spaceNeeded, tempOut_shift); + shift = tempOut_shift.get(); + spaceNeeded = tempOut_spaceNeeded.get(); + metaBytes = tempOut_metaBytes.get(); + this.WriteSparseMetadata(edit, LayoutType.DateTime, TypeArgumentList.EMPTY, metaBytes); + this.WriteDateTime(edit.get().valueOffset(), value); + checkState(spaceNeeded == metaBytes + 8); + edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; + this.length(this.length() + shift); } public void WriteDateTime(int offset, LocalDateTime value) { @@ -1337,11 +1278,26 @@ public final class RowBuffer { value.Span.CopyTo(this.buffer.Slice(offset)); } - public void WriteFloat128(int offset, Float128 value) { - Reference tempReference_value = - new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); + public void WriteSparseDecimal(Reference edit, BigDecimal value, UpdateOptions options) { + // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'sizeof': + int numBytes = sizeof(BigDecimal); + int metaBytes; + Out tempOut_metaBytes = new Out(); + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + int shift; + Out tempOut_shift = new Out(); + this.EnsureSparse(edit, LayoutType.Decimal, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, + tempOut_spaceNeeded, tempOut_shift); + shift = tempOut_shift.get(); + spaceNeeded = tempOut_spaceNeeded.get(); + metaBytes = tempOut_metaBytes.get(); + this.WriteSparseMetadata(edit, LayoutType.Decimal, TypeArgumentList.EMPTY, metaBytes); + this.WriteDecimal(edit.get().valueOffset(), value); + // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'sizeof': + checkState(spaceNeeded == metaBytes + sizeof(BigDecimal)); + edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; + this.length(this.length() + shift); } public void WriteFloat32(int offset, float value) { @@ -1362,11 +1318,24 @@ public final class RowBuffer { value = tempReference_value.get(); } - public void WriteHeader(int offset, HybridRowHeader value) { - Reference tempReference_value = - new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); + public void WriteSparseFloat128(Reference edit, Float128 value, UpdateOptions options) { + int numBytes = Float128.Size; + int metaBytes; + Out tempOut_metaBytes = new Out(); + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + int shift; + Out tempOut_shift = new Out(); + this.EnsureSparse(edit, LayoutType.Float128, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, + tempOut_spaceNeeded, tempOut_shift); + shift = tempOut_shift.get(); + spaceNeeded = tempOut_spaceNeeded.get(); + metaBytes = tempOut_metaBytes.get(); + this.WriteSparseMetadata(edit, LayoutType.Float128, TypeArgumentList.EMPTY, metaBytes); + this.WriteFloat128(edit.get().valueOffset(), value.clone()); + checkState(spaceNeeded == metaBytes + Float128.Size); + edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; + this.length(this.length() + shift); } public void WriteInt16(int offset, short value) { @@ -1394,122 +1363,6 @@ public final class RowBuffer { this.buffer[offset] = value; } - public void WriteMongoDbObjectId(int offset, MongoDbObjectId value) { - Reference tempReference_value = - new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteSparseBinary(ref RowCursor edit, ReadOnlySequence value, UpdateOptions - // options) - public void WriteSparseBinary(Reference edit, ReadOnlySequence value, - UpdateOptions options) { - int len = (int)value.Length; - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: int numBytes = len + RowBuffer.Count7BitEncodedUInt((ulong)len); - int numBytes = len + RowBuffer.Count7BitEncodedUInt(len); - int metaBytes; - Out tempOut_metaBytes = new Out(); - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - int shift; - Out tempOut_shift = new Out(); - this.EnsureSparse(edit, LayoutType.Binary, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); - shift = tempOut_shift.get(); - spaceNeeded = tempOut_spaceNeeded.get(); - metaBytes = tempOut_metaBytes.get(); - this.WriteSparseMetadata(edit, LayoutType.Binary, TypeArgumentList.EMPTY, metaBytes); - int sizeLenInBytes = this.WriteBinary(edit.get().valueOffset(), value); - checkState(spaceNeeded == metaBytes + len + sizeLenInBytes); - edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; - this.length(this.length() + shift); - } - - public void WriteSparseBool(Reference edit, boolean value, UpdateOptions options) { - int numBytes = 0; - int metaBytes; - Out tempOut_metaBytes = new Out(); - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - int shift; - Out tempOut_shift = new Out(); - this.EnsureSparse(edit, value ? LayoutType.Boolean : LayoutType.BooleanFalse, TypeArgumentList.EMPTY, - numBytes, options, tempOut_metaBytes, tempOut_spaceNeeded, tempOut_shift); - shift = tempOut_shift.get(); - spaceNeeded = tempOut_spaceNeeded.get(); - metaBytes = tempOut_metaBytes.get(); - this.WriteSparseMetadata(edit, value ? LayoutType.Boolean : LayoutType.BooleanFalse, TypeArgumentList.EMPTY, - metaBytes); - checkState(spaceNeeded == metaBytes); - edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; - this.length(this.length() + shift); - } - - public void WriteSparseDateTime(Reference edit, LocalDateTime value, UpdateOptions options) { - int numBytes = 8; - int metaBytes; - Out tempOut_metaBytes = new Out(); - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - int shift; - Out tempOut_shift = new Out(); - this.EnsureSparse(edit, LayoutType.DateTime, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); - shift = tempOut_shift.get(); - spaceNeeded = tempOut_spaceNeeded.get(); - metaBytes = tempOut_metaBytes.get(); - this.WriteSparseMetadata(edit, LayoutType.DateTime, TypeArgumentList.EMPTY, metaBytes); - this.WriteDateTime(edit.get().valueOffset(), value); - checkState(spaceNeeded == metaBytes + 8); - edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; - this.length(this.length() + shift); - } - - public void WriteSparseDecimal(Reference edit, BigDecimal value, UpdateOptions options) { - // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'sizeof': - int numBytes = sizeof(BigDecimal); - int metaBytes; - Out tempOut_metaBytes = new Out(); - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - int shift; - Out tempOut_shift = new Out(); - this.EnsureSparse(edit, LayoutType.Decimal, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); - shift = tempOut_shift.get(); - spaceNeeded = tempOut_spaceNeeded.get(); - metaBytes = tempOut_metaBytes.get(); - this.WriteSparseMetadata(edit, LayoutType.Decimal, TypeArgumentList.EMPTY, metaBytes); - this.WriteDecimal(edit.get().valueOffset(), value); - // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'sizeof': - checkState(spaceNeeded == metaBytes + sizeof(BigDecimal)); - edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; - this.length(this.length() + shift); - } - - public void WriteSparseFloat128(Reference edit, Float128 value, UpdateOptions options) { - int numBytes = Float128.Size; - int metaBytes; - Out tempOut_metaBytes = new Out(); - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - int shift; - Out tempOut_shift = new Out(); - this.EnsureSparse(edit, LayoutType.Float128, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); - shift = tempOut_shift.get(); - spaceNeeded = tempOut_spaceNeeded.get(); - metaBytes = tempOut_metaBytes.get(); - this.WriteSparseMetadata(edit, LayoutType.Float128, TypeArgumentList.EMPTY, metaBytes); - this.WriteFloat128(edit.get().valueOffset(), value.clone()); - checkState(spaceNeeded == metaBytes + Float128.Size); - edit.get().endOffset = edit.get().metaOffset() + spaceNeeded; - this.length(this.length() + shift); - } - public void WriteSparseFloat32(Reference edit, float value, UpdateOptions options) { int numBytes = (Float.SIZE / Byte.SIZE); int metaBytes; @@ -1519,7 +1372,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Float32, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1539,7 +1392,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Float64, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1559,7 +1412,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Guid, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1579,7 +1432,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Int16, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1599,7 +1452,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Int32, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1619,7 +1472,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Int64, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1639,7 +1492,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Int8, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1661,7 +1514,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, MongoDbObjectId, TypeArgumentList.EMPTY, numBytes, options, - tempOut_metaBytes, tempOut_spaceNeeded, tempOut_shift); + tempOut_metaBytes, tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1682,7 +1535,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Null, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1703,7 +1556,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1733,7 +1586,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.Utf8, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1745,7 +1598,7 @@ public final class RowBuffer { } public void WriteSparseTuple(Reference edit, LayoutScope scopeType, TypeArgumentList typeArgs - , UpdateOptions options, Out newScope) { + , UpdateOptions options, Out newScope) { int numBytes = (LayoutCode.SIZE / Byte.SIZE) * (1 + typeArgs.count()); // nulls for each element. int metaBytes; Out tempOut_metaBytes = new Out(); @@ -1754,7 +1607,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1779,15 +1632,6 @@ public final class RowBuffer { this.length(this.length() + shift); } - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void WriteSparseTypeCode(int offset, - // LayoutCode code) - public void WriteSparseTypeCode(int offset, LayoutCode code) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: this.WriteUInt8(offset, (byte)code); - this.WriteUInt8(offset, (byte) code.value()); - } - public void WriteSparseUDT(Reference edit, LayoutScope scopeType, Layout udt, UpdateOptions options, Out newScope) { TypeArgumentList typeArgs = new TypeArgumentList(udt.schemaId().clone()); @@ -1799,7 +1643,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1834,7 +1678,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.UInt16, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1856,7 +1700,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.UInt32, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1878,7 +1722,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.UInt64, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1900,7 +1744,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.UInt8, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1920,7 +1764,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.UnixDateTime, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes - , tempOut_spaceNeeded, tempOut_shift); + , tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1932,6 +1776,15 @@ public final class RowBuffer { this.length(this.length() + shift); } + // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: + //ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void WriteSparseTypeCode(int offset, + // LayoutCode code) + public void WriteSparseTypeCode(int offset, LayoutCode code) { + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: this.WriteUInt8(offset, (byte)code); + this.WriteUInt8(offset, (byte) code.value()); + } + public void WriteSparseVarInt(Reference edit, long value, UpdateOptions options) { int numBytes = RowBuffer.Count7BitEncodedInt(value); int metaBytes; @@ -1941,7 +1794,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.VarInt, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1964,7 +1817,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, LayoutType.VarUInt, TypeArgumentList.EMPTY, numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -1986,7 +1839,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -2015,7 +1868,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -2044,7 +1897,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -2063,13 +1916,6 @@ public final class RowBuffer { this.length(this.length() + shift); } - /** - * Copies the content of the buffer into the target stream. - */ - public void WriteTo(OutputStream stream) { - stream.Write(this.buffer.Slice(0, this.length())); - } - public void WriteTypedTuple(Reference edit, LayoutScope scopeType, TypeArgumentList typeArgs, UpdateOptions options, Out newScope) { int numBytes = this.countDefaultValue(scopeType, typeArgs.clone()); @@ -2080,7 +1926,7 @@ public final class RowBuffer { int shift; Out tempOut_shift = new Out(); this.EnsureSparse(edit, scopeType, typeArgs.clone(), numBytes, options, tempOut_metaBytes, - tempOut_spaceNeeded, tempOut_shift); + tempOut_spaceNeeded, tempOut_shift); shift = tempOut_shift.get(); spaceNeeded = tempOut_spaceNeeded.get(); metaBytes = tempOut_metaBytes.get(); @@ -2099,11 +1945,100 @@ public final class RowBuffer { this.length(this.length() + shift); Reference tempReference_this = - new Reference(this); - RowCursorExtensions.MoveNext(newScope.get().clone(), tempReference_this); + new Reference(this); + RowCursors.moveNext(newScope.get().clone(), tempReference_this); this = tempReference_this.get(); } + public void WriteUnixDateTime(int offset, UnixDateTime value) { + Reference tempReference_value = + new Reference(value); + MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); + value = tempReference_value.get(); + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: internal void WriteVariableBinary(int offset, ReadOnlySpan value, bool exists, out int shift) + public void WriteVariableBinary(int offset, ReadOnlySpan value, boolean exists, + Out shift) { + int numBytes = value.Length; + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); + spaceNeeded = tempOut_spaceNeeded.get(); + + int sizeLenInBytes = this.WriteBinary(offset, value); + checkState(spaceNeeded == numBytes + sizeLenInBytes); + this.length(this.length() + shift.get()); + } + + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: internal void WriteVariableBinary(int offset, ReadOnlySequence value, bool exists, out int + // shift) + public void WriteVariableBinary(int offset, ReadOnlySequence value, boolean exists, + Out shift) { + int numBytes = (int)value.Length; + int spaceNeeded; + Out tempOut_spaceNeeded = new Out(); + this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); + spaceNeeded = tempOut_spaceNeeded.get(); + + int sizeLenInBytes = this.WriteBinary(offset, value); + checkState(spaceNeeded == numBytes + sizeLenInBytes); + this.length(this.length() + shift.get()); + } + + public RowBuffer clone() { + RowBuffer varCopy = new RowBuffer(); + + varCopy.allocator = this.allocator; + varCopy.buffer = this.buffer; + varCopy.resolver = this.resolver; + varCopy.length(this.length()); + + return varCopy; + } + + /** + * Delete the sparse field at the indicated path. + * + * @param edit The field to delete. + */ + public void deleteSparse(Reference edit) { + // If the field doesn't exist, then nothing to do. + if (!edit.get().exists()) { + return; + } + + int numBytes = 0; + int _; + Out tempOut__ = new Out(); + int _; + Out tempOut__2 = new Out(); + int shift; + Out tempOut_shift = new Out(); + this.EnsureSparse(edit, edit.get().cellType(), edit.get().cellTypeArgs().clone(), numBytes, + RowOptions.Delete, tempOut__, tempOut__2, tempOut_shift); + shift = tempOut_shift.get(); + _ = tempOut__2.get(); + _ = tempOut__.get(); + this.length(this.length() + shift); + } + + /** + * Copies the content of the buffer into the target stream. + */ + public void WriteTo(OutputStream stream) { + stream.Write(this.buffer.Slice(0, this.length())); + } + + /** + * The root header for the row. + */ + public HybridRowHeader header() { + return this.readHeader(); + } + /** * Compute the byte offset from the beginning of the row for a given variable column's value. * @@ -2129,7 +2064,7 @@ public final class RowBuffer { Out tempOut_lengthSizeInBytes = new Out(); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: ulong valueSizeInBytes = this.Read7BitEncodedUInt(offset, out int lengthSizeInBytes); - long valueSizeInBytes = this.Read7BitEncodedUInt(offset, tempOut_lengthSizeInBytes); + long valueSizeInBytes = this.read7BitEncodedUInt(offset, tempOut_lengthSizeInBytes); lengthSizeInBytes = tempOut_lengthSizeInBytes.get(); if (col.getType().getIsVarint()) { offset += lengthSizeInBytes; @@ -2142,24 +2077,17 @@ public final class RowBuffer { return offset; } - /** - * The root header for the row. - */ - public HybridRowHeader header() { - return this.ReadHeader(0); + public HybridRowHeader readHeader() { + HybridRowVersion version = HybridRowVersion.from(this.buffer.readByte()); + SchemaId schemaId = SchemaId.from(this.buffer.readIntLE()); + return new HybridRowHeader(version, schemaId); } /** - * The length of row in bytes. - */ /** - * The length of row in bytes. + * The length of this {@link RowBuffer} in bytes. */ public int length() { - return this.length; - } - - public void length(int length) { - this.length = length; + return this.buffer.readerIndex() + this.buffer.readableBytes(); } /** @@ -2207,42 +2135,37 @@ public final class RowBuffer { this.buffer[offset] = value; } - public void WriteUnixDateTime(int offset, UnixDateTime value) { - Reference tempReference_value = - new Reference(value); - MemoryMarshal.Write(this.buffer.Slice(offset), tempReference_value); - value = tempReference_value.get(); + public NullValue readSparseNull(@Nonnull RowCursor edit) { + + checkNotNull(edit); + + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.Null); + edit.endOffset(edit.valueOffset()); + + return NullValue.Default; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteVariableBinary(int offset, ReadOnlySpan value, bool exists, out int shift) - public void WriteVariableBinary(int offset, ReadOnlySpan value, boolean exists, - Out shift) { - int numBytes = value.Length; - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); - spaceNeeded = tempOut_spaceNeeded.get(); + public Utf8String readSparsePath(RowCursor edit) { - int sizeLenInBytes = this.WriteBinary(offset, value); - checkState(spaceNeeded == numBytes + sizeLenInBytes); - this.length(this.length() + shift.get()); + final Optional path = edit.layout().tokenizer().tryFindString(edit.longValue().pathToken); + + if (path.isPresent()) { + return path.get(); + } + + int numBytes = edit.pathToken() - edit.layout().tokenizer().count(); + return Utf8String.unsafeFromUtf8BytesNoValidation(this.buffer.Slice(edit.pathOffset(), numBytes)); } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: internal void WriteVariableBinary(int offset, ReadOnlySequence value, bool exists, out int - // shift) - public void WriteVariableBinary(int offset, ReadOnlySequence value, boolean exists, - Out shift) { - int numBytes = (int)value.Length; - int spaceNeeded; - Out tempOut_spaceNeeded = new Out(); - this.EnsureVariable(offset, false, numBytes, exists, tempOut_spaceNeeded, shift); - spaceNeeded = tempOut_spaceNeeded.get(); + public long readSparseVarUInt(RowCursor edit) { + this.readSparsePrimitiveTypeCode(edit, LayoutTypes.VarUInt); + int sizeLenInBytes; + Out tempOut_sizeLenInBytes = new Out(); + long value = this.read7BitEncodedUInt(edit.valueOffset(), tempOut_sizeLenInBytes); + sizeLenInBytes = tempOut_sizeLenInBytes.get(); + edit.endOffset(edit.valueOffset() + sizeLenInBytes); - int sizeLenInBytes = this.WriteBinary(offset, value); - checkState(spaceNeeded == numBytes + sizeLenInBytes); - this.length(this.length() + shift.get()); + return value; } public void WriteVariableInt(int offset, long value, boolean exists, Out shift) { @@ -2285,15 +2208,68 @@ public final class RowBuffer { this.length(this.length() + shift.get()); } - public RowBuffer clone() { - RowBuffer varCopy = new RowBuffer(); + /** + * Move a sparse iterator to the next field within the same sparse scope. + * + * @param edit The iterator to advance. + * + * + * On success, the path of the field at the given offset, otherwise + * undefined. + * + * + * If found, the offset to the metadata of the field, otherwise a + * location to insert the field. + * + * + * If found, the layout code of the matching field found, otherwise + * undefined. + * + * + * If found, the offset to the value of the field, otherwise + * undefined. + * . + * @return True if there is another field, false if there are no more. + */ + public boolean sparseIteratorMoveNext(RowCursor edit) { - varCopy.resizer = this.resizer; - varCopy.buffer = this.buffer; - varCopy.resolver = this.resolver; - varCopy.length(this.length()); + if (edit.cellType() != null) { + // Move to the next element of an indexed scope. + if (edit.scopeType().isIndexedScope()) { + edit.index(edit.index() + 1); + } - return varCopy; + // Skip forward to the end of the current value. + if (edit.endOffset() != 0) { + edit.metaOffset(edit.endOffset()); + edit.endOffset(0); + } else { + edit.metaOffset(edit.metaOffset() + this.sparseComputeSize(edit)); + } + } + + // Check if reached end of buffer + + if (edit.metaOffset() < this.length()) { + + // Check if reached end of sized scope. + + if (!edit.scopeType().isSizedScope() || (edit.index() != edit.count())) { + + this.readSparseMetadata(edit); + + // Check if reached end of sparse scope. + if (!(edit.cellType() instanceof LayoutEndScope)) { + edit.exists(true); + return true; + } + } + } + + edit.cellType(LayoutTypes.EndScope); + edit.exists(false); + edit.valueOffset(edit.metaOffset()); + return false; } /** @@ -2317,11 +2293,11 @@ public final class RowBuffer { //ORIGINAL LINE: [SuppressMessage("Microsoft.StyleCop.CSharp.OrderingRules", "SA1201", Justification = "Logical // Grouping.")] private int CompareFieldValue(RowCursor left, int leftLen, RowCursor right, int rightLen) private int CompareFieldValue(RowCursor left, int leftLen, RowCursor right, int rightLen) { - if (left.cellType.LayoutCode.getValue() < right.cellType.LayoutCode.getValue()) { + if (left.cellType().LayoutCode.getValue() < right.cellType().LayoutCode.getValue()) { return -1; } - if (left.cellType == right.cellType) { + if (left.cellType() == right.cellType()) { if (leftLen < rightLen) { return -1; } @@ -2351,50 +2327,50 @@ public final class RowBuffer { * */ private int CompareKeyValueFieldValue(RowCursor left, RowCursor right) { - LayoutTypedTuple leftScopeType = left.cellType instanceof LayoutTypedTuple ? (LayoutTypedTuple)left.cellType : + LayoutTypedTuple leftScopeType = left.cellType() instanceof LayoutTypedTuple ? (LayoutTypedTuple) left.cellType() : null; - LayoutTypedTuple rightScopeType = right.cellType instanceof LayoutTypedTuple ? - (LayoutTypedTuple)right.cellType : null; + LayoutTypedTuple rightScopeType = right.cellType() instanceof LayoutTypedTuple ? + (LayoutTypedTuple) right.cellType() : null; checkArgument(leftScopeType != null); checkArgument(rightScopeType != null); - checkArgument(left.cellTypeArgs.count() == 2); - checkArgument(left.cellTypeArgs.equals(right.cellTypeArgs.clone())); + checkArgument(left.cellTypeArgs().count() == 2); + checkArgument(left.cellTypeArgs().equals(right.cellTypeArgs().clone())); RowCursor leftKey = new RowCursor(); leftKey.layout(left.layout()); leftKey.scopeType(leftScopeType); - leftKey.scopeTypeArgs(left.cellTypeArgs.clone()); + leftKey.scopeTypeArgs(left.cellTypeArgs().clone()); leftKey.start(left.valueOffset()); leftKey.metaOffset(left.valueOffset()); leftKey.index(0); Reference tempReference_leftKey = - new Reference(leftKey); - this.ReadSparseMetadata(tempReference_leftKey); + new Reference(leftKey); + this.readSparseMetadata(tempReference_leftKey); leftKey = tempReference_leftKey.get(); - checkState(leftKey.pathOffset == 0); + checkState(leftKey.pathOffset() == 0); Reference tempReference_leftKey2 = - new Reference(leftKey); + new Reference(leftKey); int leftKeyLen = - this.SparseComputeSize(tempReference_leftKey2) - (leftKey.valueOffset() - leftKey.metaOffset()); + this.sparseComputeSize(tempReference_leftKey2) - (leftKey.valueOffset() - leftKey.metaOffset()); leftKey = tempReference_leftKey2.get(); RowCursor rightKey = new RowCursor(); rightKey.layout(right.layout()); rightKey.scopeType(rightScopeType); - rightKey.scopeTypeArgs(right.cellTypeArgs.clone()); + rightKey.scopeTypeArgs(right.cellTypeArgs().clone()); rightKey.start(right.valueOffset()); rightKey.metaOffset(right.valueOffset()); rightKey.index(0); Reference tempReference_rightKey = - new Reference(rightKey); - this.ReadSparseMetadata(tempReference_rightKey); + new Reference(rightKey); + this.readSparseMetadata(tempReference_rightKey); rightKey = tempReference_rightKey.get(); - checkState(rightKey.pathOffset == 0); + checkState(rightKey.pathOffset() == 0); Reference tempReference_rightKey2 = - new Reference(rightKey); - int rightKeyLen = this.SparseComputeSize(tempReference_rightKey2) - (rightKey.valueOffset() - rightKey.metaOffset()); + new Reference(rightKey); + int rightKeyLen = this.sparseComputeSize(tempReference_rightKey2) - (rightKey.valueOffset() - rightKey.metaOffset()); rightKey = tempReference_rightKey2.get(); return this.CompareFieldValue(leftKey.clone(), leftKeyLen, rightKey.clone(), rightKeyLen); @@ -2414,14 +2390,14 @@ public final class RowBuffer { private static int CountSparsePath(Reference edit) { if (!edit.get().writePathToken().isNull()) { - return edit.get().writePathToken().varint.length; + return edit.get().writePathToken().varint().length; } Optional token = edit.get().layout().tokenizer().findToken(edit.get().writePath()); if (token.isPresent()) { edit.get().writePathToken(token.get()); - return token.get().varint.length; + return token.get().varint().length; } int numBytes = edit.get().writePath().toUtf8().length(); @@ -2430,10 +2406,8 @@ public final class RowBuffer { return sizeLenInBytes + numBytes; } - private void Ensure(int size) { - if (this.buffer.length() < size) { - this.buffer = this.resizer.Resize(size, this.buffer); - } + private void ensure(int size) { + this.buffer.ensureWritable(size); } /** @@ -2460,7 +2434,7 @@ public final class RowBuffer { int spaceAvailable = 0; // Compute the metadata offsets - if (edit.get().scopeType().HasImplicitTypeCode(edit)) { + if (edit.get().scopeType().hasImplicitTypeCode(edit)) { metaBytes.setAndGet(0); } else { metaBytes.setAndGet(cellType.CountTypeArgument(typeArgs.clone())); @@ -2472,15 +2446,15 @@ public final class RowBuffer { metaBytes.setAndGet(metaBytes.get() + pathLenInBytes); } - if (edit.get().exists) { + if (edit.get().exists()) { // Compute value offset for existing value to be overwritten. - spaceAvailable = this.SparseComputeSize(edit); + spaceAvailable = this.sparseComputeSize(edit); } spaceNeeded.setAndGet(options == RowOptions.Delete ? 0 : metaBytes.get() + numBytes); shift.setAndGet(spaceNeeded.get() - spaceAvailable); if (shift.get() > 0) { - this.Ensure(this.length() + shift.get()); + this.ensure(this.length() + shift.get()); } this.buffer.Slice(metaOffset + spaceAvailable, this.length() - (metaOffset + spaceAvailable)).CopyTo(this.buffer.Slice(metaOffset + spaceNeeded.get())); @@ -2495,12 +2469,12 @@ public final class RowBuffer { // Update the stored size (fixed arity scopes don't store the size because it is implied by the type args). if (edit.get().scopeType().isSizedScope() && !edit.get().scopeType().isFixedArity()) { - if ((options == RowOptions.Insert) || (options == RowOptions.InsertAt) || ((options == RowOptions.Upsert) && !edit.get().exists)) { + if ((options == RowOptions.Insert) || (options == RowOptions.InsertAt) || ((options == RowOptions.Upsert) && !edit.get().exists())) { // Add one to the current scope count. - checkState(!edit.get().exists); + checkState(!edit.get().exists()); this.IncrementUInt32(edit.get().start(), 1); edit.get().count(edit.get().count() + 1); - } else if ((options == RowOptions.Delete) && edit.get().exists) { + } else if ((options == RowOptions.Delete) && edit.get().exists()) { // Subtract one from the current scope count. checkState(this.ReadUInt32(edit.get().start()) > 0); this.DecrementUInt32(edit.get().start(), 1); @@ -2542,9 +2516,9 @@ public final class RowBuffer { * @return true if the serialization succeeded. false if the input stream was corrupted. */ private boolean InitReadFrom(HybridRowVersion rowVersion) { - HybridRowHeader header = this.ReadHeader(0).clone(); - Layout layout = this.resolver.Resolve(header.getSchemaId().clone()); - checkState(SchemaId.opEquals(header.getSchemaId().clone(), layout.schemaId().clone())); + HybridRowHeader header = this.readHeader(0).clone(); + Layout layout = this.resolver.resolve(header.schemaId().clone()); + checkState(SchemaId.opEquals(header.schemaId().clone(), layout.schemaId().clone())); return (header.getVersion() == rowVersion) && (HybridRowHeader.SIZE + layout.size() <= this.length()); } @@ -2556,7 +2530,7 @@ public final class RowBuffer { long existingValueBytes = 0; if (exists) { Out tempOut_spaceAvailable = new Out(); - existingValueBytes = this.Read7BitEncodedUInt(offset, tempOut_spaceAvailable); + existingValueBytes = this.read7BitEncodedUInt(offset, tempOut_spaceAvailable); spaceAvailable = tempOut_spaceAvailable.get(); } @@ -2571,7 +2545,7 @@ public final class RowBuffer { shift.setAndGet(spaceNeeded.get() - spaceAvailable); if (shift.get() > 0) { - this.Ensure(this.length() + shift.get()); + this.ensure(this.length() + shift.get()); this.buffer.Slice(offset + spaceAvailable, this.length() - (offset + spaceAvailable)).CopyTo(this.buffer.Slice(offset + spaceNeeded.get())); } else if (shift.get() < 0) { this.buffer.Slice(offset + spaceAvailable, this.length() - (offset + spaceAvailable)).CopyTo(this.buffer.Slice(offset + spaceNeeded.get())); @@ -2591,7 +2565,7 @@ public final class RowBuffer { * Implementation Note: *

This method MUST guarantee that if at least one duplicate exists it will be found.

* Insertion Sort is used for this purpose as it guarantees that each value is eventually compared - * against its previous item in sorted order. If any two successive items are the same they must be + * against its previous item in sorted order. If any two successive items are the same they must be * duplicates. *

* Other search algorithms, such as Quick Sort or Merge Sort, may offer fewer comparisons in the @@ -2634,7 +2608,7 @@ public final class RowBuffer { // If there are duplicates then fail. if (cmp == 0) { - return false; + return false; } if (cmp > 0) { @@ -2655,121 +2629,10 @@ public final class RowBuffer { //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: private ReadOnlySpan ReadBinary(int offset, out int sizeLenInBytes) private ReadOnlySpan ReadBinary(int offset, Out sizeLenInBytes) { - int numBytes = (int) this.Read7BitEncodedUInt(offset, sizeLenInBytes); + int numBytes = (int) this.read7BitEncodedUInt(offset, sizeLenInBytes); return this.buffer.Slice(offset + sizeLenInBytes.get(), numBytes); } - /** - * Read the metadata of an encoded sparse field. - * - * @param edit The edit structure to fill in. - * - * - * On success, the path of the field at the given offset, otherwise - * undefined. - * - * - * On success, the offset to the metadata of the field, otherwise a - * location to insert the field. - * - * - * On success, the layout code of the existing field, otherwise - * undefined. - * - * - * On success, the type args of the existing field, otherwise - * undefined. - * - * - * On success, the offset to the value of the field, otherwise - * undefined. - * . - */ - private void ReadSparseMetadata(Reference edit) { - if (edit.get().scopeType().HasImplicitTypeCode(edit)) { - edit.get().scopeType().SetImplicitTypeCode(edit); - edit.get().valueOffset(edit.get().metaOffset()); - } else { - edit.get().cellType = this.ReadSparseTypeCode(edit.get().metaOffset()); - edit.get().valueOffset(edit.get().metaOffset() + (LayoutCode.SIZE / Byte.SIZE)); - edit.get().cellTypeArgs = TypeArgumentList.EMPTY; - if (edit.get().cellType instanceof LayoutEndScope) { - // Reached end of current scope without finding another field. - edit.get().pathToken = 0; - edit.get().pathOffset = 0; - edit.get().valueOffset(edit.get().metaOffset()); - return; - } - - Reference tempReference_this = - new Reference(this); - int sizeLenInBytes; - Out tempOut_sizeLenInBytes = new Out(); - edit.get().cellTypeArgs = edit.get().cellType.readTypeArgumentList(tempReference_this, - edit.get().valueOffset(), tempOut_sizeLenInBytes).clone(); - sizeLenInBytes = tempOut_sizeLenInBytes.get(); - this = tempReference_this.get(); - edit.get().valueOffset(edit.get().valueOffset() + sizeLenInBytes); - } - - Reference tempReference_this2 = - new Reference(this); - edit.get().scopeType().ReadSparsePath(tempReference_this2, edit); - this = tempReference_this2.get(); - } - - // TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes: - //ORIGINAL LINE: [Conditional("DEBUG")] private void ReadSparsePrimitiveTypeCode(ref RowCursor edit, LayoutType - // code) - private void ReadSparsePrimitiveTypeCode(Reference edit, LayoutType code) { - checkState(edit.get().exists); - - if (edit.get().scopeType().HasImplicitTypeCode(edit)) { - if (edit.get().scopeType() instanceof LayoutNullable) { - checkState(edit.get().scopeTypeArgs().count() == 1); - checkState(edit.get().index() == 1); - checkState(edit.get().scopeTypeArgs().get(0).type() == code); - checkState(edit.get().scopeTypeArgs().get(0).typeArgs().count() == 0); - } else if (edit.get().scopeType().isFixedArity()) { - checkState(edit.get().scopeTypeArgs().count() > edit.get().index()); - checkState(edit.get().scopeTypeArgs().get(edit.get().index()).type() == code); - checkState(edit.get().scopeTypeArgs().get(edit.get().index()).typeArgs().count() == 0); - } else { - checkState(edit.get().scopeTypeArgs().count() == 1); - checkState(edit.get().scopeTypeArgs().get(0).type() == code); - checkState(edit.get().scopeTypeArgs().get(0).typeArgs().count() == 0); - } - } else { - if (code == LayoutType.Boolean) { - code = this.ReadSparseTypeCode(edit.get().metaOffset()); - checkState(code == LayoutType.Boolean || code == LayoutType.BooleanFalse); - } else { - checkState(this.ReadSparseTypeCode(edit.get().metaOffset()) == code); - } - } - - if (edit.get().scopeType().isIndexedScope()) { - checkState(edit.get().pathOffset == 0); - checkState(edit.get().pathToken == 0); - } else { - int _; - Out tempOut__ = new Out(); - int pathOffset; - Out tempOut_pathOffset = new Out(); - int token = this.ReadSparsePathLen(edit.get().layout(), - edit.get().metaOffset() + (LayoutCode.SIZE / Byte.SIZE), tempOut__, tempOut_pathOffset); - pathOffset = tempOut_pathOffset.get(); - _ = tempOut__.get(); - checkState(edit.get().pathOffset == pathOffset); - checkState(edit.get().pathToken == token); - } - } - - private Utf8Span ReadString(int offset, Out sizeLenInBytes) { - int numBytes = (int) this.Read7BitEncodedUInt(offset, sizeLenInBytes); - return Utf8Span.UnsafeFromUtf8BytesNoValidation(this.buffer.Slice(offset + sizeLenInBytes.get(), numBytes)); - } - /** * Skip over a nested scope. * @@ -2777,7 +2640,8 @@ public final class RowBuffer { * @return The 0-based byte offset immediately following the scope end marker. */ private int SkipScope(Reference edit) { - while (this.SparseIteratorMoveNext(edit)) { + + while (this.sparseIteratorMoveNext(edit)) { } if (!edit.get().scopeType().isSizedScope()) { @@ -2788,27 +2652,222 @@ public final class RowBuffer { return edit.get().metaOffset(); } - /** - * Compute the size of a sparse field. - * - * @param edit The edit structure describing the field to measure. - * @return The length (in bytes) of the encoded field including the metadata and the value. - */ - private int SparseComputeSize(Reference edit) { - if (!(edit.get().cellType instanceof LayoutScope)) { - return this.SparseComputePrimitiveSize(edit.get().cellType, edit.get().metaOffset(), - edit.get().valueOffset()); + private void WriteSparseMetadata(Reference edit, LayoutType cellType, + TypeArgumentList typeArgs, int metaBytes) { + int metaOffset = edit.get().metaOffset(); + if (!edit.get().scopeType().hasImplicitTypeCode(edit)) { + Reference tempReference_this = + new Reference(this); + metaOffset += cellType.writeTypeArgument(tempReference_this, metaOffset, typeArgs.clone()); + this = tempReference_this.get(); } - // Compute offset to end of value for current value. - RowCursor newScope = this.SparseIteratorReadScope(edit, true).clone(); - Reference tempReference_newScope = - new Reference(newScope); - int tempVar = this.SkipScope(tempReference_newScope) - edit.get().metaOffset(); - newScope = tempReference_newScope.get(); - return tempVar; + this.WriteSparsePath(edit, metaOffset); + edit.get().valueOffset(edit.get().metaOffset() + metaBytes); + checkState(edit.get().valueOffset() == edit.get().metaOffset() + metaBytes); } + private Utf8Span ReadString(int offset, Out sizeLenInBytes) { + int numBytes = (int) this.read7BitEncodedUInt(offset, sizeLenInBytes); + return Utf8Span.UnsafeFromUtf8BytesNoValidation(this.buffer.Slice(offset + sizeLenInBytes.get(), numBytes)); + } + + private void WriteSparsePath(Reference edit, int offset) { + // Some scopes don't encode paths, therefore the cost is always zero. + if (edit.get().scopeType().isIndexedScope()) { + edit.get().pathToken = 0; + edit.get().pathOffset = 0; + return; + } + + StringToken _; + Out tempOut__ = + new Out(); + checkState(!edit.get().layout().getTokenizer().TryFindToken(edit.get().writePath(), tempOut__) || !edit.get().writePathToken().isNull()); + _ = tempOut__.get(); + if (!edit.get().writePathToken().isNull()) { + edit.get().writePathToken().varint().CopyTo(this.buffer.Slice(offset)); + edit.get().pathToken = edit.get().intValue().writePathToken.Id; + edit.get().pathOffset = offset; + } else { + // TODO: It would be better if we could avoid allocating here when the path is UTF16. + Utf8Span span = edit.get().writePath().ToUtf8String(); + edit.get().pathToken = edit.get().layout().getTokenizer().getCount() + span.Length; + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (ulong)edit.pathToken); + int sizeLenInBytes = this.Write7BitEncodedUInt(offset, edit.get().longValue().pathToken); + edit.get().pathOffset = offset + sizeLenInBytes; + span.Span.CopyTo(this.buffer.Slice(offset + sizeLenInBytes)); + } + } + + /** + * Return the size (in bytes) of the default sparse value for the type. + * + * @param code The type of the default value. + * @param typeArgs + */ + private int countDefaultValue(LayoutType code, TypeArgumentList typeArgs) { + + // TODO: JTH: convert to a virtual? + + switch (code) { + if (code instanceof LayoutNull || code instanceof LayoutBoolean) { + return 1; + } + if (code instanceof LayoutInt8) { + return LayoutType.Int8.Size; + } + if (code instanceof LayoutInt16) { + return LayoutType.Int16.Size; + } + if (code instanceof LayoutInt32) { + return LayoutType.Int32.Size; + } + if (code instanceof LayoutInt64) { + return LayoutType.Int64.Size; + } + if (code instanceof LayoutUInt8) { + return LayoutType.UInt8.Size; + } + if (code instanceof LayoutUInt16) { + return LayoutType.UInt16.Size; + } + if (code instanceof LayoutUInt32) { + return LayoutType.UInt32.Size; + } + if (code instanceof LayoutUInt64) { + return LayoutType.UInt64.Size; + } + if (code instanceof LayoutFloat32) { + return LayoutType.Float32.Size; + } + if (code instanceof LayoutFloat64) { + return LayoutType.Float64.Size; + } + if (code instanceof LayoutFloat128) { + return LayoutType.Float128.Size; + } + if (code instanceof LayoutDecimal) { + return LayoutType.Decimal.Size; + } + if (code instanceof LayoutDateTime) { + return LayoutType.DateTime.Size; + if (code instanceof LayoutUnixDateTime) { + return LayoutType.UnixDateTime.Size; + if (code instanceof LayoutGuid) { + return LayoutType.Guid.Size; + if (code instanceof LayoutMongoDbObjectId) { + // return MongoDbObjectId.Size; + throw new UnsupportedOperationException(); + } + if (code instanceof LayoutUtf8 || code instanceof LayoutBinary || code instanceof LayoutVarInt || code instanceof LayoutVarUInt) { + // Variable length types preceded by their varuint size take 1 byte for a size of 0. + return 1; + } + if (code instanceof LayoutObject || code instanceof LayoutArray) { + // Variable length sparse collection scopes take 1 byte for the end-of-scope terminator. + return (LayoutCode.SIZE / Byte.SIZE); + } + if (code instanceof LayoutTypedArray || code instanceof LayoutTypedSet || code instanceof LayoutTypedMap) { + // Variable length typed collection scopes preceded by their scope size take sizeof(uint) for a size of 0. + return (Integer.SIZE / Byte.SIZE); + } + if (code instanceof LayoutTuple) { + // Fixed arity sparse collections take 1 byte for end-of-scope plus a null for each element. + return (LayoutCode.SIZE / Byte.SIZE) + ((LayoutCode.SIZE / Byte.SIZE) * typeArgs.count()); + } + if (code instanceof LayoutTypedTuple || code instanceof LayoutTagged || code instanceof LayoutTagged2) { + // Fixed arity typed collections take the sum of the default values of each element. The scope size is + // implied by the arity. + int sum = 0; + for (TypeArgument arg : typeArgs) { + sum += this.countDefaultValue(arg.type(), arg.typeArgs().clone()); + } + return sum; + } + if (code instanceof LayoutNullable) { + // Nullables take the default values of the value plus null. The scope size is implied by the arity. + return 1 + this.countDefaultValue(typeArgs.get(0).type(), typeArgs.get(0).typeArgs()); + } + if (code instanceof LayoutUDT) { + Layout udt = this.resolver.resolve(typeArgs.schemaId()); + return udt.getSize() + (LayoutCode.SIZE / Byte.SIZE); + } + throw new IllegalStateException(lenientFormat("Not Implemented: %s", code)); + } + + private int WriteString(int offset, Utf8Span value) { + //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + //ORIGINAL LINE: int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (ulong)value.Length); + int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (long)value.Length); + value.Span.CopyTo(this.buffer.Slice(offset + sizeLenInBytes)); + return sizeLenInBytes; + } + + /** + * Represents a single item within a set/map scope that needs to be indexed + *

+ * This structure is used when rebuilding a set/map index during row streaming via {@link RowWriter}.Each item + * encodes its offsets and length within the row. + */ + static final class UniqueIndexItem { + + private LayoutCode Code = LayoutCode.values()[0]; + private int MetaOffset; + private int Size; + private int ValueOffset; + + /** + * The layout code of the value. + */ + public LayoutCode code() { + return Code; + } + + public UniqueIndexItem code(LayoutCode code) { + Code = code; + return this; + } + + /** + * If existing, the offset to the metadata of the existing field, otherwise the location to insert a new field + */ + public int metaOffset() { + return MetaOffset; + } + + public UniqueIndexItem metaOffset(int metaOffset) { + MetaOffset = metaOffset; + return this; + } + + /** + * Size of the target element + */ + public int size() { + return Size; + } + + public UniqueIndexItem size(int size) { + Size = size; + return this; + } + + /** + * If existing, the offset to the value of the existing field, otherwise undefined + */ + public int valueOffset() { + return ValueOffset; + } + + public UniqueIndexItem valueOffset(int valueOffset) { + ValueOffset = valueOffset; + return this; + } + } +} + /** * Compute the size of a sparse (primitive) field. * @@ -2887,7 +2946,7 @@ public final class RowBuffer { { int sizeLenInBytes; Out tempOut_sizeLenInBytes = new Out(); - int numBytes = (int)this.Read7BitEncodedUInt(metaOffset + metaBytes, tempOut_sizeLenInBytes); + int numBytes = (int)this.read7BitEncodedUInt(metaOffset + metaBytes, tempOut_sizeLenInBytes); sizeLenInBytes = tempOut_sizeLenInBytes.get(); return metaBytes + sizeLenInBytes + numBytes; } @@ -2896,7 +2955,7 @@ public final class RowBuffer { case VAR_UINT: { int sizeLenInBytes; Out tempOut_sizeLenInBytes2 = new Out(); - this.Read7BitEncodedUInt(metaOffset + metaBytes, tempOut_sizeLenInBytes2); + this.read7BitEncodedUInt(metaOffset + metaBytes, tempOut_sizeLenInBytes2); sizeLenInBytes = tempOut_sizeLenInBytes2.get(); return metaBytes + sizeLenInBytes; } @@ -3149,7 +3208,7 @@ public final class RowBuffer { _: // Clear all presence bits. - Layout udt = this.resolver.Resolve(typeArgs.schemaId().clone()); + Layout udt = this.resolver.resolve(typeArgs.schemaId().clone()); this.buffer.Slice(offset, udt.getSize()).Fill(0); // Write scope terminator. @@ -3162,213 +3221,124 @@ public final class RowBuffer { } } - private void WriteSparseMetadata(Reference edit, LayoutType cellType, - TypeArgumentList typeArgs, int metaBytes) { - int metaOffset = edit.get().metaOffset(); - if (!edit.get().scopeType().HasImplicitTypeCode(edit)) { - Reference tempReference_this = - new Reference(this); - metaOffset += cellType.writeTypeArgument(tempReference_this, metaOffset, typeArgs.clone()); - this = tempReference_this.get(); - } - - this.WriteSparsePath(edit, metaOffset); - edit.get().valueOffset(edit.get().metaOffset() + metaBytes); - checkState(edit.get().valueOffset() == edit.get().metaOffset() + metaBytes); - } - - private void WriteSparsePath(Reference edit, int offset) { - // Some scopes don't encode paths, therefore the cost is always zero. - if (edit.get().scopeType().isIndexedScope()) { - edit.get().pathToken = 0; - edit.get().pathOffset = 0; - return; - } - - StringToken _; - Out tempOut__ = - new Out(); - checkState(!edit.get().layout().getTokenizer().TryFindToken(edit.get().writePath(), tempOut__) || !edit.get().writePathToken().isNull()); - _ = tempOut__.get(); - if (!edit.get().writePathToken().isNull()) { - edit.get().writePathToken().varint.CopyTo(this.buffer.Slice(offset)); - edit.get().pathToken = edit.get().intValue().writePathToken.Id; - edit.get().pathOffset = offset; - } else { - // TODO: It would be better if we could avoid allocating here when the path is UTF16. - Utf8Span span = edit.get().writePath().ToUtf8String(); - edit.get().pathToken = edit.get().layout().getTokenizer().getCount() + span.Length; - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (ulong)edit.pathToken); - int sizeLenInBytes = this.Write7BitEncodedUInt(offset, edit.get().longValue().pathToken); - edit.get().pathOffset = offset + sizeLenInBytes; - span.Span.CopyTo(this.buffer.Slice(offset + sizeLenInBytes)); - } - } - /** - * Return the size (in bytes) of the default sparse value for the type. + * Read the metadata of an encoded sparse field. * - * @param code The type of the default value. - * @param typeArgs + * @param edit The edit structure to fill in. + * + * + * On success, the path of the field at the given offset, otherwise + * undefined. + * + * + * On success, the offset to the metadata of the field, otherwise a + * location to insert the field. + * + * + * On success, the layout code of the existing field, otherwise + * undefined. + * + * + * On success, the type args of the existing field, otherwise + * undefined. + * + * + * On success, the offset to the value of the field, otherwise + * undefined. + * . */ - private int countDefaultValue(LayoutType code, TypeArgumentList typeArgs) { + private void readSparseMetadata(Reference edit) { + if (edit.get().scopeType().hasImplicitTypeCode(edit)) { + edit.get().scopeType().SetImplicitTypeCode(edit); + edit.get().valueOffset(edit.get().metaOffset()); + } else { + edit.get().cellType = this.ReadSparseTypeCode(edit.get().metaOffset()); + edit.get().valueOffset(edit.get().metaOffset() + (LayoutCode.SIZE / Byte.SIZE)); + edit.get().cellTypeArgs = TypeArgumentList.EMPTY; + if (edit.get().cellType() instanceof LayoutEndScope) { + // Reached end of current scope without finding another field. + edit.get().pathToken = 0; + edit.get().pathOffset = 0; + edit.get().valueOffset(edit.get().metaOffset()); + return; + } - // TODO: JTH: convert to a virtual? + Reference tempReference_this = + new Reference(this); + int sizeLenInBytes; + Out tempOut_sizeLenInBytes = new Out(); + edit.get().cellTypeArgs = edit.get().cellType().readTypeArgumentList(tempReference_this, + edit.get().valueOffset(), tempOut_sizeLenInBytes).clone(); + sizeLenInBytes = tempOut_sizeLenInBytes.get(); + this = tempReference_this.get(); + edit.get().valueOffset(edit.get().valueOffset() + sizeLenInBytes); + } - switch (code) { - if (code instanceof LayoutNull || code instanceof LayoutBoolean) { - return 1; - } - if (code instanceof LayoutInt8) { - return LayoutType.Int8.Size; - } - if (code instanceof LayoutInt16) { - return LayoutType.Int16.Size; - } - if (code instanceof LayoutInt32) { - return LayoutType.Int32.Size; - } - if (code instanceof LayoutInt64) { - return LayoutType.Int64.Size; - } - if (code instanceof LayoutUInt8) { - return LayoutType.UInt8.Size; - } - if (code instanceof LayoutUInt16) { - return LayoutType.UInt16.Size; - } - if (code instanceof LayoutUInt32) { - return LayoutType.UInt32.Size; - } - if (code instanceof LayoutUInt64) { - return LayoutType.UInt64.Size; - } - if (code instanceof LayoutFloat32) { - return LayoutType.Float32.Size; - } - if (code instanceof LayoutFloat64) { - return LayoutType.Float64.Size; - } - if (code instanceof LayoutFloat128) { - return LayoutType.Float128.Size; - } - if (code instanceof LayoutDecimal) { - return LayoutType.Decimal.Size; - } - if (code instanceof LayoutDateTime) { - return LayoutType.DateTime.Size; - if (code instanceof LayoutUnixDateTime) { - return LayoutType.UnixDateTime.Size; - if (code instanceof LayoutGuid) { - return LayoutType.Guid.Size; - if (code instanceof LayoutMongoDbObjectId) { - // return MongoDbObjectId.Size; - throw new UnsupportedOperationException(); - } - if (code instanceof LayoutUtf8 || code instanceof LayoutBinary || code instanceof LayoutVarInt || code instanceof LayoutVarUInt) { - // Variable length types preceded by their varuint size take 1 byte for a size of 0. - return 1; - } - if (code instanceof LayoutObject || code instanceof LayoutArray) { - // Variable length sparse collection scopes take 1 byte for the end-of-scope terminator. - return (LayoutCode.SIZE / Byte.SIZE); - } - if (code instanceof LayoutTypedArray || code instanceof LayoutTypedSet || code instanceof LayoutTypedMap) { - // Variable length typed collection scopes preceded by their scope size take sizeof(uint) for a size of 0. - return (Integer.SIZE / Byte.SIZE); - } - if (code instanceof LayoutTuple) { - // Fixed arity sparse collections take 1 byte for end-of-scope plus a null for each element. - return (LayoutCode.SIZE / Byte.SIZE) + ((LayoutCode.SIZE / Byte.SIZE) * typeArgs.count()); - } - if (code instanceof LayoutTypedTuple || code instanceof LayoutTagged || code instanceof LayoutTagged2) { - // Fixed arity typed collections take the sum of the default values of each element. The scope size is - // implied by the arity. - int sum = 0; - for (TypeArgument arg : typeArgs) { - sum += this.countDefaultValue(arg.type(), arg.typeArgs().clone()); - } - return sum; - } - if (code instanceof LayoutNullable) { - // Nullables take the default values of the value plus null. The scope size is implied by the arity. - return 1 + this.countDefaultValue(typeArgs.get(0).type(), typeArgs.get(0).typeArgs()); - } - if (code instanceof LayoutUDT) { - Layout udt = this.resolver.Resolve(typeArgs.schemaId()); - return udt.getSize() + (LayoutCode.SIZE / Byte.SIZE); - } - throw new IllegalStateException(lenientFormat("Not Implemented: %s", code)); + Reference tempReference_this2 = + new Reference(this); + edit.get().scopeType().ReadSparsePath(tempReference_this2, edit); + this = tempReference_this2.get(); } - private int WriteString(int offset, Utf8Span value) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (ulong)value.Length); - int sizeLenInBytes = this.Write7BitEncodedUInt(offset, (long)value.Length); - value.Span.CopyTo(this.buffer.Slice(offset + sizeLenInBytes)); - return sizeLenInBytes; + private void readSparsePrimitiveTypeCode(@Nonnull RowCursor edit, LayoutType code) { + + checkNotNull(edit); + checkArgument(edit.exists()); + + if (edit.scopeType().hasImplicitTypeCode(edit)) { + if (edit.scopeType() instanceof LayoutNullable) { + checkState(edit.scopeTypeArgs().count() == 1); + checkState(edit.index() == 1); + checkState(edit.scopeTypeArgs().get(0).type() == code); + checkState(edit.scopeTypeArgs().get(0).typeArgs().count() == 0); + } else if (edit.scopeType().isFixedArity()) { + checkState(edit.scopeTypeArgs().count() > edit.index()); + checkState(edit.scopeTypeArgs().get(edit.index()).type() == code); + checkState(edit.scopeTypeArgs().get(edit.index()).typeArgs().count() == 0); + } else { + checkState(edit.scopeTypeArgs().count() == 1); + checkState(edit.scopeTypeArgs().get(0).type() == code); + checkState(edit.scopeTypeArgs().get(0).typeArgs().count() == 0); + } + } else { + if (code == LayoutTypes.Boolean) { + code = this.ReadSparseTypeCode(edit.metaOffset()); + checkState(code == LayoutTypes.Boolean || code == LayoutTypes.BooleanFalse); + } else { + checkState(this.ReadSparseTypeCode(edit.metaOffset()) == code); + } + } + + if (edit.scopeType().isIndexedScope()) { + checkState(edit.pathOffset() == 0); + checkState(edit.pathToken() == 0); + } else { + Out pathLenInBytes = new Out<>(); + Out pathOffset = new Out<>(); + int token = this.ReadSparsePathLen(edit.layout(), edit.metaOffset() + (LayoutCode.SIZE / Byte.SIZE), + pathLenInBytes, pathOffset); + checkState(edit.pathOffset() == pathOffset.get()); + checkState(edit.pathToken() == token); + } } /** - * Represents a single item within a set/map scope that needs to be indexed - *

- * This structure is used when rebuilding a set/map index during row streaming via {@link RowWriter}.Each item - * encodes its offsets and length within the row. + * Compute the size of a sparse field. + * + * @param edit The edit structure describing the field to measure. + * @return The length (in bytes) of the encoded field including the metadata and the value. */ - static final class UniqueIndexItem { - - private LayoutCode Code = LayoutCode.values()[0]; - private int MetaOffset; - private int Size; - private int ValueOffset; - - /** - * The layout code of the value. - */ - public LayoutCode code() { - return Code; + private int sparseComputeSize(Reference edit) { + if (!(edit.get().cellType() instanceof LayoutScope)) { + return this.SparseComputePrimitiveSize(edit.get().cellType(), edit.get().metaOffset(), + edit.get().valueOffset()); } - public UniqueIndexItem code(LayoutCode code) { - Code = code; - return this; - } - - /** - * If existing, the offset to the metadata of the existing field, otherwise the location to insert a new field - */ - public int metaOffset() { - return MetaOffset; - } - - public UniqueIndexItem metaOffset(int metaOffset) { - MetaOffset = metaOffset; - return this; - } - - /** - * Size of the target element - */ - public int size() { - return Size; - } - - public UniqueIndexItem size(int size) { - Size = size; - return this; - } - - /** - * If existing, the offset to the value of the existing field, otherwise undefined - */ - public int valueOffset() { - return ValueOffset; - } - - public UniqueIndexItem valueOffset(int valueOffset) { - ValueOffset = valueOffset; - return this; - } - } -} \ No newline at end of file + // Compute offset to end of value for current value. + RowCursor newScope = this.SparseIteratorReadScope(edit, true).clone(); + Reference tempReference_newScope = + new Reference(newScope); + int tempVar = this.SkipScope(tempReference_newScope) - edit.get().metaOffset(); + newScope = tempReference_newScope.get(); + return tempVar; + } \ No newline at end of file diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java index bb8c37e..a314a33 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java @@ -4,7 +4,6 @@ package com.azure.data.cosmos.serialization.hybridrow; -import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.core.UtfAnyString; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope; @@ -18,53 +17,42 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList; import static com.google.common.base.Strings.lenientFormat; -public final class RowCursor { +public final class RowCursor implements Cloneable { - /** - * If existing, the layout code of the existing field, otherwise undefined. - */ - public LayoutType cellType; - /** - * For types with generic parameters (e.g. {@link LayoutTuple}, the type parameters. - */ - public TypeArgumentList cellTypeArgs; - /** - * If true, this scope is an unique index scope whose index will be built after its items are written. - */ - public boolean deferUniqueIndex; - /** - * If existing, the offset to the end of the existing field. Used as a hint when skipping - * forward. - */ - public int endOffset; - /** - * True if an existing field matching the search criteria was found. - */ - public boolean exists; - /** - * If existing, the offset scope relative path for reading. - */ - public int pathOffset; - /** - * If existing, the layout string token of scope relative path for reading. - */ - public int pathToken; + private LayoutType cellType; + private TypeArgumentList cellTypeArgs; private int count; + private boolean deferUniqueIndex; + private int endOffset; + private boolean exists; private boolean immutable; private int index; private Layout layout; private int metaOffset; + private int pathOffset; + private int pathToken; private LayoutScope scopeType; private TypeArgumentList scopeTypeArgs; private int start; private int valueOffset; private UtfAnyString writePath; - private StringToken writePathToken = new StringToken(); + private StringToken writePathToken; + + private RowCursor() { + } + + protected RowCursor clone() { + try { + return (RowCursor) super.clone(); + } catch (CloneNotSupportedException error) { + throw new IllegalStateException(error); + } + } public static RowCursor Create(RowBuffer row) { final SchemaId schemaId = row.ReadSchemaId(1); - final Layout layout = row.resolver().Resolve(schemaId); + final Layout layout = row.resolver().resolve(schemaId); final int sparseSegmentOffset = row.computeVariableValueOffset(layout, HybridRowHeader.SIZE, layout.numVariable()); return new RowCursor() @@ -79,7 +67,7 @@ public final class RowCursor { public static RowCursor CreateForAppend(RowBuffer row) { final SchemaId schemaId = row.ReadSchemaId(1); - final Layout layout = row.resolver().Resolve(schemaId); + final Layout layout = row.resolver().resolve(schemaId); return new RowCursor() .layout(layout) @@ -90,11 +78,30 @@ public final class RowCursor { .valueOffset(row.length()); } + /** + * If existing, the layout code of the existing field, otherwise undefined. + */ + public LayoutType cellType() { + return this.cellType; + } + + public RowCursor cellType(LayoutType cellType) { + this.cellType = cellType; + return this; + } + + /** + * For types with generic parameters (e.g. {@link LayoutTuple}, the type parameters. + */ + public TypeArgumentList cellTypeArgs() { + return this.cellTypeArgs; + } + /** * For sized scopes (e.g. Typed Array), the number of elements. */ public int count() { - return count; + return this.count; } public RowCursor count(int count) { @@ -102,13 +109,45 @@ public final class RowCursor { return this; } + /** + * If true, this scope is an unique index scope whose index will be built after its items are written. + */ + public boolean deferUniqueIndex() { + return this.deferUniqueIndex; + } + + /** + * If existing, the offset to the end of the existing field. Used as a hint when skipping + * forward. + */ + public int endOffset() { + return this.endOffset; + } + + public RowCursor endOffset(int endOffset) { + this.endOffset = endOffset; + return this; + } + + /** + * True if an existing field matching the search criteria was found. + */ + public boolean exists() { + return this.exists; + } + + public RowCursor exists(boolean exists) { + this.exists = exists; + return this; + } + /** * If {@code true}, this scope's nested fields cannot be updated individually *

* The entire scope can still be replaced. */ public boolean immutable() { - return immutable; + return this.immutable; } public RowCursor immutable(boolean immutable) { @@ -120,7 +159,7 @@ public final class RowCursor { * For indexed scopes (e.g. an Array scope), the zero-based index into the scope of the sparse field */ public int index() { - return index; + return this.index; } public RowCursor index(int index) { @@ -132,7 +171,7 @@ public final class RowCursor { * The layout describing the contents of the scope, or {@code null} if the scope is unschematized. */ public Layout layout() { - return layout; + return this.layout; } public RowCursor layout(Layout layout) { @@ -145,7 +184,7 @@ public final class RowCursor { * insert a new field. */ public int metaOffset() { - return metaOffset; + return this.metaOffset; } public RowCursor metaOffset(int metaOffset) { @@ -153,11 +192,25 @@ public final class RowCursor { return this; } + /** + * If existing, the offset scope relative path for reading. + */ + public int pathOffset() { + return this.pathOffset; + } + + /** + * If existing, the layout string token of scope relative path for reading. + */ + public int pathToken() { + return this.pathToken; + } + /** * The kind of scope within which this edit was prepared */ public LayoutScope scopeType() { - return scopeType; + return this.scopeType; } public RowCursor scopeType(LayoutScope scopeType) { @@ -169,7 +222,7 @@ public final class RowCursor { * The type parameters of the scope within which this edit was prepared */ public TypeArgumentList scopeTypeArgs() { - return scopeTypeArgs; + return this.scopeTypeArgs; } public RowCursor scopeTypeArgs(TypeArgumentList scopeTypeArgs) { @@ -182,7 +235,7 @@ public final class RowCursor { * the scope begins. */ public int start() { - return start; + return this.start; } public RowCursor start(int start) { @@ -203,9 +256,9 @@ public final class RowCursor { ? TypeArgument.NONE : new TypeArgument(this.scopeType(), this.scopeTypeArgs()); - TypeArgument typeArg = (this.cellType == null) || (this.cellType instanceof LayoutEndScope) + TypeArgument typeArg = (this.cellType() == null) || (this.cellType() instanceof LayoutEndScope) ? TypeArgument.NONE - : new TypeArgument(this.cellType, this.cellTypeArgs); + : new TypeArgument(this.cellType(), this.cellTypeArgs()); String pathOrIndex = this.writePath().isNull() ? String.valueOf(this.index()) : this.writePath().toString(); @@ -226,7 +279,7 @@ public final class RowCursor { * If existing, the offset to the value of the existing field, otherwise undefined. */ public int valueOffset() { - return valueOffset; + return this.valueOffset; } public RowCursor valueOffset(int valueOffset) { @@ -238,7 +291,7 @@ public final class RowCursor { * If existing, the scope relative path for writing. */ public UtfAnyString writePath() { - return writePath; + return this.writePath; } public void writePath(UtfAnyString writePath) { @@ -249,7 +302,7 @@ public final class RowCursor { * If WritePath is tokenized, then its token. */ public StringToken writePathToken() { - return writePathToken; + return this.writePathToken; } public void writePathToken(StringToken writePathToken) { diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursorExtensions.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursorExtensions.java deleted file mode 100644 index 4739d5c..0000000 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursorExtensions.java +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -package com.azure.data.cosmos.serialization.hybridrow; - -import com.azure.data.cosmos.core.Reference; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope; - -import static com.google.common.base.Preconditions.checkArgument; - -public final class RowCursorExtensions { - /** Makes a copy of the current cursor. - - The two cursors will have independent and unconnected lifetimes after cloning. However, - mutations to a {@link RowBuffer} can invalidate any active cursors over the same row. - - */ - // TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter: - // public static ref RowCursor Clone(this in RowCursor src, out RowCursor dest) - // { - // dest = src; - // return ref dest; - // } - - /** - * Returns an equivalent scope that is read-only. - */ - // TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter: - // public static ref RowCursor AsReadOnly(this in RowCursor src, out RowCursor dest) - // { - // dest = src; - // dest.immutable = true; - // return ref dest; - // } - - // TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter: - // public static ref RowCursor Find(this ref RowCursor edit, ref RowBuffer row, UtfAnyString path) - // { - // Contract.Requires(!edit.scopeType.IsIndexedScope); - // - // if (!(edit.cellType is LayoutEndScope)) - // { - // while (row.SparseIteratorMoveNext(ref edit)) - // { - // if (path.Equals(row.ReadSparsePath(ref edit))) - // { - // edit.exists = true; - // break; - // } - // } - // } - // - // edit.writePath = path; - // edit.writePathToken = default; - // return ref edit; - // } - - // TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter: - // public static ref RowCursor Find(this ref RowCursor edit, ref RowBuffer row, in StringToken pathToken) - // { - // Contract.Requires(!edit.scopeType.IsIndexedScope); - // - // if (!(edit.cellType is LayoutEndScope)) - // { - // while (row.SparseIteratorMoveNext(ref edit)) - // { - // if (pathToken.Id == (ulong)edit.pathToken) - // { - // edit.exists = true; - // break; - // } - // } - // } - // - // edit.writePath = pathToken.Path; - // edit.writePathToken = pathToken; - // return ref edit; - // } - public static boolean MoveNext(Reference edit, Reference row) { - edit.get().writePath(null); - edit.get().writePathToken(null); - return row.get().SparseIteratorMoveNext(edit); - } - - public static boolean MoveNext(Reference edit, Reference row, - Reference childScope) { - if (childScope.get().scopeType() != null) { - RowCursorExtensions.Skip(edit.get().clone(), row, childScope); - } - - return RowCursorExtensions.MoveNext(edit.get().clone(), row); - } - - public static boolean MoveTo(Reference edit, Reference row, int index) { - checkState(edit.get().index() <= index); - edit.get().writePath(null); - edit.get().writePathToken(null); - while (edit.get().index() < index) { - if (!row.get().SparseIteratorMoveNext(edit)) { - return false; - } - } - - return true; - } - - public static void Skip(Reference edit, Reference row, - Reference childScope) { - checkArgument(childScope.get().start() == edit.get().valueOffset()); - if (!(childScope.get().cellType instanceof LayoutEndScope)) { - while (row.get().SparseIteratorMoveNext(childScope)) { - } - } - - if (childScope.get().scopeType().isSizedScope()) { - edit.get().endOffset = childScope.get().metaOffset(); - } else { - edit.get().endOffset = childScope.get().metaOffset() + (LayoutCode.SIZE / Byte.SIZE); // Move past the end of scope marker. - } - - // TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java: - //#if DEBUG - childScope.setAndGet(null); - //#endif - } -} \ No newline at end of file diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursors.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursors.java new file mode 100644 index 0000000..c40dbb4 --- /dev/null +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursors.java @@ -0,0 +1,127 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +package com.azure.data.cosmos.serialization.hybridrow; + +import com.azure.data.cosmos.core.UtfAnyString; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope; +import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken; + +import javax.annotation.Nonnull; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +public final class RowCursors { + + private RowCursors() { + } + + public static RowCursor Find(@Nonnull RowCursor edit, @Nonnull RowBuffer row, @Nonnull UtfAnyString path) { + checkArgument(!edit.scopeType().isIndexedScope()); + + if (!(edit.cellType() instanceof LayoutEndScope)) { + while (row.sparseIteratorMoveNext(edit)) { + if (path.equals(row.readSparsePath(edit))) { + edit.exists(true); + break; + } + } + } + + edit.writePath(path); + edit.writePathToken(null); + + return edit; + } + + public static RowCursor Find(@Nonnull RowCursor edit, @Nonnull RowBuffer row, @Nonnull StringToken pathToken) { + + checkNotNull(edit); + checkNotNull(row); + checkNotNull(pathToken); + + checkArgument(!edit.scopeType().isIndexedScope()); + + if (!(edit.cellType() instanceof LayoutEndScope)) { + while (row.sparseIteratorMoveNext(edit)) { + if (pathToken.id() == (long) edit.pathToken()) { + edit.exists(true); + break; + } + } + } + + edit.writePath(new UtfAnyString(pathToken.path())); + edit.writePathToken(pathToken); + + return edit; + } + + /** + * Returns an equivalent scope that is read-only. + */ + public static RowCursor asReadOnly(RowCursor src) { + return src.clone().immutable(true); + } + + /** + * Makes a copy of the current cursor. + *

+ * The two cursors will have independent and unconnected lifetimes after cloning. However, mutations to a + * {@link RowBuffer} can invalidate any active cursors over the same row. + */ + public static RowCursor copy(RowCursor source) { + return source.clone(); + } + + public static boolean moveNext(RowCursor edit, RowBuffer row) { + edit.writePath(null); + edit.writePathToken(null); + return row.sparseIteratorMoveNext(edit); + } + + public static boolean moveNext(@Nonnull RowCursor edit, @Nonnull RowBuffer row, @Nonnull RowCursor childScope) { + if (childScope.scopeType() != null) { + RowCursors.skip(edit.clone(), row, childScope); + } + return RowCursors.moveNext(edit.clone(), row); + } + + public static boolean moveTo(@Nonnull final RowCursor edit, @Nonnull final RowBuffer row, final int index) { + + checkNotNull(row); + checkNotNull(edit); + checkArgument(edit.index() <= index); + + edit.writePath(null); + edit.writePathToken(null); + + while (edit.index() < index) { + if (!row.sparseIteratorMoveNext(edit)) { + return false; + } + } + + return true; + } + + public static void skip(RowCursor edit, RowBuffer row, RowCursor childScope) { + + checkArgument(childScope.start() == edit.valueOffset()); + + if (!(childScope.cellType() instanceof LayoutEndScope)) { + //noinspection StatementWithEmptyBody + while (row.sparseIteratorMoveNext(childScope)) { + } + } + + if (childScope.scopeType().isSizedScope()) { + edit.endOffset(childScope.metaOffset()); + } else { + edit.endOffset(childScope.metaOffset() + (LayoutCode.SIZE / Byte.SIZE)); // move past end of scope marker + } + } +} \ No newline at end of file diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/SchemaId.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/SchemaId.java index 9a62058..88902c9 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/SchemaId.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/SchemaId.java @@ -27,9 +27,12 @@ import static com.google.common.base.Strings.lenientFormat; @JsonSerialize(using = SchemaId.JsonSerializer.class) public final class SchemaId { + // TODO: DANOBLE: Consider caching SchemaId instances to reduce memory footprint + public static final SchemaId INVALID = null; - public static final SchemaId NONE = new SchemaId(); + public static final SchemaId NONE = new SchemaId(-1); public static final int SIZE = (Integer.SIZE / Byte.SIZE); + private static long MAX_VALUE = 0x00000000FFFFFFFFL; private final int id; @@ -38,14 +41,10 @@ public final class SchemaId { * * @param id The underlying globally unique identifier of the schema. */ - public SchemaId(int id) { + private SchemaId(int id) { this.id = id; } - private SchemaId() { - this.id = -1; - } - @Override public boolean equals(Object other) { return other instanceof SchemaId && this.equals((SchemaId) other); @@ -75,7 +74,16 @@ public final class SchemaId { * @return The integer value of this {@link SchemaId} */ public int id() { - return id; + return this.id; + } + + /** + * Returns a {@link SchemaId} from a specified underlying integer value + * + * @return The integer value of this {@link SchemaId} + */ + public static SchemaId from(int id) { + return new SchemaId(id); } @Override diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java index 65048e5..5c36891 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java @@ -13,7 +13,7 @@ import com.azure.data.cosmos.serialization.hybridrow.NullValue; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; import com.azure.data.cosmos.serialization.hybridrow.layouts.ILayoutSpanReadable; import com.azure.data.cosmos.serialization.hybridrow.layouts.ILayoutUtf8SpanReadable; @@ -67,14 +67,12 @@ public final class RowReader { private int columnIndex; private ReadOnlySpan columns; - private RowCursor cursor = new RowCursor(); - private RowBuffer row = new RowBuffer(); + private RowCursor cursor; + private RowBuffer row; private int schematizedCount; + private States state; // checkpoint state - // State that can be checkpointed. - private States state = States.values()[0]; - - public RowReader() { + private RowReader() { } /** @@ -140,7 +138,7 @@ public final class RowReader { return true; case Sparse: - if (this.cursor.cellType instanceof LayoutNullable) { + if (this.cursor.cellType() instanceof LayoutNullable) { Reference cursor = new Reference<>(this.cursor); RowCursor nullableScope = this.row.SparseIteratorReadScope(cursor, true).clone(); this.cursor = cursor.get(); @@ -193,13 +191,13 @@ public final class RowReader { case Schematized: return this.columns[this.columnIndex].Path; case Sparse: - if (this.cursor.pathOffset == 0) { + if (this.cursor.pathOffset() == 0) { return null; } Reference tempReference_cursor = new Reference(this.cursor); - Utf8Span span = this.row.ReadSparsePath(tempReference_cursor); + Utf8Span span = this.row.readSparsePath(tempReference_cursor); this.cursor = tempReference_cursor.get(); return Utf8String.CopyFrom(span); default: @@ -219,7 +217,7 @@ public final class RowReader { case Sparse: Reference tempReference_cursor = new Reference(this.cursor); - Utf8Span tempVar = this.row.ReadSparsePath(tempReference_cursor); + Utf8Span tempVar = this.row.readSparsePath(tempReference_cursor); this.cursor = tempReference_cursor.get(); return tempVar; default: @@ -249,7 +247,7 @@ public final class RowReader { case Schematized: return this.columns[this.columnIndex].Type; case Sparse: - return this.cursor.cellType; + return this.cursor.cellType(); default: return null; } @@ -263,7 +261,7 @@ public final class RowReader { case Schematized: return this.columns[this.columnIndex].TypeArgs; case Sparse: - return this.cursor.cellTypeArgs.clone(); + return this.cursor.cellTypeArgs().clone(); default: return TypeArgumentList.EMPTY; } @@ -314,7 +312,7 @@ public final class RowReader { Reference tempReference_row = new Reference(this.row); - if (!RowCursorExtensions.MoveNext(this.cursor.clone(), + if (!RowCursors.moveNext(this.cursor.clone(), tempReference_row)) { this.row = tempReference_row.get(); this.state = States.Done; @@ -368,7 +366,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutBinary)) { + if (!(this.cursor.cellType() instanceof LayoutBinary)) { value.setAndGet(null); return Result.TypeMismatch; } @@ -395,7 +393,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutBoolean)) { + if (!(this.cursor.cellType() instanceof LayoutBoolean)) { value.setAndGet(false); return Result.TypeMismatch; } @@ -422,7 +420,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutDateTime)) { + if (!(this.cursor.cellType() instanceof LayoutDateTime)) { value.setAndGet(LocalDateTime.MIN); return Result.TypeMismatch; } @@ -449,7 +447,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutDecimal)) { + if (!(this.cursor.cellType() instanceof LayoutDecimal)) { value.setAndGet(new BigDecimal(0)); return Result.TypeMismatch; } @@ -476,7 +474,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value.clone()); case Sparse: - if (!(this.cursor.cellType instanceof LayoutFloat128)) { + if (!(this.cursor.cellType() instanceof LayoutFloat128)) { value.setAndGet(null); return Result.TypeMismatch; } @@ -503,7 +501,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutFloat32)) { + if (!(this.cursor.cellType() instanceof LayoutFloat32)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -530,7 +528,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutFloat64)) { + if (!(this.cursor.cellType() instanceof LayoutFloat64)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -557,7 +555,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutGuid)) { + if (!(this.cursor.cellType() instanceof LayoutGuid)) { value.setAndGet(null); return Result.TypeMismatch; } @@ -584,7 +582,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutInt16)) { + if (!(this.cursor.cellType() instanceof LayoutInt16)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -611,7 +609,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutInt32)) { + if (!(this.cursor.cellType() instanceof LayoutInt32)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -638,7 +636,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutInt64)) { + if (!(this.cursor.cellType() instanceof LayoutInt64)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -665,7 +663,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutInt8)) { + if (!(this.cursor.cellType() instanceof LayoutInt8)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -692,7 +690,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value.clone()); case Sparse: - if (!(this.cursor.cellType instanceof LayoutMongoDbObjectId)) { + if (!(this.cursor.cellType() instanceof LayoutMongoDbObjectId)) { value.setAndGet(null); return Result.TypeMismatch; } @@ -719,14 +717,14 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value.clone()); case Sparse: - if (!(this.cursor.cellType instanceof LayoutNull)) { + if (!(this.cursor.cellType() instanceof LayoutNull)) { value.setAndGet(null); return Result.TypeMismatch; } Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseNull(tempReference_cursor).clone()); + value.setAndGet(this.row.readSparseNull(tempReference_cursor).clone()); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -785,7 +783,7 @@ public final class RowReader { new Reference(this.row); Reference tempReference_cursor2 = new Reference(nestedReader.cursor); - RowCursorExtensions.Skip(this.cursor.clone(), tempReference_row2, + RowCursors.skip(this.cursor.clone(), tempReference_row2, tempReference_cursor2); nestedReader.cursor = tempReference_cursor2.get(); this.row = tempReference_row2.get(); @@ -835,7 +833,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutUtf8)) { + if (!(this.cursor.cellType() instanceof LayoutUtf8)) { value.setAndGet(null); return Result.TypeMismatch; } @@ -864,7 +862,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutUInt16)) { + if (!(this.cursor.cellType() instanceof LayoutUInt16)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -893,7 +891,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutUInt32)) { + if (!(this.cursor.cellType() instanceof LayoutUInt32)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -922,7 +920,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutUInt64)) { + if (!(this.cursor.cellType() instanceof LayoutUInt64)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -951,7 +949,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutUInt8)) { + if (!(this.cursor.cellType() instanceof LayoutUInt8)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -978,7 +976,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value.clone()); case Sparse: - if (!(this.cursor.cellType instanceof LayoutUnixDateTime)) { + if (!(this.cursor.cellType() instanceof LayoutUnixDateTime)) { value.setAndGet(null); return Result.TypeMismatch; } @@ -1005,7 +1003,7 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutVarInt)) { + if (!(this.cursor.cellType() instanceof LayoutVarInt)) { value.setAndGet(0); return Result.TypeMismatch; } @@ -1034,14 +1032,14 @@ public final class RowReader { case Schematized: return this.ReadPrimitiveValue(value); case Sparse: - if (!(this.cursor.cellType instanceof LayoutVarUInt)) { + if (!(this.cursor.cellType() instanceof LayoutVarUInt)) { value.setAndGet(0); return Result.TypeMismatch; } Reference tempReference_cursor = new Reference(this.cursor); - value.setAndGet(this.row.ReadSparseVarUInt(tempReference_cursor)); + value.setAndGet(this.row.readSparseVarUInt(tempReference_cursor)); this.cursor = tempReference_cursor.get(); return Result.Success; default: @@ -1072,7 +1070,7 @@ public final class RowReader { new Reference(this.row); Reference tempReference_cursor = new Reference(nestedReader.get().cursor); - RowCursorExtensions.Skip(this.cursor.clone(), tempReference_row, + RowCursors.skip(this.cursor.clone(), tempReference_row, tempReference_cursor); nestedReader.get().argValue.cursor = tempReference_cursor.get(); this.row = tempReference_row.get(); diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java index 2dbd3ae..b3bd559 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java @@ -12,7 +12,7 @@ import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType; @@ -491,7 +491,7 @@ public final class RowWriter { //ORIGINAL LINE: case LayoutUDT scopeType: case LayoutUDT scopeType: - Layout udt = this.row.resolver().Resolve(typeArg.typeArgs().schemaId().clone()); + Layout udt = this.row.resolver().resolve(typeArg.typeArgs().schemaId().clone()); Reference tempReference_cursor9 = new Reference(this.cursor); Out tempOut_nestedScope9 = @@ -569,7 +569,7 @@ public final class RowWriter { new Reference(this.row); Reference tempReference_cursor12 = new Reference(nestedWriter.cursor); - RowCursorExtensions.MoveNext(this.cursor.clone(), tempReference_row2 + RowCursors.moveNext(this.cursor.clone(), tempReference_row2 , tempReference_cursor12); nestedWriter.cursor = tempReference_cursor12.get(); this.row = tempReference_row2.get(); @@ -815,7 +815,7 @@ public final class RowWriter { this = tempReference_this.get(); Reference tempReference_row = new Reference(this.row); - RowCursorExtensions.MoveNext(this.cursor.clone(), + RowCursors.moveNext(this.cursor.clone(), tempReference_row); this.row = tempReference_row.get(); } @@ -854,7 +854,7 @@ public final class RowWriter { this = tempReference_this.get(); Reference tempReference_row = new Reference(this.row); - RowCursorExtensions.MoveNext(this.cursor.clone(), + RowCursors.moveNext(this.cursor.clone(), tempReference_row); this.row = tempReference_row.get(); } @@ -893,7 +893,7 @@ public final class RowWriter { this = tempReference_this.get(); Reference tempReference_row = new Reference(this.row); - RowCursorExtensions.MoveNext(this.cursor.clone(), + RowCursors.moveNext(this.cursor.clone(), tempReference_row); this.row = tempReference_row.get(); } @@ -933,7 +933,7 @@ public final class RowWriter { this = tempReference_this.get(); Reference tempReference_row = new Reference(this.row); - RowCursorExtensions.MoveNext(this.cursor.clone(), + RowCursors.moveNext(this.cursor.clone(), tempReference_row); this.row = tempReference_row.get(); } diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/Layout.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/Layout.java index fab5740..7b3f21b 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/Layout.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/Layout.java @@ -29,7 +29,7 @@ import java.util.HashMap; */ public final class Layout { - public static final Layout EMPTY = SystemSchema.LayoutResolver.Resolve(SystemSchema.EmptySchemaId); + public static final Layout EMPTY = SystemSchema.LayoutResolver.resolve(SystemSchema.EmptySchemaId); private final String name; private final int numBitmaskBytes; diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java index 40c467b..5106650 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNull.java @@ -51,7 +51,7 @@ public final class LayoutNull extends LayoutType { return result; } - value.setAndGet(b.get().ReadSparseNull(edit).clone()); + value.setAndGet(b.get().readSparseNull(edit).clone()); return Result.Success; } diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java index 8dd969f..07e8e02 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java @@ -7,5 +7,5 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; import com.azure.data.cosmos.serialization.hybridrow.SchemaId; public abstract class LayoutResolver { - public abstract Layout Resolve(SchemaId schemaId); + public abstract Layout resolve(SchemaId schemaId); } \ No newline at end of file diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java index f1eb410..0fb4fb5 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java @@ -44,7 +44,7 @@ public final class LayoutResolverNamespace extends LayoutResolver { } @Override - public Layout Resolve(SchemaId schemaId) { + public Layout resolve(SchemaId schemaId) { Layout layout; // TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET // ConcurrentDictionary method: @@ -63,7 +63,7 @@ public final class LayoutResolverNamespace extends LayoutResolver { } } - layout = this.parent == null ? null : this.parent.Resolve(schemaId.clone()); + layout = this.parent == null ? null : this.parent.resolve(schemaId.clone()); if (layout != null) { // TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET // ConcurrentDictionary method: diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java index e606109..aed5c6f 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java @@ -14,7 +14,7 @@ public final class LayoutResolverSimple extends LayoutResolver { } @Override - public Layout Resolve(SchemaId schemaId) { + public Layout resolve(SchemaId schemaId) { return this.resolver.invoke(schemaId.clone()); } } \ No newline at end of file diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java index 7b8bb08..ae24a1d 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java @@ -9,9 +9,13 @@ import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import javax.annotation.Nonnull; + +import static com.google.common.base.Preconditions.checkNotNull; + public abstract class LayoutScope extends LayoutType { private boolean isFixedArity; @@ -81,13 +85,14 @@ public abstract class LayoutScope extends LayoutType { } /** - * Returns true if writing an item in the specified typed scope would elide the type code - * because it is implied by the type arguments. + * {@code true} if writing an item in the specified typed scope would elide the type code because it is implied by the + * type arguments * - * @param edit - * @return True if the type code is implied (not written), false otherwise. + * @param edit a non-null {@link RowCursor} specifying a typed scope + * @return {@code true} if the type code is implied (not written); {@code false} otherwise. */ - public boolean HasImplicitTypeCode(Reference edit) { + public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); return false; } @@ -163,7 +168,7 @@ public abstract class LayoutScope extends LayoutType { Reference tempReference_childScope2 = new Reference(childScope); - RowCursorExtensions.Skip(scope.get().clone(), b, + RowCursors.skip(scope.get().clone(), b, tempReference_childScope2); childScope = tempReference_childScope2.get(); return Result.Success; diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java index 42cdeac..c57436b 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java @@ -147,7 +147,7 @@ public abstract class LayoutType implements ILayoutType { if (exists) { int varOffset = b.get().computeVariableValueOffset(scope.get().layout(), scope.get().start(), col.getOffset()); - b.get().DeleteVariable(varOffset, this.isVarint()); + b.get().deleteVariable(varOffset, this.isVarint()); b.get().UnsetBit(scope.get().start(), col.getNullBit().clone()); } @@ -196,7 +196,7 @@ public abstract class LayoutType implements ILayoutType { return Result.InsufficientPermissions; } - if (edit.get().exists && LayoutCodeTraits.Canonicalize(edit.get().cellType.layoutCode()) != code) { + if (edit.get().exists() && LayoutCodeTraits.Canonicalize(edit.get().cellType().layoutCode()) != code) { return Result.TypeMismatch; } @@ -236,7 +236,7 @@ public abstract class LayoutType implements ILayoutType { return result; } - if (!srcEdit.get().exists) { + if (!srcEdit.get().exists()) { dstEdit.setAndGet(null); return Result.NotFound; } @@ -247,7 +247,7 @@ public abstract class LayoutType implements ILayoutType { return Result.InsufficientPermissions; } - if (!srcEdit.get().cellTypeArgs.equals(elementType.typeArgs())) { + if (!srcEdit.get().cellTypeArgs().equals(elementType.typeArgs())) { b.get().deleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.TypeConstraint; @@ -261,13 +261,13 @@ public abstract class LayoutType implements ILayoutType { // Prepare the insertion at the destination. dstEdit.setAndGet(b.get().PrepareSparseMove(destinationScope, srcEdit)); - if ((options == UpdateOptions.Update) && (!dstEdit.get().exists)) { + if ((options == UpdateOptions.Update) && (!dstEdit.get().exists())) { b.get().deleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.NotFound; } - if ((options == UpdateOptions.Insert) && dstEdit.get().exists) { + if ((options == UpdateOptions.Insert) && dstEdit.get().exists()) { b.get().deleteSparse(srcEdit); dstEdit.setAndGet(null); return Result.Exists; @@ -286,11 +286,11 @@ public abstract class LayoutType implements ILayoutType { */ public static Result prepareSparseRead(Reference b, Reference edit, LayoutCode code) { - if (!edit.get().exists) { + if (!edit.get().exists()) { return Result.NotFound; } - if (LayoutCodeTraits.Canonicalize(edit.get().cellType.layoutCode()) != code) { + if (LayoutCodeTraits.Canonicalize(edit.get().cellType().layoutCode()) != code) { return Result.TypeMismatch; } @@ -308,7 +308,7 @@ public abstract class LayoutType implements ILayoutType { */ public static Result prepareSparseWrite(Reference b, Reference edit, TypeArgument typeArg, UpdateOptions options) { - if (edit.get().immutable() || (edit.get().scopeType().isUniqueScope() && !edit.get().deferUniqueIndex)) { + if (edit.get().immutable() || (edit.get().scopeType().isUniqueScope() && !edit.get().deferUniqueIndex())) { return Result.InsufficientPermissions; } @@ -332,11 +332,11 @@ public abstract class LayoutType implements ILayoutType { edit.get().exists = false; // InsertAt never overwrites an existing item. } - if ((options == UpdateOptions.Update) && (!edit.get().exists)) { + if ((options == UpdateOptions.Update) && (!edit.get().exists())) { return Result.NotFound; } - if ((options == UpdateOptions.Insert) && edit.get().exists) { + if ((options == UpdateOptions.Insert) && edit.get().exists()) { return Result.Exists; } diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java index 2518a10..6ff425c 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java @@ -45,7 +45,7 @@ public final class LayoutUDT extends LayoutPropertyScope { @Override public Result WriteScope(Reference b, Reference edit, TypeArgumentList typeArgs, Out value, UpdateOptions options) { - Layout udt = b.get().resolver().Resolve(typeArgs.schemaId().clone()); + Layout udt = b.get().resolver().resolve(typeArgs.schemaId().clone()); Result result = prepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options); if (result != Result.Success) { value.setAndGet(null); diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java index 115e183..2a8475a 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java @@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowOptions; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; public abstract class LayoutUniqueScope extends LayoutIndexedScope { protected LayoutUniqueScope(LayoutCode code, boolean immutable, boolean isSizedScope, boolean isTypedScope) { @@ -140,7 +140,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope { Reference tempReference_childScope2 = new Reference(childScope); - RowCursorExtensions.Skip(scope.get().clone(), b, + RowCursors.skip(scope.get().clone(), b, tempReference_childScope2); childScope = tempReference_childScope2.get(); return Result.Success; diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java index 4026879..af297b9 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java @@ -52,7 +52,7 @@ public final class LayoutVarUInt extends LayoutType { return result; } - value.setAndGet(b.get().ReadSparseVarUInt(edit)); + value.setAndGet(b.get().readSparseVarUInt(edit)); return Result.Success; } diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringToken.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringToken.java index 0343476..ad08a6d 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringToken.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringToken.java @@ -5,43 +5,67 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; import com.azure.data.cosmos.core.Utf8String; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import javax.annotation.Nonnull; + +import static com.google.common.base.Preconditions.checkNotNull; public final class StringToken implements Cloneable { - public long id; - public Utf8String path; - public byte[] varint; + public static final StringToken NONE = new StringToken(); - public StringToken() { - } + private final long id; + private final Utf8String path; + private final ByteBuf varint; - public StringToken(long id, Utf8String path) { - this.varint = new byte[StringToken.Count7BitEncodedUInt(id)]; - StringToken.Write7BitEncodedUInt(this.varint, id); + public StringToken(long id, @Nonnull Utf8String path) { + + checkNotNull(path); + + byte[] buffer = new byte[count7BitEncodedUInt(id)]; + StringToken.write7BitEncodedUInt(buffer, id); + + this.varint = Unpooled.wrappedBuffer(buffer).asReadOnly(); this.path = path; this.id = id; } + private StringToken() { + this.id = 0L; + this.path = Utf8String.EMPTY; + this.varint = Unpooled.wrappedBuffer(new byte[1]).setInt(0, 0).asReadOnly(); + } + + public boolean isNull() { + return this.varint() == null; + } + + public long id() { + return this.id; + } + + public Utf8String path() { + return this.path; + } + + public ByteBuf varint() { + return this.varint; + } + @Override - public StringToken clone() { + protected StringToken clone() { try { - final StringToken token = (StringToken)super.clone(); - token.id = this.id; - token.path = this.path; - token.varint = this.varint; - return token; + return (StringToken) super.clone(); } catch (CloneNotSupportedException error) { assert false : error; throw new IllegalStateException(error); } } - public boolean isNull() { - return this.varint == null; - } - - private static int Count7BitEncodedUInt(long value) { + private static int count7BitEncodedUInt(long value) { // Count the number of bytes needed to write out an int 7 bits at a time. int i = 0; @@ -54,7 +78,7 @@ public final class StringToken implements Cloneable { return ++i; } - private static int Write7BitEncodedUInt(byte[] buffer, long value) { + private static int write7BitEncodedUInt(byte[] buffer, long value) { // Write an unsigned long 7 bits at a time. The high bit of the byte, when set, indicates there are more bytes. int i = 0; diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringTokenizer.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringTokenizer.java index ec6e908..1f0c956 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringTokenizer.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/StringTokenizer.java @@ -4,7 +4,6 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; -import com.azure.data.cosmos.core.Out; import com.azure.data.cosmos.core.Utf8String; import com.azure.data.cosmos.core.UtfAnyString; @@ -44,18 +43,10 @@ public final class StringTokenizer { * Looks up a token's corresponding string. * * @param token The token to look up. - * @param path If successful, the token's assigned string. * @return True if successful, false otherwise. */ - public boolean tryFindString(long token, Out path) { - - if (token >= (long)this.strings.size()) { - path.setAndGet(null); - return false; - } - - path.setAndGet(this.strings.get((int) token)); - return true; + public Optional tryFindString(long token) { + return token >= (long)this.strings.size() ? Optional.empty() : Optional.of(this.strings.get((int) token)); } /** @@ -112,7 +103,7 @@ public final class StringTokenizer { this.tokens.put(path, token); this.strings.add(path); - checkState((long)this.strings.size() - 1 == token.id); + checkState((long)this.strings.size() - 1 == token.id()); return token; } } \ No newline at end of file diff --git a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java index 04d77dc..6748405 100644 --- a/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java +++ b/jre/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOFormatter.java @@ -64,7 +64,7 @@ public final class RecordIOFormatter { private static Result FormatObject(ISpanResizer resizer, int initialCapacity, Layout layout, T obj, RowWriter.WriterFunc writer, Out row) { row.setAndGet(new RowBuffer(initialCapacity, resizer)); - row.get().InitLayout(HybridRowVersion.V1, layout, SystemSchema.LayoutResolver); + row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.LayoutResolver); Result r = RowWriter.WriteBuffer(row.clone(), obj, writer); if (r != Result.Success) { row.setAndGet(null); diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BsonRowGenerator.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BsonRowGenerator.java index f505c18..626f76b 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BsonRowGenerator.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/BsonRowGenerator.java @@ -140,7 +140,7 @@ public final class BsonRowGenerator implements Closeable { this.writer.WriteStartDocument(); HashMap dict = (HashMap)value; - Layout udt = this.resolver.Resolve(typeArg.typeArgs().schemaId().clone()); + Layout udt = this.resolver.resolve(typeArg.typeArgs().schemaId().clone()); for (LayoutColumn c : udt.columns()) { this.LayoutCodeSwitch(c.getPath(), c.getTypeArg().clone(), dict.get(c.getPath())); } diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java index 4ba589b..b3ed7c9 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java @@ -11,7 +11,7 @@ import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; @@ -50,7 +50,7 @@ public final class CodeGenRowGenerator { //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: public CodeGenRowGenerator(int capacity, Layout layout, LayoutResolver resolver, ISpanResizer resizer) { this.row = new RowBuffer(capacity, resizer); - this.row.InitLayout(HybridRowVersion.V1, layout, resolver); + this.row.initLayout(HybridRowVersion.V1, layout, resolver); switch (layout.name()) { case "Hotels": @@ -95,8 +95,8 @@ public final class CodeGenRowGenerator { } public void Reset() { - Layout layout = this.row.resolver().Resolve(this.row.header().getSchemaId().clone()); - this.row.InitLayout(HybridRowVersion.V1, layout, this.row.resolver()); + Layout layout = this.row.resolver().resolve(this.row.header().schemaId().clone()); + this.row.initLayout(HybridRowVersion.V1, layout, this.row.resolver()); } //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @@ -157,7 +157,7 @@ public final class CodeGenRowGenerator { Out tempOut_postalCodeToken = new Out(); layout.getTokenizer().TryFindToken(this.postalCode.getPath(), tempOut_postalCodeToken); this.postalCodeToken = tempOut_postalCodeToken.get(); - this.postalCodeSerializer = new PostalCodeHybridRowSerializer(resolver.Resolve(this.postalCode.getTypeArgs().schemaId().clone()), resolver); + this.postalCodeSerializer = new PostalCodeHybridRowSerializer(resolver.resolve(this.postalCode.getTypeArgs().schemaId().clone()), resolver); } @Override @@ -200,7 +200,7 @@ public final class CodeGenRowGenerator { } Reference tempReference_childScope2 = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, tempReference_childScope2); + RowCursors.skip(root.get().clone(), row, tempReference_childScope2); childScope = tempReference_childScope2.get(); return Result.Success; } @@ -269,7 +269,7 @@ public final class CodeGenRowGenerator { } Reference tempReference_childScope2 = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, tempReference_childScope2); + RowCursors.skip(root.get().clone(), row, tempReference_childScope2); childScope = tempReference_childScope2.get(); } @@ -353,7 +353,7 @@ public final class CodeGenRowGenerator { this.addresses.getTypeArgs().clone()) }); this.addressSerializer = - new AddressHybridRowSerializer(resolver.Resolve(this.addresses.getTypeArgs().get(1).typeArgs().schemaId().clone()), resolver); + new AddressHybridRowSerializer(resolver.resolve(this.addresses.getTypeArgs().get(1).typeArgs().schemaId().clone()), resolver); this.addressSerializerWriter = (Reference b, Reference scope, HashMap context) -> addressSerializer.WriteBuffer(b, scope, context); @@ -422,7 +422,7 @@ public final class CodeGenRowGenerator { Reference tempReference_childScope = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_childScope); childScope = tempReference_childScope.get(); root.get().Find(row, this.phoneNumbersToken.clone()); @@ -450,7 +450,7 @@ public final class CodeGenRowGenerator { Reference tempReference_childScope2 = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_childScope2); childScope = tempReference_childScope2.get(); root.get().Find(row, this.addressesToken.clone()); @@ -527,7 +527,7 @@ public final class CodeGenRowGenerator { Reference tempReference_childScope4 = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_childScope4); childScope = tempReference_childScope4.get(); @@ -665,7 +665,7 @@ public final class CodeGenRowGenerator { } Reference tempReference_childScope = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, tempReference_childScope); + RowCursors.skip(root.get().clone(), row, tempReference_childScope); childScope = tempReference_childScope.get(); } @@ -796,7 +796,7 @@ public final class CodeGenRowGenerator { layout.getTokenizer().TryFindToken(this.address.getPath(), tempOut_addressToken); this.addressToken = tempOut_addressToken.get(); this.addressSerializer = - new AddressHybridRowSerializer(resolver.Resolve(this.address.getTypeArgs().schemaId().clone()), + new AddressHybridRowSerializer(resolver.resolve(this.address.getTypeArgs().schemaId().clone()), resolver); } @@ -849,7 +849,7 @@ public final class CodeGenRowGenerator { Reference tempReference_childScope2 = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_childScope2); childScope = tempReference_childScope2.get(); return Result.Success; @@ -925,7 +925,7 @@ public final class CodeGenRowGenerator { } Reference tempReference_childScope2 = new Reference(childScope); - RowCursorExtensions.Skip(root.get().clone(), row, tempReference_childScope2); + RowCursors.skip(root.get().clone(), row, tempReference_childScope2); childScope = tempReference_childScope2.get(); } diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java index a34d0cf..857dd4a 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java @@ -44,7 +44,7 @@ public final class JsonModelRowGenerator { //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: public JsonModelRowGenerator(int capacity, Layout layout, LayoutResolver resolver, ISpanResizer resizer) { this.row = new RowBuffer(capacity, resizer); - this.row.InitLayout(HybridRowVersion.V1, layout, resolver); + this.row.initLayout(HybridRowVersion.V1, layout, resolver); } public int getLength() { @@ -62,12 +62,12 @@ public final class JsonModelRowGenerator { // TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or // output: public boolean ReadFrom(InputStream stream, int length) { - return this.row.ReadFrom(stream, length, HybridRowVersion.V1, this.row.resolver()); + return this.row.readFrom(stream, length, HybridRowVersion.V1, this.row.resolver()); } public void Reset() { - Layout layout = this.row.resolver().Resolve(this.row.header().getSchemaId().clone()); - this.row.InitLayout(HybridRowVersion.V1, layout, this.row.resolver()); + Layout layout = this.row.resolver().resolve(this.row.header().schemaId().clone()); + this.row.initLayout(HybridRowVersion.V1, layout, this.row.resolver()); } //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CustomerExampleUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CustomerExampleUnitTests.java index 5ff7c7d..ef9696d 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CustomerExampleUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/CustomerExampleUnitTests.java @@ -6,12 +6,11 @@ package com.azure.data.cosmos.serialization.hybridrow.unit; import com.azure.data.cosmos.core.Out; import com.azure.data.cosmos.core.Reference; -import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import java.nio.file.Files; import java.util.ArrayList; @@ -46,7 +45,7 @@ public final class CustomerExampleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateGuest() public void CreateGuest() { RowBuffer row = new RowBuffer(1024 * 1024); - row.InitLayout(HybridRowVersion.V1, this.guestLayout, this.customerResolver); + row.initLayout(HybridRowVersion.V1, this.guestLayout, this.customerResolver); Guest g1 = new Guest(); g1.Id = UUID.fromString("64d9d6d3-fd6b-4556-8c6e-d960a7ece7b9"); @@ -184,7 +183,7 @@ public final class CustomerExampleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateHotel() public void CreateHotel() { RowBuffer row = new RowBuffer(0); - row.InitLayout(HybridRowVersion.V1, this.hotelLayout, this.customerResolver); + row.initLayout(HybridRowVersion.V1, this.hotelLayout, this.customerResolver); Hotel h1 = this.hotelExample; Reference tempReference_row = @@ -218,7 +217,7 @@ public final class CustomerExampleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void FrozenHotel() public void FrozenHotel() { RowBuffer row = new RowBuffer(0); - row.InitLayout(HybridRowVersion.V1, this.hotelLayout, this.customerResolver); + row.initLayout(HybridRowVersion.V1, this.hotelLayout, this.customerResolver); Hotel h1 = this.hotelExample; Reference tempReference_row = @@ -435,7 +434,7 @@ public final class CustomerExampleUnitTests { postalCodeScope = tempReference_postalCodeScope.get(); Reference tempReference_postalCodeScope2 = new Reference(postalCodeScope); - RowCursorExtensions.Skip(addressScope.get().clone(), row, + RowCursors.skip(addressScope.get().clone(), row, tempReference_postalCodeScope2); postalCodeScope = tempReference_postalCodeScope2.get(); return a; @@ -556,13 +555,13 @@ public final class CustomerExampleUnitTests { tempReference_addressesScope2, tempOut_pairScope)); pairScope = tempOut_pairScope.get(); addressesScope = tempReference_addressesScope2.get(); - assert RowCursorExtensions.MoveNext(pairScope.clone(), row); + assert RowCursors.moveNext(pairScope.clone(), row); Reference tempReference_pairScope2 = new Reference(pairScope); String key; // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified: ResultAssert.IsSuccess(t0.TypeAs().ReadSparse(row, tempReference_pairScope2, out key)); pairScope = tempReference_pairScope2.get(); - assert RowCursorExtensions.MoveNext(pairScope.clone(), row); + assert RowCursors.moveNext(pairScope.clone(), row); Reference tempReference_pairScope3 = new Reference(pairScope); RowCursor addressScope; Out tempOut_addressScope = new Out(); @@ -574,7 +573,7 @@ public final class CustomerExampleUnitTests { addressScope = tempReference_addressScope.get(); g.Addresses.put(key, value); Reference tempReference_addressScope2 = new Reference(addressScope); - assert !RowCursorExtensions.MoveNext(pairScope.clone(), row, tempReference_addressScope2); + assert !RowCursors.moveNext(pairScope.clone(), row, tempReference_addressScope2); addressScope = tempReference_addressScope2.get(); } pairScope = tempReference_pairScope.get(); @@ -621,7 +620,7 @@ public final class CustomerExampleUnitTests { addressScope = tempReference_addressScope.get(); Reference tempReference_addressScope2 = new Reference(addressScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_addressScope2); addressScope = tempReference_addressScope2.get(); return h; @@ -684,7 +683,7 @@ public final class CustomerExampleUnitTests { postalCodeScope = tempReference_postalCodeScope.get(); Reference tempReference_postalCodeScope2 = new Reference(postalCodeScope); - RowCursorExtensions.Skip(addressScope.get().clone(), row, + RowCursors.skip(addressScope.get().clone(), row, tempReference_postalCodeScope2); postalCodeScope = tempReference_postalCodeScope2.get(); } @@ -733,7 +732,7 @@ public final class CustomerExampleUnitTests { Reference tempReference_emailScope = new Reference(emailScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_emailScope); emailScope = tempReference_emailScope.get(); } @@ -761,7 +760,7 @@ public final class CustomerExampleUnitTests { Reference tempReference_phoneNumbersScope = new Reference(phoneNumbersScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_phoneNumbersScope); phoneNumbersScope = tempReference_phoneNumbersScope.get(); } @@ -830,7 +829,7 @@ public final class CustomerExampleUnitTests { Reference tempReference_addressesScope = new Reference(addressesScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_addressesScope); addressesScope = tempReference_addressesScope.get(); } @@ -865,7 +864,7 @@ public final class CustomerExampleUnitTests { addressScope = tempReference_addressScope.get(); Reference tempReference_addressScope2 = new Reference(addressScope); - RowCursorExtensions.Skip(root.get().clone(), row, + RowCursors.skip(root.get().clone(), row, tempReference_addressScope2); addressScope = tempReference_addressScope2.get(); } diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/NullableUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/NullableUnitTests.java index cfc3e2e..b239b50 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/NullableUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/NullableUnitTests.java @@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; import java.nio.file.Files; @@ -37,7 +37,7 @@ public final class NullableUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateNullables() public void CreateNullables() { RowBuffer row = new RowBuffer(NullableUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Nullables t1 = new Nullables(); t1.NullBool = new ArrayList(Arrays.asList(true, false, null)); @@ -125,7 +125,7 @@ public final class NullableUnitTests { return r; } - if (RowCursorExtensions.MoveNext(nullableScope.get().clone(), row)) { + if (RowCursors.moveNext(nullableScope.get().clone(), row)) { ResultAssert.IsSuccess(LayoutNullable.HasValue(row, nullableScope.clone())); return itemType.getTypeArgs().get(0).getType().>TypeAs().ReadSparse(row, nullableScope.clone(), item); @@ -267,7 +267,7 @@ public final class NullableUnitTests { tupleScope = tempOut_tupleScope.get(); scope = tempReference_scope4.get(); - assert RowCursorExtensions.MoveNext(tupleScope.clone() + assert RowCursors.moveNext(tupleScope.clone() , row); Reference tempReference_tupleScope2 = new Reference(tupleScope); @@ -283,7 +283,7 @@ public final class NullableUnitTests { tupleScope = tempReference_tupleScope2.get(); Reference tempReference_nullableScope4 = new Reference(nullableScope); - assert RowCursorExtensions.MoveNext(tupleScope.clone() + assert RowCursors.moveNext(tupleScope.clone() , row, tempReference_nullableScope4); nullableScope = tempReference_nullableScope4.get(); Reference tempReference_tupleScope3 = @@ -300,7 +300,7 @@ public final class NullableUnitTests { Reference tempReference_nullableScope5 = new Reference(nullableScope); - assert !RowCursorExtensions.MoveNext(tupleScope.clone(), row, tempReference_nullableScope5); + assert !RowCursors.moveNext(tupleScope.clone(), row, tempReference_nullableScope5); nullableScope = tempReference_nullableScope5.get(); value.NullTuple.add((item1, item2)) } @@ -339,7 +339,7 @@ public final class NullableUnitTests { tupleScope = tempOut_tupleScope2.get(); scope = tempReference_scope5.get(); - assert RowCursorExtensions.MoveNext(tupleScope.clone() + assert RowCursors.moveNext(tupleScope.clone() , row); Reference tempReference_tupleScope5 = new Reference(tupleScope); @@ -356,7 +356,7 @@ public final class NullableUnitTests { Reference tempReference_nullableScope6 = new Reference(nullableScope); - assert RowCursorExtensions.MoveNext(tupleScope.clone() + assert RowCursors.moveNext(tupleScope.clone() , row, tempReference_nullableScope6); nullableScope = tempReference_nullableScope6.get(); Reference tempReference_tupleScope6 = @@ -373,7 +373,7 @@ public final class NullableUnitTests { Reference tempReference_nullableScope7 = new Reference(nullableScope); - assert !RowCursorExtensions.MoveNext(tupleScope.clone(), row, tempReference_nullableScope7); + assert !RowCursors.moveNext(tupleScope.clone(), row, tempReference_nullableScope7); nullableScope = tempReference_nullableScope7.get(); value.NullMap.put(itemKey != null ? itemKey : UUID.Empty, itemValue); } diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java index 6c532d6..6db2dc4 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RecordIOUnitTests.java @@ -227,7 +227,7 @@ public class RecordIOUnitTests { private Result WriteAddress(MemorySpanResizer resizer, Address obj, Out> buffer) { RowBuffer row = new RowBuffer(RecordIOUnitTests.InitialRowSize, resizer); - row.InitLayout(HybridRowVersion.V1, this.addressLayout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.addressLayout, this.resolver); Reference tempReference_row = new Reference(row); Result r = RowWriter.WriteBuffer(tempReference_row, obj, AddressSerializer.Write); diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java index 3103f8d..c828267 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowOperationDispatcher.java @@ -6,7 +6,6 @@ package com.azure.data.cosmos.serialization.hybridrow.unit; import com.azure.data.cosmos.core.Out; import com.azure.data.cosmos.core.Reference; -import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.serialization.hybridrow.Float128; import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.NullValue; @@ -72,7 +71,7 @@ public final class RowOperationDispatcher { this.dispatcher = dispatcher; this.Row = new RowBuffer(RowOperationDispatcher.InitialRowSize); this.Resolver = resolver; - this.Row.InitLayout(HybridRowVersion.V1, layout, this.Resolver); + this.Row.initLayout(HybridRowVersion.V1, layout, this.Resolver); } private RowOperationDispatcher(IDispatcher dispatcher, LayoutResolver resolver, String expected) { @@ -82,7 +81,7 @@ public final class RowOperationDispatcher { //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //ORIGINAL LINE: byte[] bytes = ByteConverter.ToBytes(expected); byte[] bytes = ByteConverter.ToBytes(expected); - this.Row.ReadFrom(bytes, HybridRowVersion.V1, this.Resolver); + this.Row.readFrom(bytes, HybridRowVersion.V1, this.Resolver); } // TODO: C# TO JAVA CONVERTER: The C# 'struct' constraint has no equivalent in Java: diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java index cd77fa0..f052e3c 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowReaderUnitTests.java @@ -197,7 +197,7 @@ public final class RowReaderUnitTests { RowBuffer row = new RowBuffer(0, resizer); Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals( "Mixed")).SchemaId); - row.InitLayout(HybridRowVersion.V1, layout, this.resolver); + row.initLayout(HybridRowVersion.V1, layout, this.resolver); Reference tempReference_row = new Reference(row); diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java index 81e77ce..1145559 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/RowWriterUnitTests.java @@ -6,7 +6,6 @@ package com.azure.data.cosmos.serialization.hybridrow.unit; import com.azure.data.cosmos.core.Out; import com.azure.data.cosmos.core.Reference; -import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.serialization.hybridrow.Float128; import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.NullValue; @@ -52,7 +51,7 @@ public final class RowWriterUnitTests { assert layout != null; RowBuffer row = new RowBuffer(RowWriterUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, layout, this.resolver); + row.initLayout(HybridRowVersion.V1, layout, this.resolver); int writerLength = 0; Reference tempReference_row = diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java index 220798c..6fc34be 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/SerializerUnitTest.java @@ -66,7 +66,7 @@ public final class SerializerUnitTest { // Write the request by serializing it to a row. RowBuffer row = new RowBuffer(SerializerUnitTest.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Reference tempReference_row = new Reference(row); Result r = RowWriter.WriteBuffer(tempReference_row, request, BatchRequestSerializer.Write); diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TaggedUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TaggedUnitTests.java index cb05446..59ba558 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TaggedUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TaggedUnitTests.java @@ -4,7 +4,6 @@ package com.azure.data.cosmos.serialization.hybridrow.unit; -import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.core.Reference; import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.Result; @@ -26,7 +25,7 @@ public final class TaggedUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateTaggedApi() public void CreateTaggedApi() { RowBuffer row = new RowBuffer(TaggedUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); TaggedApi c1 = new TaggedApi(); //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TupleUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TupleUnitTests.java index 54b1b2b..1161a1f 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TupleUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TupleUnitTests.java @@ -34,7 +34,7 @@ public final class TupleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateCoordCounter() public void CreateCoordCounter() { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); PerfCounter c1 = new PerfCounter(); c1.Name = "CoordInserts"; @@ -70,7 +70,7 @@ public final class TupleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateCounter() public void CreateCounter() { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); PerfCounter c1 = this.counterExample; Reference tempReference_row = @@ -100,7 +100,7 @@ public final class TupleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateMinMeanMaxCounter() public void CreateMinMeanMaxCounter() { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); PerfCounter c1 = new PerfCounter(); c1.Name = "RowInserts"; @@ -135,7 +135,7 @@ public final class TupleUnitTests { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); Layout layout = this.countersResolver.Resolve(tangible.ListHelper.find(this.counterSchema.getSchemas(), x -> x.Name.equals("CounterSet")).SchemaId); - row.InitLayout(HybridRowVersion.V1, layout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, layout, this.countersResolver); LayoutColumn col; // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these @@ -280,7 +280,7 @@ public final class TupleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void PreventInsertsAndDeletesInFixedArityCounter() public void PreventInsertsAndDeletesInFixedArityCounter() { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); PerfCounter c1 = this.counterExample; Reference tempReference_row = @@ -373,7 +373,7 @@ public final class TupleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void VerifyTypeConstraintsCoordCounter() public void VerifyTypeConstraintsCoordCounter() { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); PerfCounter c1 = new PerfCounter(); c1.Name = "RowInserts"; @@ -464,7 +464,7 @@ public final class TupleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void VerifyTypeConstraintsCounter() public void VerifyTypeConstraintsCounter() { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); PerfCounter c1 = this.counterExample; Reference tempReference_row = @@ -540,7 +540,7 @@ public final class TupleUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void VerifyTypeConstraintsMinMeanMaxCounter() public void VerifyTypeConstraintsMinMeanMaxCounter() { RowBuffer row = new RowBuffer(TupleUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); + row.initLayout(HybridRowVersion.V1, this.countersLayout, this.countersResolver); PerfCounter c1 = new PerfCounter(); c1.Name = "RowInserts"; @@ -877,7 +877,7 @@ public final class TupleUnitTests { } private static void WriteCoord(Reference row, Reference coordScope, TypeArgumentList typeArgs, Coord cd) { - Layout coordLayout = row.get().resolver().Resolve(typeArgs.getSchemaId().clone()); + Layout coordLayout = row.get().resolver().resolve(typeArgs.getSchemaId().clone()); LayoutColumn c; // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified: assert coordLayout.TryFind("lat", out c); diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedArrayUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedArrayUnitTests.java index af5a8d4..44ea9f2 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedArrayUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedArrayUnitTests.java @@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; -import com.azure.data.cosmos.serialization.hybridrow.RowCursorExtensions; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import java.nio.file.Files; import java.util.ArrayList; @@ -34,7 +34,7 @@ public final class TypedArrayUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateTags() public void CreateTags() { RowBuffer row = new RowBuffer(TypedArrayUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Tagged t1 = new Tagged(); t1.Title = "Thriller"; @@ -221,7 +221,7 @@ public final class TypedArrayUnitTests { ResultAssert.IsSuccess(innerLayout.ReadScope(row, tempReference_ratingsScope, tempOut_innerScope)); innerScope = tempOut_innerScope.get(); ratingsScope = tempReference_ratingsScope.get(); - while (RowCursorExtensions.MoveNext(innerScope.clone() + while (RowCursors.moveNext(innerScope.clone() , row)) { LayoutFloat64 itemLayout = innerType.getTypeArgs().get(0).getType().TypeAs(); Reference tempReference_innerScope2 @@ -299,7 +299,7 @@ public final class TypedArrayUnitTests { ResultAssert.IsSuccess(innerLayout.ReadScope(row, tempReference_priorityScope, tempOut_tupleScope)); tupleScope = tempOut_tupleScope.get(); priorityScope = tempReference_priorityScope.get(); - assert RowCursorExtensions.MoveNext(tupleScope.clone() + assert RowCursors.moveNext(tupleScope.clone() , row); Reference tempReference_tupleScope2 = new Reference(tupleScope); @@ -311,7 +311,7 @@ public final class TypedArrayUnitTests { tempReference_tupleScope2, out item1)); tupleScope = tempReference_tupleScope2.get(); - assert RowCursorExtensions.MoveNext(tupleScope.clone() + assert RowCursors.moveNext(tupleScope.clone() , row); Reference tempReference_tupleScope3 = new Reference(tupleScope); @@ -332,7 +332,7 @@ public final class TypedArrayUnitTests { private static void WriteSimilarMatch(Reference row, Reference matchScope , TypeArgumentList typeArgs, SimilarMatch m) { - Layout matchLayout = row.get().resolver().Resolve(typeArgs.getSchemaId().clone()); + Layout matchLayout = row.get().resolver().resolve(typeArgs.getSchemaId().clone()); LayoutColumn c; // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these // cannot be converted using the 'Out' helper class unless the method is within the code being modified: diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedMapUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedMapUnitTests.java index 04b2bb7..e09bf1d 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedMapUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedMapUnitTests.java @@ -35,7 +35,7 @@ public final class TypedMapUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateMovies() public void CreateMovies() { RowBuffer row = new RowBuffer(TypedMapUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); // ReSharper disable StringLiteralTypo Movie t1 = new Movie(); @@ -88,7 +88,7 @@ public final class TypedMapUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void FindAndDelete() public void FindAndDelete() { RowBuffer row = new RowBuffer(TypedMapUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Reference tempReference_row = new Reference(row); RowCursor root = RowCursor.Create(tempReference_row); @@ -184,7 +184,7 @@ public final class TypedMapUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void FindInMap() public void FindInMap() { RowBuffer row = new RowBuffer(TypedMapUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Reference tempReference_row = new Reference(row); RowCursor root = RowCursor.Create(tempReference_row); @@ -284,7 +284,7 @@ public final class TypedMapUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void PreventUniquenessViolations() public void PreventUniquenessViolations() { RowBuffer row = new RowBuffer(TypedMapUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Reference tempReference_row = new Reference(row); RowCursor root = RowCursor.Create(tempReference_row); @@ -475,7 +475,7 @@ public final class TypedMapUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void PreventUpdatesInNonUpdatableScope() public void PreventUpdatesInNonUpdatableScope() { RowBuffer row = new RowBuffer(TypedMapUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Reference tempReference_row = new Reference(row); RowCursor root = RowCursor.Create(tempReference_row); @@ -677,7 +677,7 @@ public final class TypedMapUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void UpdateInMap() public void UpdateInMap() { RowBuffer row = new RowBuffer(TypedMapUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Reference tempReference_row = new Reference(row); RowCursor root = RowCursor.Create(tempReference_row); @@ -1179,7 +1179,7 @@ public final class TypedMapUnitTests { } private static void WriteEarnings(Reference row, Reference udtScope, TypeArgumentList typeArgs, Earnings m) { - Layout udt = row.get().resolver().Resolve(typeArgs.getSchemaId().clone()); + Layout udt = row.get().resolver().resolve(typeArgs.getSchemaId().clone()); LayoutColumn c; // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified: assert udt.TryFind("domestic", out c); diff --git a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedSetUnitTests.java b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedSetUnitTests.java index e46100d..5c218ac 100644 --- a/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedSetUnitTests.java +++ b/jre/src/test/java/com/azure/data/cosmos/serialization/hybridrow/unit/TypedSetUnitTests.java @@ -31,7 +31,7 @@ public final class TypedSetUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateTodos() public void CreateTodos() { RowBuffer row = new RowBuffer(TypedSetUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Todo t1 = new Todo(); t1.Attendees = new ArrayList(Arrays.asList("jason", "janice", "joshua")); @@ -86,7 +86,7 @@ public final class TypedSetUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void FindAndDelete() public void FindAndDelete() { RowBuffer row = new RowBuffer(TypedSetUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); ArrayList expected = new ArrayList(Arrays.asList(UUID.fromString("{4674962B-CE11-4916-81C5" + "-0421EE36F168}"), UUID.fromString("{7499C40E-7077-45C1-AE5F-3E384966B3B9}"), UUID.fromString("{B7BC39C2" + @@ -182,7 +182,7 @@ public final class TypedSetUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void FindInSet() public void FindInSet() { RowBuffer row = new RowBuffer(TypedSetUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Todo t1 = new Todo(); t1.Attendees = new ArrayList(Arrays.asList("jason", "janice", "joshua")); @@ -357,7 +357,7 @@ public final class TypedSetUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void PreventUniquenessViolations() public void PreventUniquenessViolations() { RowBuffer row = new RowBuffer(TypedSetUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Todo t1 = new Todo(); t1.Attendees = new ArrayList(Arrays.asList("jason")); @@ -697,7 +697,7 @@ public final class TypedSetUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void PreventUpdatesInNonUpdatableScope() public void PreventUpdatesInNonUpdatableScope() { RowBuffer row = new RowBuffer(TypedSetUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); // Write a set and then try to write directly into it. LayoutColumn c; @@ -892,7 +892,7 @@ public final class TypedSetUnitTests { Todo t1 = new Todo(); t1.Projects = new ArrayList(permutation); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); Reference tempReference_row = new Reference(row); ResultAssert.IsSuccess(RowWriter.WriteBuffer(tempReference_row, t1, TypedSetUnitTests.SerializeTodo)); @@ -977,7 +977,7 @@ public final class TypedSetUnitTests { //ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void UpdateInSet() public void UpdateInSet() { RowBuffer row = new RowBuffer(TypedSetUnitTests.InitialRowSize); - row.InitLayout(HybridRowVersion.V1, this.layout, this.resolver); + row.initLayout(HybridRowVersion.V1, this.layout, this.resolver); ArrayList expected = new ArrayList(Arrays.asList(UUID.fromString("{4674962B-CE11-4916-81C5" + "-0421EE36F168}"), UUID.fromString("{7499C40E-7077-45C1-AE5F-3E384966B3B9}"), UUID.fromString("{B7BC39C2" + @@ -1466,7 +1466,7 @@ public final class TypedSetUnitTests { } private static void WriteShoppingItem(Reference row, Reference matchScope, TypeArgumentList typeArgs, ShoppingItem m) { - Layout matchLayout = row.get().resolver().Resolve(typeArgs.getSchemaId().clone()); + Layout matchLayout = row.get().resolver().resolve(typeArgs.getSchemaId().clone()); LayoutColumn c; // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified: assert matchLayout.TryFind("label", out c);