Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-09-09 22:05:00 -07:00
parent 2db3d8d517
commit 05577333c0
65 changed files with 1514 additions and 1438 deletions

View File

@@ -98,6 +98,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return StreamSupport.intStream(new CodePointIterable(this.buffer, this.length), false);
}
public final int compareTo(@Nonnull final Utf8String other) {
checkNotNull(other, "expected non-null other");
@@ -349,11 +350,11 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
@Override
public String toString() {
return this.buffer.getCharSequence(0, this.buffer.capacity(), UTF_8).toString();
return this.buffer.getCharSequence(0, this.buffer.writerIndex(), UTF_8).toString();
}
public String toUtf16() {
return this.buffer.getCharSequence(0, this.buffer.capacity(), UTF_8).toString();
return this.buffer.getCharSequence(0, this.buffer.writerIndex(), UTF_8).toString();
}
@Override

View File

@@ -1,25 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow;
public interface ISpanResizer<T> {
/**
* Resizes an existing a buffer.
* <typeparam name="T">The type of the elements of the memory.</typeparam>
*
* @param minimumLength The minimum required length (in elements) of the memory.
* @param buffer Optional existing memory to be copied to the new buffer. Ownership of <paramref
* name="buffer" /> is
* transferred as part of this call and it should not be used by the caller after this call
* completes.
* @return A new memory whose size is <em>at least as big</em> as <paramref name="minimumLength" />
* and containing the content of <paramref name="buffer" />.
*/
Span<T> Resize(int minimumLength);
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: Span<T> Resize(int minimumLength, Span<T> buffer = default);
Span<T> Resize(int minimumLength, Span<T> buffer);
}

View File

@@ -1,55 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow;
import static com.google.common.base.Preconditions.checkArgument;
public final class MemorySpanResizer<T> implements ISpanResizer<T> {
private Memory<T> memory;
public MemorySpanResizer() {
this(0);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public MemorySpanResizer(int initialCapacity = 0)
public MemorySpanResizer(int initialCapacity) {
checkArgument(initialCapacity >= 0);
//C# TO JAVA CONVERTER WARNING: Java does not allow direct instantiation of arrays of generic type parameters:
//ORIGINAL LINE: this.memory = initialCapacity == 0 ? default : new Memory<T>(new T[initialCapacity]);
this.memory = initialCapacity == 0 ? null : new Memory<T>((T[])new Object[initialCapacity]);
}
public Memory<T> getMemory() {
return this.memory;
}
/**
* <inheritdoc />
*/
public Span<T> Resize(int minimumLength) {
return Resize(minimumLength, null);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Span<T> Resize(int minimumLength, Span<T> buffer = default)
public Span<T> Resize(int minimumLength, Span<T> buffer) {
if (this.memory.Length < minimumLength) {
//C# TO JAVA CONVERTER WARNING: Java does not allow direct instantiation of arrays of generic type
// parameters:
//ORIGINAL LINE: this.memory = new Memory<T>(new T[Math.Max(minimumLength, buffer.Length)]);
this.memory = new Memory<T>((T[])new Object[Math.max(minimumLength, buffer.Length)]);
}
Span<T> next = this.memory.Span;
if (!buffer.IsEmpty && next.Slice(0, buffer.Length) != buffer) {
buffer.CopyTo(next);
}
return next;
}
}

View File

@@ -35,7 +35,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNull;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutObject;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypeScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTagged;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTagged2;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple;
@@ -754,16 +754,22 @@ public final class RowBuffer {
return item.value();
}
public Utf8String readVariableString(int offset) {
public Utf8String readVariableString(final int offset) {
Item<Utf8String> item = this.read(this::readUtf8String, offset);
return item.value();
}
public long readVariableUInt(int offset) {
public long readVariableUInt(final int offset) {
Item<Long> item = this.read(this::read7BitEncodedUInt, offset);
return item.value();
}
public long readVariableUInt(final int offset, @Nonnull final Out<Integer> length) {
Item<Long> item = this.read(this::read7BitEncodedUInt, offset);
length.set(item.length());
return item.value();
}
/**
* Clears all content from the row. The row is empty after this method.
*/
@@ -905,7 +911,7 @@ public final class RowBuffer {
*/
public RowCursor sparseIteratorReadScope(@Nonnull final RowCursor edit, boolean immutable) {
LayoutScope scopeType = edit.cellType() instanceof LayoutScope ? (LayoutScope) edit.cellType() : null;
LayoutTypeScope scopeType = edit.cellType() instanceof LayoutTypeScope ? (LayoutTypeScope) edit.cellType() : null;
if (scopeType instanceof LayoutObject || scopeType instanceof LayoutArray) {
return new RowCursor()
@@ -1195,6 +1201,7 @@ public final class RowBuffer {
}
public void writeFixedBinary(final int offset, @Nonnull final ByteBuf value, final int length) {
checkNotNull(value, "expected non-null value");
checkArgument(offset >= 0, "expected offset >= 0, not %s", offset);
checkArgument(length >= 0, "expected length >= 0, not %s", length);
@@ -1279,7 +1286,7 @@ public final class RowBuffer {
@Nonnull
public RowCursor writeNullable(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
boolean hasValue) {
@@ -1333,7 +1340,7 @@ public final class RowBuffer {
@Nonnull
public RowCursor writeSparseArray(
@Nonnull final RowCursor edit, @Nonnull final LayoutScope scope, @Nonnull final UpdateOptions options) {
@Nonnull final RowCursor edit, @Nonnull final LayoutTypeScope scope, @Nonnull final UpdateOptions options) {
checkNotNull(edit, "expected non-null edit");
checkNotNull(scope, "expected non-null scope");
@@ -1691,7 +1698,7 @@ public final class RowBuffer {
public RowCursor writeSparseObject(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final UpdateOptions options) {
checkNotNull(edit, "expected non-null edit");
@@ -1749,7 +1756,7 @@ public final class RowBuffer {
@Nonnull
public RowCursor writeSparseTuple(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) {
@@ -1793,7 +1800,7 @@ public final class RowBuffer {
@Nonnull
public RowCursor writeSparseUDT(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final Layout udt,
@Nonnull final UpdateOptions options) {
@@ -2016,7 +2023,7 @@ public final class RowBuffer {
@Nonnull
public RowCursor writeTypedArray(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) {
@@ -2048,7 +2055,7 @@ public final class RowBuffer {
@Nonnull
public RowCursor writeTypedMap(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) {
@@ -2081,7 +2088,7 @@ public final class RowBuffer {
@Nonnull
public RowCursor writeTypedSet(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) {
@@ -2113,7 +2120,7 @@ public final class RowBuffer {
public RowCursor writeTypedTuple(
@Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope,
@Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) {
@@ -2225,6 +2232,12 @@ public final class RowBuffer {
return shift.get();
}
public int writeVariableUInt(final int offset, final long value) {
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
Item<Long> item = this.write(this::write7BitEncodedUInt, offset, value);
return item.length();
}
public int writeVariableUInt(final int offset, final long value, final boolean exists) {
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
@@ -3032,7 +3045,7 @@ public final class RowBuffer {
*/
private int sparseComputeSize(RowCursor edit) {
if (!(edit.cellType() instanceof LayoutScope)) {
if (!(edit.cellType() instanceof LayoutTypeScope)) {
return this.sparseComputePrimitiveSize(edit.cellType(), edit.metaOffset(), edit.valueOffset());
}

View File

@@ -6,7 +6,7 @@ package com.azure.data.cosmos.serialization.hybridrow;
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;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypeScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes;
@@ -30,7 +30,7 @@ public final class RowCursor implements Cloneable {
private int metaOffset;
private int pathOffset;
private int pathToken;
private LayoutScope scopeType;
private LayoutTypeScope scopeType;
private TypeArgumentList scopeTypeArgs;
private int start;
private int valueOffset;
@@ -228,11 +228,11 @@ public final class RowCursor implements Cloneable {
/**
* The kind of scope within which this edit was prepared
*/
public LayoutScope scopeType() {
public LayoutTypeScope scopeType() {
return this.scopeType;
}
public RowCursor scopeType(LayoutScope scopeType) {
public RowCursor scopeType(LayoutTypeScope scopeType) {
this.scopeType = scopeType;
return this;
}

View File

@@ -13,8 +13,8 @@ import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
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;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanReadable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8SpanReadable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
@@ -1049,7 +1049,7 @@ public final class RowReader {
LayoutColumn column = this.columns.get(this.columnIndex);
LayoutType type = this.columns.get(this.columnIndex).type();
if (!(type instanceof ILayoutUtf8SpanReadable)) {
if (!(type instanceof LayoutUtf8SpanReadable)) {
value.set(null);
return Result.TYPE_MISMATCH;
}
@@ -1059,10 +1059,10 @@ public final class RowReader {
switch (storage) {
case FIXED:
return type.<ILayoutUtf8SpanReadable>typeAs().readFixed(this.row, this.cursor, column, value);
return type.<LayoutUtf8SpanReadable>typeAs().readFixed(this.row, this.cursor, column, value);
case VARIABLE:
return type.<ILayoutUtf8SpanReadable>typeAs().readVariable(this.row, this.cursor, column, value);
return type.<LayoutUtf8SpanReadable>typeAs().readVariable(this.row, this.cursor, column, value);
default:
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
@@ -1083,7 +1083,7 @@ public final class RowReader {
LayoutColumn column = this.columns.get(this.columnIndex);
LayoutType type = this.columns.get(this.columnIndex).type();
if (!(type instanceof ILayoutSpanReadable<?>)) {
if (!(type instanceof LayoutSpanReadable<?>)) {
value.set(null);
return Result.TYPE_MISMATCH;
}
@@ -1093,10 +1093,10 @@ public final class RowReader {
switch (storage) {
case FIXED:
return type.<ILayoutSpanReadable<TElement>>typeAs().readFixed(this.row, this.cursor, column, value);
return type.<LayoutSpanReadable<TElement>>typeAs().readFixed(this.row, this.cursor, column, value);
case VARIABLE:
return type.<ILayoutSpanReadable<TElement>>typeAs().readVariable(this.row, this.cursor, column, value);
return type.<LayoutSpanReadable<TElement>>typeAs().readVariable(this.row, this.cursor, column, value);
default:
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);

View File

@@ -31,7 +31,7 @@ public final class RowWriter {
private RowBuffer row;
/**
* Initializes a new instance of the {@link RowWriter} struct
* Initializes a new instance of the {@link RowWriter} class
*
* @param row The row to be read.
* @param scope The scope into which items should be written.
@@ -73,13 +73,6 @@ public final class RowWriter {
* @return Success if the write is successful, an error code otherwise.
*/
public Result WriteBinary(UtfAnyString path, byte[] value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, byte[] v) => w
// .row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutTypes.BINARY,
(ref RowWriter w, byte[] v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT));
}
@@ -91,16 +84,7 @@ public final class RowWriter {
* @param value The value to write.
* @return Success if the write is successful, an error code otherwise.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteBinary(UtfAnyString path, ReadOnlySpan<byte> value)
public Result WriteBinary(UtfAnyString path, ReadOnlySpan<Byte> value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w,
// ReadOnlySpan<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary,
(ref RowWriter w, ReadOnlySpan<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT));
}
@@ -112,34 +96,21 @@ public final class RowWriter {
* @param value The value to write.
* @return Success if the write is successful, an error code otherwise.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteBinary(UtfAnyString path, ReadOnlySequence<byte> value)
public Result WriteBinary(UtfAnyString path, ReadOnlySequence<Byte> value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w,
// ReadOnlySequence<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary,
(ref RowWriter w, ReadOnlySequence<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v,
UpdateOptions.UPSERT));
}
/**
* Write a field as a {@link bool}.
* Write a field as a {@link Boolean}.
*
* @param path The scope-relative path of the field to write.
* @param value The value to write.
* @return Success if the write is successful, an error code otherwise.
*/
public Result WriteBool(UtfAnyString path, boolean value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
return this.WritePrimitive(path, value, LayoutType.Boolean,
public Result WriteBoolean(UtfAnyString path, boolean value) {
return this.WritePrimitive(path, value, LayoutTypes.BOOLEAN,
(ref RowWriter w, boolean v) -> w.row.WriteSparseBool(ref w.cursor, v, UpdateOptions.UPSERT));
}
@@ -152,8 +123,8 @@ public final class RowWriter {
* @param func A function to write the entire row.
* @return Success if the write is successful, an error code otherwise.
*/
public static <TContext> Result WriteBuffer(Reference<RowBuffer> row, TContext context,
WriterFunc<TContext> func) {
public static <TContext> Result WriteBuffer(
Reference<RowBuffer> row, TContext context, WriterFunc<TContext> func) {
RowCursor scope = RowCursor.create(row);
Reference<RowCursor> tempReference_scope =
new Reference<RowCursor>(scope);

View File

@@ -3,26 +3,37 @@
package com.azure.data.cosmos.serialization.hybridrow.json;
import com.azure.data.cosmos.core.Json;
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.Float128;
import com.azure.data.cosmos.serialization.hybridrow.NullValue;
import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nonnull;
import java.math.BigDecimal;
import java.time.OffsetDateTime;
import java.util.Objects;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.lenientFormat;
public final class RowReaderJsonExtensions {
/**
* Project a JSON document from a HybridRow {@link RowReader}.
*
* @param reader The reader to project to JSON.
* @param str If successful, the JSON document that corresponds to the <paramref name="reader"/>.
* @param string If {@link Result#SUCCESS}, the JSON document that corresponds to the {@code reader).
* @return The result.
*/
public static Result ToJson(Reference<RowReader> reader, Out<String> str) {
return RowReaderJsonExtensions.ToJson(reader.get().clone(), new RowReaderJsonSettings(" "), str);
@Nonnull
public static Result toJson(@Nonnull final RowReader reader, @Nonnull final Out<String> string) {
return RowReaderJsonExtensions.toJson(reader, new RowReaderJsonSettings(" "), string);
}
/**
@@ -30,421 +41,333 @@ public final class RowReaderJsonExtensions {
*
* @param reader The reader to project to JSON.
* @param settings Settings that control how the JSON document is formatted.
* @param str If successful, the JSON document that corresponds to the <paramref name="reader"/>.
* @param string If {@link Result#SUCCESS}, the JSON document that corresponds to the {@code reader).
* @return The result.
*/
public static Result ToJson(Reference<RowReader> reader, RowReaderJsonSettings settings,
Out<String> str) {
ReaderStringContext ctx = new ReaderStringContext(new StringBuilder(),
new RowReaderJsonSettings(settings.IndentChars, settings.QuoteChar == '\'' ? '\'' : '"'), 1);
@Nonnull
public static Result toJson(
@Nonnull final RowReader reader,
@Nonnull final RowReaderJsonSettings settings,
@Nonnull final Out<String> string) {
final ReaderStringContext context = new ReaderStringContext(
new StringBuilder(),
new RowReaderJsonSettings(
settings.indentChars(),
settings.quoteChar() == '\'' ? '\'' : '"'),
1);
context.builder().append("{");
Result result = RowReaderJsonExtensions.toJson(reader, context);
ctx.Builder.append("{");
Result result = RowReaderJsonExtensions.ToJson(reader, ctx.clone());
if (result != Result.SUCCESS) {
str.setAndGet(null);
string.set(null);
return result;
}
ctx.Builder.append(ctx.NewLine);
ctx.Builder.append("}");
str.setAndGet(ctx.Builder.toString());
context.builder().append(context.newline());
context.builder().append("}");
string.set(context.builder().toString());
return Result.SUCCESS;
}
private static Result ToJson(Reference<RowReader> reader, ReaderStringContext ctx) {
@Nonnull
private static Result toJson(@Nonnull final RowReader reader, @Nonnull final ReaderStringContext context) {
int index = 0;
while (reader.get().read()) {
String path = !reader.get().path().IsNull ? String.format("%1$s%2$s%3$s:", ctx.Settings.QuoteChar,
reader.get().path(), ctx.Settings.QuoteChar) : null;
while (reader.read()) {
String path = !reader.path().isNull()
? lenientFormat("%s%s%s:", context.settings().quoteChar(), reader.path(), context.settings().quoteChar())
: null;
if (index != 0) {
ctx.Builder.append(',');
context.builder().append(',');
}
index++;
ctx.Builder.append(ctx.NewLine);
ctx.WriteIndent();
context.builder().append(context.newline());
context.writeIndent();
if (path != null) {
ctx.Builder.append(path);
ctx.Builder.append(ctx.Separator);
context.builder().append(path);
context.builder().append(context.separator());
}
Result r;
final Out out = new Out<>();
Result result;
char scopeBracket = '\0';
char scopeCloseBracket = '\0';
switch (reader.get().type().LayoutCode) {
case Null: {
NullValue _;
Out<NullValue> tempOut__ =
new Out<NullValue>();
r = reader.get().readNull(tempOut__);
_ = tempOut__.get();
if (r != Result.SUCCESS) {
return r;
}
ctx.Builder.append("null");
switch (Objects.requireNonNull(reader.type()).layoutCode()) {
case NULL: {
result = reader.readNull(out);
if (result != Result.SUCCESS) {
return result;
}
context.builder().append("null");
break;
}
case Boolean: {
boolean value;
Out<Boolean> tempOut_value = new Out<Boolean>();
r = reader.get().readBoolean(tempOut_value);
value = tempOut_value.get();
if (r != Result.SUCCESS) {
return r;
case BOOLEAN: {
result = reader.readBoolean(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case Int8: {
byte value;
Out<Byte> tempOut_value2 = new Out<Byte>();
r = reader.get().readInt8(tempOut_value2);
value = tempOut_value2.get();
if (r != Result.SUCCESS) {
return r;
case INT_8: {
result = reader.readInt8(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case Int16: {
short value;
Out<Short> tempOut_value3 = new Out<Short>();
r = reader.get().readInt16(tempOut_value3);
value = tempOut_value3.get();
if (r != Result.SUCCESS) {
return r;
case INT_16: {
result = reader.readInt16(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case Int32: {
int value;
Out<Integer> tempOut_value4 = new Out<Integer>();
r = reader.get().readInt32(tempOut_value4);
value = tempOut_value4.get();
if (r != Result.SUCCESS) {
return r;
case INT_32: {
result = reader.readInt32(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case Int64: {
long value;
Out<Long> tempOut_value5 = new Out<Long>();
r = reader.get().readInt64(tempOut_value5);
value = tempOut_value5.get();
if (r != Result.SUCCESS) {
return r;
case INT_64: {
result = reader.readInt64(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case UInt8: {
byte value;
Out<Byte> tempOut_value6 = new Out<Byte>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt8(out byte value);
r = reader.get().readUInt8(tempOut_value6);
value = tempOut_value6.get();
if (r != Result.SUCCESS) {
return r;
case UINT_8: {
result = reader.readUInt8(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case UInt16: {
short value;
Out<Short> tempOut_value7 = new Out<Short>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt16(out ushort value);
r = reader.get().readUInt16(tempOut_value7);
value = tempOut_value7.get();
if (r != Result.SUCCESS) {
return r;
case UINT_16: {
result = reader.readUInt16(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case UInt32: {
int value;
Out<Integer> tempOut_value8 = new Out<Integer>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt32(out uint value);
r = reader.get().readUInt32(tempOut_value8);
value = tempOut_value8.get();
if (r != Result.SUCCESS) {
return r;
case UINT_32: {
result = reader.readUInt32(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case UInt64: {
long value;
Out<Long> tempOut_value9 = new Out<Long>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt64(out ulong value);
r = reader.get().readUInt64(tempOut_value9);
value = tempOut_value9.get();
if (r != Result.SUCCESS) {
return r;
case UINT_64: {
result = reader.readUInt64(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case VarInt: {
long value;
Out<Long> tempOut_value10 = new Out<Long>();
r = reader.get().readVarInt(tempOut_value10);
value = tempOut_value10.get();
if (r != Result.SUCCESS) {
return r;
case VAR_INT: {
result = reader.readVarInt(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case VarUInt: {
long value;
Out<Long> tempOut_value11 = new Out<Long>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadVarUInt(out ulong value);
r = reader.get().readVarUInt(tempOut_value11);
value = tempOut_value11.get();
if (r != Result.SUCCESS) {
return r;
case VAR_UINT: {
result = reader.readVarUInt(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case Float32: {
float value;
Out<Float> tempOut_value12 = new Out<Float>();
r = reader.get().readFloat32(tempOut_value12);
value = tempOut_value12.get();
if (r != Result.SUCCESS) {
return r;
case FLOAT_32: {
result = reader.readFloat32(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case Float64: {
double value;
Out<Double> tempOut_value13 = new Out<Double>();
r = reader.get().readFloat64(tempOut_value13);
value = tempOut_value13.get();
if (r != Result.SUCCESS) {
return r;
case FLOAT_64: {
result = reader.readFloat64(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(out.get());
break;
}
case Float128: {
Float128 _;
Out<Float128> tempOut__2 =
new Out<Float128>();
r = reader.get().readFloat128(tempOut__2);
_ = tempOut__2.get();
if (r != Result.SUCCESS) {
return r;
case FLOAT_128: {
result = reader.readFloat128(out);
if (result != Result.SUCCESS) {
return result;
}
// context.Builder.AppendFormat("High: {0}, Low: {1}\n", value.High, value.Low);
throw new UnsupportedOperationException("Float128 values are not supported.");
}
// ctx.Builder.AppendFormat("High: {0}, Low: {1}\n", value.High, value.Low);
checkState(false, "Float128 are not supported.");
case DECIMAL: {
result = reader.readDecimal(out);
if (result != Result.SUCCESS) {
return result;
}
context.builder().append(out.get());
break;
}
case Decimal: {
java.math.BigDecimal value;
Out<BigDecimal> tempOut_value14 = new Out<BigDecimal>();
r = reader.get().readDecimal(tempOut_value14);
value = tempOut_value14.get();
if (r != Result.SUCCESS) {
return r;
case DATE_TIME: {
result = reader.readDateTime(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value);
context.builder().append(context.settings().quoteChar());
context.builder().append(out.get());
context.builder().append(context.settings().quoteChar());
break;
}
case DateTime: {
java.time.LocalDateTime value;
Out<LocalDateTime> tempOut_value15 = new Out<LocalDateTime>();
r = reader.get().readDateTime(tempOut_value15);
value = tempOut_value15.get();
if (r != Result.SUCCESS) {
return r;
case UNIX_DATE_TIME: {
result = reader.readUnixDateTime(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value);
ctx.Builder.append(ctx.Settings.QuoteChar);
context.builder().append(((UnixDateTime)out.get()).milliseconds());
break;
}
case UnixDateTime: {
UnixDateTime value;
Out<UnixDateTime> tempOut_value16 =
new Out<UnixDateTime>();
r = reader.get().readUnixDateTime(tempOut_value16);
value = tempOut_value16.get();
if (r != Result.SUCCESS) {
return r;
case GUID: {
result = reader.readGuid(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(value.Milliseconds);
context.builder().append(context.settings().quoteChar());
context.builder().append(out.get());
context.builder().append(context.settings().quoteChar());
break;
}
case Guid: {
java.util.UUID value;
Out<UUID> tempOut_value17 = new Out<UUID>();
r = reader.get().readGuid(tempOut_value17);
value = tempOut_value17.get();
if (r != Result.SUCCESS) {
return r;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value.toString());
ctx.Builder.append(ctx.Settings.QuoteChar);
case MONGODB_OBJECT_ID: {
// TODO: DANOBLE: Resurrect this code block
// MongoDbObjectId value;
// Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId> tempOut_value18 =
// new Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId>();
// result = reader.ReadMongoDbObjectId(tempOut_value18);
// value = tempOut_value18.get();
// if (result != Result.SUCCESS) {
// return result;
// }
//
// context.builder().append(context.settings().quoteChar());
// //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
// //ORIGINAL LINE: ReadOnlyMemory<byte> bytes = value.ToByteArray();
// ReadOnlyMemory<Byte> bytes = value.ToByteArray();
// context.builder().append(bytes.Span.ToHexString());
// context.builder().append(context.settings().quoteChar());
break;
}
case MongoDbObjectId: {
MongoDbObjectId value;
Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId> tempOut_value18 = new Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId>();
r = reader.get().ReadMongoDbObjectId(tempOut_value18);
value = tempOut_value18.get();
if (r != Result.SUCCESS) {
return r;
case UTF_8: {
result = reader.readString(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ReadOnlyMemory<byte> bytes = value.ToByteArray();
ReadOnlyMemory<Byte> bytes = value.ToByteArray();
ctx.Builder.append(bytes.Span.ToHexString());
ctx.Builder.append(ctx.Settings.QuoteChar);
context.builder().append(context.settings().quoteChar());
context.builder().append(Json.toString(out));
context.builder().append(context.settings().quoteChar());
break;
}
case Utf8: {
Utf8Span value;
// 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:
r = reader.get().ReadString(out value);
if (r != Result.SUCCESS) {
return r;
case BINARY: {
result = reader.readBinary(out);
if (result != Result.SUCCESS) {
return result;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value.toString());
ctx.Builder.append(ctx.Settings.QuoteChar);
context.builder().append(context.settings().quoteChar());
context.builder().append(out.get());
context.builder().append(context.settings().quoteChar());
break;
}
case Binary: {
ReadOnlySpan<Byte> value;
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadBinary(out ReadOnlySpan<byte> value);
r = reader.get().ReadBinary(out value);
if (r != Result.SUCCESS) {
return r;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value.ToHexString());
ctx.Builder.append(ctx.Settings.QuoteChar);
break;
}
case NullableScope:
case ImmutableNullableScope: {
if (!reader.get().hasValue()) {
ctx.Builder.append("null");
case NULLABLE_SCOPE:
case IMMUTABLE_NULLABLE_SCOPE:
if (!reader.hasValue()) {
context.builder().append("null");
break;
}
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
// goto case LayoutCode.TypedTupleScope;
}
case ArrayScope:
case ImmutableArrayScope:
case TypedArrayScope:
case ImmutableTypedArrayScope:
case TypedSetScope:
case ImmutableTypedSetScope:
case TypedMapScope:
case ImmutableTypedMapScope:
case TupleScope:
case ImmutableTupleScope:
case TypedTupleScope:
case ImmutableTypedTupleScope:
case TaggedScope:
case ImmutableTaggedScope:
case Tagged2Scope:
case ImmutableTagged2Scope:
scopeBracket = '[';
scopeCloseBracket = ']';
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
// goto case LayoutCode.EndScope;
case ObjectScope:
case ImmutableObjectScope:
case Schema:
case ImmutableSchema:
scopeBracket = '{';
scopeCloseBracket = '}';
case EndScope: {
ctx.Builder.append(scopeBracket);
int snapshot = ctx.Builder.length();
r = reader.get().readScope(new ReaderStringContext(ctx.Builder, ctx.Settings.clone(), ctx.Indent + 1), RowReaderJsonExtensions.ToJson);
if (r != Result.SUCCESS) {
return r;
case ARRAY_SCOPE:
case IMMUTABLE_ARRAY_SCOPE:
case TYPED_ARRAY_SCOPE:
case IMMUTABLE_TYPED_ARRAY_SCOPE:
case TYPED_SET_SCOPE:
case IMMUTABLE_TYPED_SET_SCOPE:
case TYPED_MAP_SCOPE:
case IMMUTABLE_TYPED_MAP_SCOPE:
case TUPLE_SCOPE:
case IMMUTABLE_TUPLE_SCOPE:
case TYPED_TUPLE_SCOPE:
case IMMUTABLE_TYPED_TUPLE_SCOPE:
case TAGGED_SCOPE:
case IMMUTABLE_TAGGED_SCOPE:
case TAGGED2_SCOPE:
case IMMUTABLE_TAGGED2_SCOPE:
result = endScope(reader, context, scopeBracket = '[', scopeCloseBracket = ']');
if (result != Result.SUCCESS) {
return result;
}
if (ctx.Builder.length() != snapshot) {
ctx.Builder.append(ctx.NewLine);
ctx.WriteIndent();
break;
case OBJECT_SCOPE:
case IMMUTABLE_OBJECT_SCOPE:
case SCHEMA:
case IMMUTABLE_SCHEMA:
result = endScope(reader, context, scopeBracket = '{', scopeCloseBracket = '}');
if (result != Result.SUCCESS) {
return result;
}
break;
ctx.Builder.append(scopeCloseBracket);
case END_SCOPE: {
result = endScope(reader, context, scopeBracket, scopeCloseBracket);
if (result != Result.SUCCESS) {
return result;
}
break;
}
default: {
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", reader.get().type().LayoutCode));
break;
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s",
Objects.requireNonNull(reader.type()).layoutCode())
);
}
}
}
@@ -452,44 +375,75 @@ public final class RowReaderJsonExtensions {
return Result.SUCCESS;
}
//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: private readonly struct ReaderStringContext
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
private final static class ReaderStringContext {
public StringBuilder Builder;
public int Indent;
public String NewLine;
public String Separator;
public RowReaderJsonSettings Settings = new RowReaderJsonSettings();
@NonNull
private static Result endScope(
@Nonnull RowReader reader, @Nonnull ReaderStringContext context, char scopeBracket, char scopeCloseBracket) {
public ReaderStringContext() {
Result result;
context.builder().append(scopeBracket);
int snapshot = context.builder().length();
result = reader.readScope(
new ReaderStringContext(
context.builder(),
context.settings(),
context.indent() + 1),
RowReaderJsonExtensions::toJson);
if (result != Result.SUCCESS) {
return result;
}
if (context.builder().length() != snapshot) {
context.builder().append(context.newline());
context.writeIndent();
}
context.builder().append(scopeCloseBracket);
return result;
}
private final static class ReaderStringContext {
private StringBuilder builder;
private int indent;
private String newline;
private String separator;
private RowReaderJsonSettings settings = new RowReaderJsonSettings();
public ReaderStringContext(StringBuilder builder, RowReaderJsonSettings settings, int indent) {
this.Settings = settings.clone();
this.Separator = settings.IndentChars == null ? "" : " ";
this.NewLine = settings.IndentChars == null ? "" : "\n";
this.Indent = indent;
this.Builder = builder;
this.settings = settings;
this.separator = settings.indentChars() == null ? "" : " ";
this.newline = settings.indentChars() == null ? "" : "\n";
this.indent = indent;
this.builder = builder;
}
public void WriteIndent() {
String indentChars = this.Settings.IndentChars != null ? this.Settings.IndentChars : "";
for (int i = 0; i < this.Indent; i++) {
this.Builder.append(indentChars);
public StringBuilder builder() {
return this.builder;
}
public int indent() {
return this.indent;
}
public String newline() {
return this.newline;
}
public String separator() {
return this.separator;
}
public RowReaderJsonSettings settings() {
return this.settings;
}
public void writeIndent() {
String indentChars = this.settings().indentChars() != null ? this.settings().indentChars() : "";
for (int i = 0; i < this.indent(); i++) {
this.builder().append(indentChars);
}
}
public ReaderStringContext clone() {
ReaderStringContext varCopy = new ReaderStringContext();
varCopy.Indent = this.Indent;
varCopy.Builder = this.Builder;
varCopy.Settings = this.Settings.clone();
varCopy.Separator = this.Separator;
varCopy.NewLine = this.NewLine;
return varCopy;
}
}
}

View File

@@ -3,25 +3,10 @@
package com.azure.data.cosmos.serialization.hybridrow.json;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1051 // Do not declare visible instance fields
//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: public readonly struct RowReaderJsonSettings
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class RowReaderJsonSettings {
/**
* If non-null then child objects are indented by one copy of this string per level.
*/
public String IndentChars;
private String indentChars;
/**
* The quote character to use.
* May be <see cref="lang:\""/> or {@link '}.
*/
public char QuoteChar;
private char quoteChar;
public RowReaderJsonSettings(String indentChars) {
@@ -32,19 +17,23 @@ public final class RowReaderJsonSettings {
this(" ", '"');
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public RowReaderJsonSettings(string indentChars = " ", char quoteChar = '"')
public RowReaderJsonSettings(String indentChars, char quoteChar) {
this.IndentChars = indentChars;
this.QuoteChar = quoteChar;
this.indentChars = indentChars;
this.quoteChar = quoteChar;
}
public RowReaderJsonSettings clone() {
RowReaderJsonSettings varCopy = new RowReaderJsonSettings();
/**
* If non-null then child objects are indented by one copy of this string per level.
*/
public String indentChars() {
return this.indentChars;
}
varCopy.IndentChars = this.IndentChars;
varCopy.QuoteChar = this.QuoteChar;
return varCopy;
/**
* The quote character to use.
* May be <see cref="lang:\""/> or {@link '}.
*/
public char quoteChar() {
return this.quoteChar;
}
}

View File

@@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
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 java.util.List;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also write using a read-only {@link List{T}}.
*
* @param <TElement> The sub-element type to be written
*/
public interface ILayoutSequenceWritable<TElement> extends ILayoutType {
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn col, List<TElement> value);
Result writeSparse(RowBuffer buffer, RowCursor edit, List<TElement> value);
Result writeSparse(RowBuffer buffer, RowCursor edit, List<TElement> value, UpdateOptions options);
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
}

View File

@@ -37,7 +37,7 @@ public final class LayoutArray extends LayoutIndexedScope {
@Override
@Nonnull
public Result writeScope(
RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull UpdateOptions options, @Nonnull Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);

View File

@@ -7,13 +7,20 @@ import com.azure.data.cosmos.core.Out;
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import javax.annotation.Nonnull;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpanWritable<Byte>, ILayoutSpanReadable<Byte>, ILayoutSequenceWritable<Byte> {
public final class LayoutBinary extends LayoutTypePrimitive<byte[]> {
// implements
// LayoutSpanWritable<Byte>,
// LayoutSpanReadable<Byte>,
// ILayoutSequenceWritable<Byte> {
public LayoutBinary() {
super(LayoutCode.BINARY, 0);
@@ -23,10 +30,6 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return false;
}
public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence<Byte> value) {
return writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Nonnull
public String name() {
return "binary";
@@ -34,19 +37,16 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<byte[]> value) {
ReadOnlySpan<Byte> span;
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result result = this.ReadFixed(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result result = this.ReadFixed(buffer, scope, column, out span);
value.set((result == Result.SUCCESS) ? span.ToArray() :)
default
return result;
}
public Result readFixed(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<byte[]> value) {
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<ReadOnlySpan<Byte>> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkNotNull(value, "expected non-null value");
checkArgument(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0);
@@ -56,143 +56,98 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.NOT_FOUND;
}
value.set(buffer.readFixedBinary(scope.start() + column.offset(), column.size()));
value.set(ByteBufUtil.getBytes(buffer.readFixedBinary(scope.start() + column.offset(), column.size())));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ReadOnlySpan<byte> value)
public Result ReadSparse(RowBuffer buffer, RowCursor edit, Out<ReadOnlySpan<Byte>> value) {
@Override
@Nonnull
public Result readSparse(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull final Out<byte[]> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(value, "expected non-null value");
final Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.set(null);
return result;
}
value.set(buffer.readSparseBinary(edit));
value.set(ByteBufUtil.getBytes(buffer.readSparseBinary(edit)));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out byte[] value)
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<byte[]> value) {
ReadOnlySpan<Byte> span;
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadSparse(ref b, ref edit, out ReadOnlySpan<byte> span);
Result r = this.ReadSparse(buffer, edit, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :)
default
return r;
}
public Result readVariable(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor scope,
@Nonnull LayoutColumn column,
@Nonnull Out<byte[]> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkNotNull(value, "expected non-null value");
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result ReadVariable(ref RowBuffer buffer, ref RowCursor scope, LayoutColumn column, out
// ReadOnlySpan<byte> value)
public Result ReadVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<ReadOnlySpan<Byte>> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(null);
return Result.NOT_FOUND;
}
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
value.set(buffer.readVariableBinary(varOffset));
final int valueOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
value.set(ByteBufUtil.getBytes(buffer.readVariableBinary(valueOffset)));
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// byte[] value)
@Override
@Nonnull
public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<byte[]> value) {
ReadOnlySpan<Byte> span;
// 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:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadVariable(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result r = this.ReadVariable(buffer, scope, column, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :)
default
return r;
}
public Result writeFixed(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor scope,
@Nonnull LayoutColumn column,
@Nonnull byte[] value) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// ReadOnlySpan<byte> value)
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<Byte> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkNotNull(value, "expected non-null value");
checkArgument(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0);
checkArgument(value.Length == column.size());
checkArgument(value.length == column.size());
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
buffer.writeFixedBinary(scope.start() + column.offset(), value, column.size());
final ByteBuf valueBuffer = Unpooled.wrappedBuffer(value).asReadOnly();
final int valueOffset = scope.start() + column.offset();
buffer.setBit(scope.start(), column.nullBit());
buffer.writeFixedBinary(valueOffset, valueBuffer, column.size());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteFixed(ref RowBuffer buffer, ref RowCursor scope, LayoutColumn col,
// ReadOnlySequence<byte> value)
public Result WriteFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, ReadOnlySequence<Byte> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0);
checkArgument(value.Length == column.size());
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
buffer.writeFixedBinary(scope.start() + column.offset(), value, column.size());
buffer.setBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, byte[]
// value)
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) {
checkArgument(value != null);
return this.writeFixed(buffer, scope, column, new ReadOnlySpan<Byte>(value));
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull byte[] value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, byte[] value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value,
UpdateOptions options) {
checkArgument(value != null);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WriteSparse(ref b, ref edit, new ReadOnlySpan<byte>(value), options);
return this.WriteSparse(buffer, edit, new ReadOnlySpan<Byte>(value), options);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ReadOnlySpan<byte> value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public Result writeSparse(RowBuffer buffer, RowCursor edit, List<Byte> value, UpdateOptions options) {
public Result writeSparse(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull byte[] value,
@Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -200,39 +155,17 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return result;
}
buffer.writeSparseBinary(edit, value, options);
return Result.SUCCESS;
}
public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) {
return writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence<Byte> value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
buffer.writeSparseBinary(edit, value, options);
buffer.writeSparseBinary(edit, Unpooled.wrappedBuffer(value).asReadOnly(), options);
return Result.SUCCESS;
}
@Override
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) {
checkArgument(value != null);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WriteVariable(ref b, ref scope, col, new ReadOnlySpan<byte>(value));
return this.writeVariable(buffer, scope, column, new ReadOnlySpan<Byte>(value));
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// ReadOnlySpan<byte> value)
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<Byte> value) {
public Result writeVariable(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor scope,
@Nonnull LayoutColumn column,
@Nonnull byte[] value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -240,49 +173,20 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.INSUFFICIENT_PERMISSIONS;
}
int length = value.Length;
if ((column.size() > 0) && (length > column.size())) {
if ((column.size() > 0) && (value.length > column.size())) {
return Result.TOO_BIG;
}
boolean exists = buffer.readBit(scope.start(), column.nullBit());
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(),
column.offset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
buffer.writeVariableBinary(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
final boolean exists = buffer.readBit(scope.start(), column.nullBit());
final ByteBuf valueBuffer = Unpooled.wrappedBuffer(value).asReadOnly();
final int valueOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
final Out<Integer> shift = new Out<>();
buffer.writeVariableBinary(valueOffset, valueBuffer, exists, shift);
buffer.setBit(scope.start(), column.nullBit());
scope.metaOffset(scope.metaOffset() + shift);
scope.valueOffset(scope.valueOffset() + shift);
return Result.SUCCESS;
}
scope.metaOffset(scope.metaOffset() + shift.get());
scope.valueOffset(scope.valueOffset() + shift.get());
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteVariable(ref RowBuffer buffer, ref RowCursor scope, LayoutColumn column,
// ReadOnlySequence<byte> value)
public Result WriteVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, ReadOnlySequence<Byte> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
int length = (int)value.Length;
if ((column.size() > 0) && (length > column.size())) {
return Result.TOO_BIG;
}
boolean exists = buffer.readBit(scope.start(), column.nullBit());
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(),
column.offset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
buffer.writeVariableBinary(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift;
buffer.setBit(scope.start(), column.nullBit());
scope.metaOffset(scope.metaOffset() + shift);
scope.valueOffset(scope.valueOffset() + shift);
return Result.SUCCESS;
}
}

View File

@@ -14,7 +14,7 @@ import java.time.OffsetDateTime;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
public final class LayoutDateTime extends LayoutTypePrimitive<OffsetDateTime> {
public LayoutDateTime() {
super(LayoutCode.DATE_TIME, DateTimeCodec.BYTES);
@@ -31,7 +31,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<OffsetDateTime> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<OffsetDateTime> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -46,7 +46,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<OffsetDateTime> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<OffsetDateTime> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -61,7 +61,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, OffsetDateTime value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull OffsetDateTime value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -76,7 +76,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, OffsetDateTime value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull OffsetDateTime value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -90,7 +90,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, OffsetDateTime value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull OffsetDateTime value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -14,7 +14,7 @@ import java.math.BigDecimal;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutDecimal extends LayoutType<BigDecimal> {
public final class LayoutDecimal extends LayoutTypePrimitive<BigDecimal> {
public LayoutDecimal() {
super(LayoutCode.DECIMAL, DecimalCodec.BYTES);
@@ -31,7 +31,7 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<BigDecimal> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<BigDecimal> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -46,8 +46,8 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<BigDecimal> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit,
@Nonnull Out<BigDecimal> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(new BigDecimal(0));
@@ -60,8 +60,8 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
BigDecimal value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column,
@Nonnull BigDecimal value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
@@ -74,7 +74,7 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, BigDecimal value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull BigDecimal value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
@@ -86,7 +86,7 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, BigDecimal value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull BigDecimal value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
public final class LayoutEndScope extends LayoutScope {
public final class LayoutEndScope extends LayoutTypeScope {
public LayoutEndScope() {
super(LayoutCode.END_SCOPE, false, false, false, false, false, false);

View File

@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat128 extends LayoutType<Float128> {
public final class LayoutFloat128 extends LayoutTypePrimitive<Float128> {
public LayoutFloat128() {
super(LayoutCode.FLOAT_128, Float128.BYTES);
@@ -30,7 +30,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Float128> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Float128> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -45,7 +45,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Float128> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Float128> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -60,7 +60,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Float128 value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Float128 value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float128 value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float128 value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -89,7 +89,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float128 value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float128 value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat32 extends LayoutType<Float> {
public final class LayoutFloat32 extends LayoutTypePrimitive<Float> {
public LayoutFloat32() {
super(LayoutCode.FLOAT_32, Float.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Float> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Float> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Float> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Float> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Float value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Float value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Float value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat64 extends LayoutType<Double> {
public final class LayoutFloat64 extends LayoutTypePrimitive<Double> {
public LayoutFloat64() {
super(LayoutCode.FLOAT_64, Double.BYTES / Byte.SIZE);
@@ -29,7 +29,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Double> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Double> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Double> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Double> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn col, Double value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn col, @Nonnull Double value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -77,7 +77,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
// UpdateOptions options = UpdateOptions.Upsert)
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Double value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Double value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -91,7 +91,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Double value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Double value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -14,7 +14,7 @@ import java.util.UUID;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutGuid extends LayoutType<UUID> {
public final class LayoutGuid extends LayoutTypePrimitive<UUID> {
public LayoutGuid() {
super(LayoutCode.GUID, GuidCodec.BYTES);
@@ -31,7 +31,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<UUID> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<UUID> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -46,7 +46,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<UUID> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<UUID> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -61,7 +61,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, UUID value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull UUID value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -76,7 +76,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UUID value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UUID value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -90,7 +90,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UUID value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UUID value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -8,17 +8,24 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
public abstract class LayoutIndexedScope extends LayoutScope {
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class LayoutIndexedScope extends LayoutTypeScope {
protected LayoutIndexedScope(
@Nonnull final LayoutCode code, final boolean immutable, final boolean isSizedScope, final boolean isFixedArity,
final boolean isUniqueScope, final boolean isTypedScope) {
@Nonnull final LayoutCode code,
final boolean immutable,
final boolean isSizedScope,
final boolean isFixedArity,
final boolean isUniqueScope,
final boolean isTypedScope) {
super(code, immutable, isSizedScope, true, isFixedArity, isUniqueScope, isTypedScope);
}
@Override
public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
edit.pathToken(0);
edit.pathOffset(0);
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt16 extends LayoutType<Short> {
public final class LayoutInt16 extends LayoutTypePrimitive<Short> {
public LayoutInt16() {
super(LayoutCode.INT_16, Short.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Short> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Short> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Short> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Short> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Short value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Short value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt32 extends LayoutType<Integer> {
public final class LayoutInt32 extends LayoutTypePrimitive<Integer> {
public LayoutInt32() {
super(LayoutCode.INT_32, Integer.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Integer> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Integer> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Integer> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Integer> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Integer value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Integer value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt64 extends LayoutType<Long> {
public final class LayoutInt64 extends LayoutTypePrimitive<Long> {
public LayoutInt64() {
super(LayoutCode.INT_64, Long.BYTES / Byte.SIZE);
@@ -29,7 +29,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
@@ -87,7 +87,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt8 extends LayoutType<Byte> {
public final class LayoutInt8 extends LayoutTypePrimitive<Byte> {
public LayoutInt8() {
super(LayoutCode.INT_8, Byte.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Byte> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Byte> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Byte> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Byte> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Byte value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Byte value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Byte value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Byte value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,83 +12,84 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
public final class LayoutMongoDbObjectId extends LayoutType/*<MongoDbObjectId>*/ {
public LayoutMongoDbObjectId() {
super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.MONGODB_OBJECT_ID, azure.data.cosmos.serialization.hybridrow.MongoDbObjectId.Size);
super(LayoutCode.MONGODB_OBJECT_ID, 0/*MongoDbObjectId.Size*/);
}
public boolean isFixed() {
return true;
}
// ReSharper disable once StringLiteralTypo
@Nonnull
public String name() {
return "mongodbobjectid";
}
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
Out<MongoDbObjectId> value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
value.setAndGet(null);
return Result.NOT_FOUND;
}
value.setAndGet(buffer.get().ReadMongoDbObjectId(scope.get().start() + column.getOffset()).clone());
return Result.SUCCESS;
}
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit,
Out<MongoDbObjectId> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.setAndGet(null);
return result;
}
value.setAndGet(buffer.get().ReadSparseMongoDbObjectId(edit).clone());
return Result.SUCCESS;
}
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
MongoDbObjectId value) {
checkArgument(scope.get().scopeType() instanceof LayoutUDT);
if (scope.get().immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
buffer.get().WriteMongoDbObjectId(scope.get().start() + column.getOffset(), value.clone());
buffer.get().SetBit(scope.get().start(), column.getNullBit().clone());
return Result.SUCCESS;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit,
MongoDbObjectId value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
if (result != Result.SUCCESS) {
return result;
}
buffer.get().WriteSparseMongoDbObjectId(edit, value.clone(), options);
return Result.SUCCESS;
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit,
MongoDbObjectId value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
// TODO: DANOBLE: Ressurect this class implementation
// @Override
// @Nonnull
// public Result readFixed(
// RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<MongoDbObjectId> value) {
// checkArgument(scope.get().scopeType() instanceof LayoutUDT);
// if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
// value.setAndGet(null);
// return Result.NOT_FOUND;
// }
//
// value.setAndGet(buffer.get().ReadMongoDbObjectId(scope.get().start() + column.getOffset()).clone());
// return Result.SUCCESS;
// }
//
// @Override
// @Nonnull
// public Result readSparse(RowBuffer buffer, RowCursor edit,
// Out<MongoDbObjectId> value) {
// Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
// if (result != Result.SUCCESS) {
// value.setAndGet(null);
// return result;
// }
//
// value.setAndGet(buffer.get().ReadSparseMongoDbObjectId(edit).clone());
// return Result.SUCCESS;
// }
//
// @Override
// @Nonnull
// public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
// MongoDbObjectId value) {
// checkArgument(scope.get().scopeType() instanceof LayoutUDT);
// if (scope.get().immutable()) {
// return Result.INSUFFICIENT_PERMISSIONS;
// }
//
// buffer.get().WriteMongoDbObjectId(scope.get().start() + column.getOffset(), value.clone());
// buffer.get().SetBit(scope.get().start(), column.getNullBit().clone());
// return Result.SUCCESS;
// }
//
// //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
// //ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value,
// // UpdateOptions options = UpdateOptions.Upsert)
// @Override
// @Nonnull
// public Result writeSparse(RowBuffer buffer, RowCursor edit,
// MongoDbObjectId value, UpdateOptions options) {
// Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
// if (result != Result.SUCCESS) {
// return result;
// }
//
// buffer.get().WriteSparseMongoDbObjectId(edit, value.clone(), options);
// return Result.SUCCESS;
// }
//
// @Override
// @Nonnull
// public Result writeSparse(RowBuffer buffer, RowCursor edit,
// MongoDbObjectId value) {
// return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
// }
}

View File

@@ -46,8 +46,8 @@ public final class LayoutNullable extends LayoutIndexedScope {
}
public static Result hasValue(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope) {
checkNotNull(buffer);
checkNotNull(scope);
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkArgument(scope.scopeType() instanceof LayoutNullable);
checkArgument(scope.index() == 1 || scope.index() == 2);
checkArgument(scope.scopeTypeArgs().count() == 1);
@@ -55,28 +55,34 @@ public final class LayoutNullable extends LayoutIndexedScope {
return hasValue ? Result.SUCCESS : Result.NOT_FOUND;
}
@Nonnull
@Override
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lengthInBytes));
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
public void setImplicitTypeCode(@Nonnull RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkState(edit.index() == 1);
edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
}
@Nonnull
public Result writeScope(
RowBuffer buffer,
RowCursor edit,
TypeArgumentList typeArgs,
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
boolean hasValue,
Out<RowCursor> value) {
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, hasValue, UpdateOptions.UPSERT, value);
}
@Nonnull
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@@ -126,8 +132,8 @@ public final class LayoutNullable extends LayoutIndexedScope {
@Override
public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) {
checkNotNull(buffer);
checkNotNull(value);
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(value, "expected non-null value");
checkArgument(offset >= 0);
checkArgument(value.count() == 1);

View File

@@ -10,6 +10,8 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutObject extends LayoutPropertyScope {
private TypeArgument typeArg;
@@ -32,13 +34,26 @@ public final class LayoutObject extends LayoutPropertyScope {
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
public Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs,
@Nonnull UpdateOptions options, @Nonnull Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(value, "expected non-null value");
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);

View File

@@ -3,7 +3,7 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
public abstract class LayoutPropertyScope extends LayoutScope {
public abstract class LayoutPropertyScope extends LayoutTypeScope {
protected LayoutPropertyScope(LayoutCode code, boolean immutable) {
super(code, immutable, false, false, false, false, false);
}

View File

@@ -5,6 +5,9 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import javax.annotation.Nonnull;
public abstract class LayoutResolver {
public abstract Layout resolve(SchemaId schemaId);
@Nonnull
public abstract Layout resolve(@Nonnull SchemaId schemaId);
}

View File

@@ -11,6 +11,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.lenientFormat;
@@ -28,11 +29,12 @@ public final class LayoutResolverNamespace extends LayoutResolver {
private final LayoutResolver parent;
private final Namespace schemaNamespace;
public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace) {
this(schemaNamespace, null);
public LayoutResolverNamespace(@Nonnull final Namespace namespace) {
this(namespace, null);
}
public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace, @Nullable final LayoutResolver parent) {
checkNotNull(schemaNamespace, "expected non-null schemaNamespace");
this.schemaNamespace = schemaNamespace;
this.parent = parent;
this.layoutCache = new ConcurrentHashMap<>();
@@ -42,8 +44,11 @@ public final class LayoutResolverNamespace extends LayoutResolver {
return this.schemaNamespace;
}
@Nonnull
@Override
public Layout resolve(SchemaId schemaId) {
public Layout resolve(@Nonnull SchemaId schemaId) {
checkNotNull(schemaId, "expected non-null schemaId");
Layout layout = this.layoutCache.computeIfAbsent(schemaId, id -> {
for (Schema schema : this.namespace().schemas()) {
@@ -55,6 +60,6 @@ public final class LayoutResolverNamespace extends LayoutResolver {
});
checkState(layout != null, "failed to resolve schema %s", schemaId);
return null;
return layout;
}
}

View File

@@ -5,16 +5,24 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import javax.annotation.Nonnull;
import java.util.function.Function;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutResolverSimple extends LayoutResolver {
private tangible.Func1Param<SchemaId, Layout> resolver;
private Function<SchemaId, Layout> resolver;
public LayoutResolverSimple(tangible.Func1Param<SchemaId, Layout> resolver) {
this.resolver = (SchemaId arg) -> resolver.invoke(arg);
public LayoutResolverSimple(Function<SchemaId, Layout> resolver) {
this.resolver = resolver;
}
@Nonnull
@Override
public Layout resolve(SchemaId schemaId) {
return this.resolver.invoke(schemaId);
public Layout resolve(@Nonnull SchemaId schemaId) {
checkNotNull(schemaId, "expected non-null schemaId");
return this.resolver.apply(schemaId);
}
}

View File

@@ -1,25 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
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 java.util.List;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also read using a read-only {@link List{T}}
*
* @param <TElement> The sub-element type to be written
*/
public interface ILayoutSpanReadable<TElement> extends ILayoutType {
Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value);
Result readSparse(RowBuffer buffer, RowCursor scope, Out<List<TElement>> value);
Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value);
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
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 java.util.List;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also read using a read-only {@link List{T}}
*
* @param <TElement> The sub-element type to be written
*/
public interface LayoutSpanReadable<TElement> extends ILayoutType {
Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value);
Result readSparse(RowBuffer buffer, RowCursor scope, Out<List<TElement>> value);
Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value);
}

View File

@@ -1,26 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
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 java.util.List;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link List{T}}
*
* @param <TElement> The sub-element type to be written
*/
public interface ILayoutSpanWritable<TElement> extends ILayoutType {
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
Result writeSparse(RowBuffer buffer, RowCursor edit, TElement value);
Result writeSparse(RowBuffer buffer, RowCursor edit, List<TElement> value, UpdateOptions options);
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
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 java.util.List;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link List{T}}
*
* @param <TElement> The sub-element type to be written
*/
public interface LayoutSpanWritable<TElement> extends ILayoutType {
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
Result writeSparse(RowBuffer buffer, RowCursor edit, TElement value);
Result writeSparse(RowBuffer buffer, RowCursor edit, List<TElement> value, UpdateOptions options);
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
}

View File

@@ -37,7 +37,8 @@ public final class LayoutTagged extends LayoutIndexedScope {
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkArgument(edit.index() >= 0);
checkArgument(edit.scopeTypeArgs().count() > edit.index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode());
@@ -45,29 +46,48 @@ public final class LayoutTagged extends LayoutIndexedScope {
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
TypeArgument[] typeArgs = new TypeArgument[2];
typeArgs[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY);
typeArgs[1] = readTypeArgument(buffer, offset, lenInBytes);
return new TypeArgumentList(typeArgs);
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
return new TypeArgumentList(
new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY),
readTypeArgument(buffer, offset, lengthInBytes)
);
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
edit.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(
RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options, final @Nonnull Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(value, "expected non-null value");
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -81,11 +101,18 @@ public final class LayoutTagged extends LayoutIndexedScope {
}
@Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
public int writeTypeArgument(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final TypeArgumentList value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(value, "expected non-null value");
checkArgument(value.count() == 2);
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
lenInBytes += value.get(1).type().writeTypeArgument(buffer, offset + lenInBytes, value.get(1).typeArgs());
return lenInBytes;
final TypeArgument typeArg = value.get(1);
int lengthInBytes = LayoutCode.BYTES;
lengthInBytes += typeArg.type().writeTypeArgument(buffer, offset + lengthInBytes, typeArg.typeArgs());
return lengthInBytes;
}
}

View File

@@ -10,6 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@@ -32,7 +33,8 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkState(edit.index() >= 0);
checkState(edit.scopeTypeArgs().count() > edit.index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode());
@@ -46,37 +48,59 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
lenInBytes.set(0);
TypeArgument[] retval = new TypeArgument[3];
retval[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY);
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
final TypeArgument[] typeArgs = new TypeArgument[] {
new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY),
null,
null };
final Out<Integer> len = new Out<>();
int sum = 0;
for (int i = 1; i < 3; i++) {
int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
retval[i] = readTypeArgument(buffer, offset + lenInBytes.get(), tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.get();
lenInBytes.set(lenInBytes.get() + itemLenInBytes);
typeArgs[i] = readTypeArgument(buffer, offset + sum, len);
sum += len.get();
}
return new TypeArgumentList(retval);
lengthInBytes.set(sum);
return new TypeArgumentList(typeArgs);
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
public void setImplicitTypeCode(@Nonnull RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
edit.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
public Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs,
@Nonnull UpdateOptions options, @Nonnull Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(value, "expected non-null value");
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -90,18 +114,18 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
}
@Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
public int writeTypeArgument(@Nonnull RowBuffer buffer, int offset, @Nonnull TypeArgumentList value) {
checkState(value.count() == 3);
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
int lengthInBytes = LayoutCode.BYTES;
for (int i = 1; i < value.count(); i++) {
TypeArgument arg = value.get(i);
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs());
}
return lenInBytes;
return lengthInBytes;
}
}

View File

@@ -39,15 +39,18 @@ public final class LayoutTuple extends LayoutIndexedScope {
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
final int numTypeArgs = buffer.read7BitEncodedUInt(offset, lenInBytes);
final int numTypeArgs = (int) buffer.readVariableUInt(offset, lengthInBytes);
final TypeArgument[] typeArgs = new TypeArgument[numTypeArgs];
final Out<Integer> itemLength = new Out<>();
final Out<Integer> len = new Out<>();
int sum = lengthInBytes.get();
for (int i = 0; i < numTypeArgs; i++) {
typeArgs[i] = readTypeArgument(buffer, offset + lenInBytes.get(), itemLength);
lenInBytes.set(lenInBytes.get() + itemLength.get());
typeArgs[i] = readTypeArgument(buffer, offset + sum, len);
sum += len.get();
}
return new TypeArgumentList(typeArgs);
@@ -55,14 +58,28 @@ public final class LayoutTuple extends LayoutIndexedScope {
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(value, "expected non-null value");
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -76,16 +93,14 @@ public final class LayoutTuple extends LayoutIndexedScope {
}
@Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
public int writeTypeArgument(@Nonnull RowBuffer buffer, int offset, @Nonnull TypeArgumentList value) {
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += buffer.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += buffer.write7BitEncodedUInt(offset + lenInBytes, (long) value.count());
for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
int lengthInBytes = LayoutCode.BYTES;
lengthInBytes += buffer.writeVariableUInt(offset + lengthInBytes, value.count());
for (TypeArgument arg : value.list()) {
lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs());
}
return lenInBytes;
return lengthInBytes;
}
}

View File

@@ -17,12 +17,10 @@ import static com.google.common.base.Strings.lenientFormat;
/**
* Describes the physical byte layout of a hybrid row field of a specific physical type {@code T}
*
* {@link LayoutType<T>} is an immutable, stateless, helper class. It provides methods for manipulating hybrid row
* fields of a particular type, and properties that describe the layout of fields of that type.
* <p>
* {@param <T>} The specific physical type whose byte layout is represented by this class.
* {@link LayoutType} provides methods for manipulating hybrid row fields of a particular type, and properties that
* describe the layout of fields of that type.
*/
public abstract class LayoutType<T> implements ILayoutType {
public abstract class LayoutType /*implements ILayoutType*/ {
private static final LayoutType[] codeIndex = new LayoutType[LayoutCode.END_SCOPE.value() + 1];
@@ -32,7 +30,7 @@ public abstract class LayoutType<T> implements ILayoutType {
private final TypeArgument typeArg;
/**
* Initializes a new instance of the {@link LayoutType<T>} class.
* Initializes a new instance of the {@link LayoutType} class.
*/
protected LayoutType(@Nonnull final LayoutCode code, final boolean immutable, final int size) {
@@ -47,7 +45,7 @@ public abstract class LayoutType<T> implements ILayoutType {
}
/**
* Initializes a new instance of the {@link LayoutType<T>} class.
* Initializes a new instance of the {@link LayoutType} class.
*/
protected LayoutType(LayoutCode code, int size) {
this(code, false, size);
@@ -98,71 +96,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return LayoutCode.BYTES;
}
@Nonnull
public final Result deleteFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
if (column.nullBit().isInvalid()) {
// Cannot delete a non-nullable fixed column.
return Result.TYPE_MISMATCH;
}
buffer.unsetBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
/**
* Delete an existing value.
* <p>
* If a value exists, then it is removed. The remainder of the row is resized to accomodate
* a decrease in required space. If no value exists this operation is a no-op.
* @param buffer
* @param edit
*/
@Nonnull
public final Result deleteSparse(RowBuffer buffer, RowCursor edit) {
Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
return result;
}
buffer.deleteSparse(edit);
return Result.SUCCESS;
}
/**
* Delete an existing value.
* <p>
* If a value exists, then it is removed. The remainder of the row is resized to accommodate a decrease in
* required space. If no value exists this operation is a no-op.
*/
@Nonnull
public final Result deleteVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
boolean exists = buffer.readBit(scope.start(), column.nullBit());
if (exists) {
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
buffer.deleteVariable(varOffset, this.isVarint());
buffer.unsetBit(scope.start(), column.nullBit());
}
return Result.SUCCESS;
}
@Nonnull
public static LayoutType fromCode(LayoutCode code) {
LayoutType type = LayoutType.codeIndex[code.value()];
@@ -170,14 +103,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return type;
}
@Nonnull
public final Result hasValue(RowBuffer buffer, RowCursor scope, LayoutColumn column) {
if (!buffer.readBit(scope.start(), column.nullBit())) {
return Result.NOT_FOUND;
}
return Result.SUCCESS;
}
/**
* The physical layout code used to represent the type within the serialization.
*/
@@ -221,7 +146,7 @@ public abstract class LayoutType<T> implements ILayoutType {
/**
* Helper for preparing the move of a sparse field into an existing restricted edit.
*
* @param buffer The row to read from.
* @param buffer The row to read from.
* @param destinationScope The parent set edit into which the field should be moved.
* @param destinationCode The expected type of the edit moving within.
* @param elementType The expected type of the elements within the edit.
@@ -235,7 +160,7 @@ public abstract class LayoutType<T> implements ILayoutType {
public static Result prepareSparseMove(
RowBuffer buffer,
RowCursor destinationScope,
LayoutScope destinationCode,
LayoutTypeScope destinationCode,
TypeArgument elementType,
RowCursor srcEdit,
UpdateOptions options,
@@ -296,15 +221,19 @@ public abstract class LayoutType<T> implements ILayoutType {
/**
* Helper for preparing the read of a sparse field.
*
* @param buffer The row to read from.
* @param edit The parent edit containing the field to read.
* @param code The expected type of the field.
* @param buffer The row to read from.
* @param edit The parent edit containing the field to read.
* @param code The expected type of the field.
* @return Success if the read is permitted, the error code otherwise.
*/
@Nonnull
public static Result prepareSparseRead(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull LayoutCode code) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(code, "expected non-null code");
if (!edit.exists()) {
return Result.NOT_FOUND;
}
@@ -319,7 +248,7 @@ public abstract class LayoutType<T> implements ILayoutType {
/**
* Helper for preparing the write of a sparse field.
*
* @param buffer The row to write to.
* @param buffer The row to write to.
* @param edit The cursor for the field to write.
* @param typeArg The (optional) type constraints.
* @param options The write options.
@@ -332,6 +261,11 @@ public abstract class LayoutType<T> implements ILayoutType {
@Nonnull final TypeArgument typeArg,
@Nonnull final UpdateOptions options) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArg, "expected non-null typeArg");
checkNotNull(options, "expected non-null options");
if (edit.immutable() || (edit.scopeType().isUniqueScope() && !edit.deferUniqueIndex())) {
return Result.INSUFFICIENT_PERMISSIONS;
}
@@ -367,12 +301,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return Result.SUCCESS;
}
@Nonnull
public abstract Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<T> value);
@Nonnull
public abstract Result readSparse(RowBuffer buffer, RowCursor edit, Out<T> value);
@Nonnull
public static TypeArgument readTypeArgument(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
@@ -400,22 +328,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return TypeArgumentList.EMPTY;
}
@Nonnull
public Result readVariable(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<T> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkNotNull(value, "expected non-null value");
value.set(null);
return Result.FAILURE;
}
/**
* If fixed, the fixed size of the type's serialization in bytes, otherwise undefined.
*/
@@ -427,29 +339,14 @@ public abstract class LayoutType<T> implements ILayoutType {
* The physical layout type of the field cast to the specified type.
*/
@SuppressWarnings("unchecked")
public final <Value extends ILayoutType> Value typeAs() {
return (Value)this;
public final <T extends LayoutType> T typeAs() {
return (T)this;
}
@Nonnull
public abstract Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, T value);
@Nonnull
public abstract Result writeSparse(RowBuffer buffer, RowCursor edit, T value);
@Nonnull
public abstract Result writeSparse(RowBuffer buffer, RowCursor edit, T value, UpdateOptions options);
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) {
buffer.writeSparseTypeCode(offset, this.layoutCode());
return LayoutCode.BYTES;
}
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, T value) {
return Result.FAILURE;
}
TypeArgument typeArg() {
return this.typeArg;
}

View File

@@ -0,0 +1,174 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
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 javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class LayoutTypePrimitive<T> extends LayoutType {
/**
* Initializes a new instance of the {@link LayoutType<T>} class.
*
* @param code
* @param immutable
* @param size
*/
protected LayoutTypePrimitive(@Nonnull LayoutCode code, boolean immutable, int size) {
super(code, immutable, size);
}
/**
* Initializes a new instance of the {@link LayoutTypePrimitive<T>} class.
*
* @param code
* @param size
*/
protected LayoutTypePrimitive(LayoutCode code, int size) {
super(code, size);
}
// TODO: DANOBLE: move methods implemented by the C# code LayoutType<T> to this type from LayoutType<T>
// Also:
// * Convert LayoutType<T> to a non-generic type (LayoutType, not LayoutType<T>)
// * Ensure that all primitive types inherit from this type
@Nonnull
public final Result hasValue(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nonnull final LayoutColumn column) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
if (!buffer.readBit(scope.start(), column.nullBit())) {
return Result.NOT_FOUND;
}
return Result.SUCCESS;
}
@Nonnull
public final Result deleteFixed(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nonnull final LayoutColumn column) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
if (column.nullBit().isInvalid()) {
// Cannot delete a non-nullable fixed column.
return Result.TYPE_MISMATCH;
}
buffer.unsetBit(scope.start(), column.nullBit());
return Result.SUCCESS;
}
/**
* Delete an existing value.
* <p>
* If a value exists, then it is removed. The remainder of the row is resized to accommodate
* a decrease in required space. If no value exists this operation is a no-op.
* @param buffer
* @param edit
*/
@Nonnull
public final Result deleteSparse(RowBuffer buffer, RowCursor edit) {
Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
return result;
}
buffer.deleteSparse(edit);
return Result.SUCCESS;
}
/**
* Delete an existing value.
* <p>
* If a value exists, then it is removed. The remainder of the row is resized to accommodate a decrease in
* required space. If no value exists this operation is a no-op.
*/
@Nonnull
public final Result deleteVariable(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS;
}
boolean exists = buffer.readBit(scope.start(), column.nullBit());
if (exists) {
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
buffer.deleteVariable(varOffset, this.isVarint());
buffer.unsetBit(scope.start(), column.nullBit());
}
return Result.SUCCESS;
}
@Nonnull
public abstract Result readFixed(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<T> value);
@Nonnull
public abstract Result readSparse(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final Out<T> value);
@Nonnull
public Result readVariable(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<T> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope, "expected non-null scope");
checkNotNull(column, "expected non-null column");
checkNotNull(value, "expected non-null value");
value.set(null);
return Result.FAILURE;
}
@Nonnull
public abstract Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull T value);
@Nonnull
public abstract Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull T value);
@Nonnull
public abstract Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull T value, @Nonnull UpdateOptions options);
@Nonnull
public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull T value) {
return Result.FAILURE;
}
}

View File

@@ -1,217 +1,217 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
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.RowCursors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class LayoutScope extends LayoutType {
private final boolean isFixedArity;
private final boolean isIndexedScope;
private final boolean isSizedScope;
private final boolean isTypedScope;
private final boolean isUniqueScope;
protected LayoutScope(
@Nonnull final LayoutCode code,
final boolean immutable,
final boolean isSizedScope,
final boolean isIndexedScope,
final boolean isFixedArity,
final boolean isUniqueScope,
final boolean isTypedScope) {
super(code, immutable, 0);
this.isSizedScope = isSizedScope;
this.isIndexedScope = isIndexedScope;
this.isFixedArity = isFixedArity;
this.isUniqueScope = isUniqueScope;
this.isTypedScope = isTypedScope;
}
/**
* Returns {@code false} to indicate that a {@link LayoutScope} is a variable length, not fixed length layout type
*
* @return {@code false}
*/
@Override
public boolean isFixed() {
return false;
}
/**
* Returns true if this is a fixed arity scope.
*/
public boolean isFixedArity() {
return this.isFixedArity;
}
/**
* Returns true if this is an indexed scope.
*/
public boolean isIndexedScope() {
return this.isIndexedScope;
}
/**
* Returns true if this is a sized scope.
*/
public boolean isSizedScope() {
return this.isSizedScope;
}
/**
* Returns true if this is a typed scope.
*/
public boolean isTypedScope() {
return this.isTypedScope;
}
/**
* Returns true if the scope's elements cannot be updated directly.
*/
public boolean isUniqueScope() {
return this.isUniqueScope;
}
@Nonnull
public final Result deleteScope(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
return result;
}
buffer.deleteSparse(edit);
return Result.SUCCESS;
}
/**
* {@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 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(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
return false;
}
@Nonnull
public final Result readScope(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull final Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(value, "expected non-null value");
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.set(null);
return result;
}
boolean immutable = this.isImmutable() || edit.immutable() || edit.scopeType().isUniqueScope();
value.set(buffer.sparseIteratorReadScope(edit, immutable));
return Result.SUCCESS;
}
public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) {
Out<Integer> pathLenInBytes = new Out<>();
Out<Integer> pathOffset = new Out<>();
edit.pathToken(buffer.readSparsePathLen(edit.layout(), edit.valueOffset(), pathLenInBytes, pathOffset));
edit.pathOffset(pathOffset.get());
edit.valueOffset(edit.valueOffset() + pathLenInBytes.get());
}
public void setImplicitTypeCode(final RowCursor edit) {
throw new UnsupportedOperationException();
}
@Nonnull
public abstract Result writeScope(
RowBuffer buffer,
RowCursor scope,
TypeArgumentList typeArgs, Out<RowCursor> value);
@Nonnull
public abstract Result writeScope(
RowBuffer buffer,
RowCursor scope,
TypeArgumentList typeArgs,
UpdateOptions options, Out<RowCursor> value);
@Nonnull
public <TContext> Result writeScope(
RowBuffer buffer,
RowCursor scope,
TypeArgumentList typeArgs,
TContext context, WriterFunc<TContext> func) {
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT);
}
@Nonnull
public <TContext> Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final TypeArgumentList typeArgs,
@Nullable TContext context,
@Nullable WriterFunc<TContext> func,
@Nonnull UpdateOptions options) {
final Out<RowCursor> out = new Out<>();
Result result = this.writeScope(buffer, scope, typeArgs, options, out);
if (result != Result.SUCCESS) {
return result;
}
final RowCursor childScope = out.get();
if (func != null) {
result = func.invoke(buffer, childScope, context);
if (result != Result.SUCCESS) {
this.deleteScope(buffer, scope);
return result;
}
}
RowCursors.skip(scope, buffer, childScope);
return Result.SUCCESS;
}
/**
* A functional interfaced that can be used to write content to a {@link RowBuffer}
*
* @param <TContext> The type of the context value passed by the caller
*/
@FunctionalInterface
public interface WriterFunc<TContext> {
/**
* Writes content to a {@link RowBuffer}
*
* @param buffer The row to write to
* @param scope The type of the scope to write into
* @param context A context value provided by the caller
* @return The result
*/
@Nonnull
Result invoke(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nullable TContext context);
}
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Out;
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.RowCursors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class LayoutTypeScope extends LayoutType {
private final boolean isFixedArity;
private final boolean isIndexedScope;
private final boolean isSizedScope;
private final boolean isTypedScope;
private final boolean isUniqueScope;
protected LayoutTypeScope(
@Nonnull final LayoutCode code,
final boolean immutable,
final boolean isSizedScope,
final boolean isIndexedScope,
final boolean isFixedArity,
final boolean isUniqueScope,
final boolean isTypedScope) {
super(code, immutable, 0);
this.isSizedScope = isSizedScope;
this.isIndexedScope = isIndexedScope;
this.isFixedArity = isFixedArity;
this.isUniqueScope = isUniqueScope;
this.isTypedScope = isTypedScope;
}
/**
* Returns {@code false} to indicate that a {@link LayoutTypeScope} is a variable length, not fixed length layout type
*
* @return {@code false}
*/
@Override
public boolean isFixed() {
return false;
}
/**
* Returns true if this is a fixed arity scope.
*/
public boolean isFixedArity() {
return this.isFixedArity;
}
/**
* Returns true if this is an indexed scope.
*/
public boolean isIndexedScope() {
return this.isIndexedScope;
}
/**
* Returns true if this is a sized scope.
*/
public boolean isSizedScope() {
return this.isSizedScope;
}
/**
* Returns true if this is a typed scope.
*/
public boolean isTypedScope() {
return this.isTypedScope;
}
/**
* Returns true if the scope's elements cannot be updated directly.
*/
public boolean isUniqueScope() {
return this.isUniqueScope;
}
@Nonnull
public final Result deleteScope(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
return result;
}
buffer.deleteSparse(edit);
return Result.SUCCESS;
}
/**
* {@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 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(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
return false;
}
@Nonnull
public final Result readScope(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull final Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(value, "expected non-null value");
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.set(null);
return result;
}
boolean immutable = this.isImmutable() || edit.immutable() || edit.scopeType().isUniqueScope();
value.set(buffer.sparseIteratorReadScope(edit, immutable));
return Result.SUCCESS;
}
public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) {
Out<Integer> pathLenInBytes = new Out<>();
Out<Integer> pathOffset = new Out<>();
edit.pathToken(buffer.readSparsePathLen(edit.layout(), edit.valueOffset(), pathLenInBytes, pathOffset));
edit.pathOffset(pathOffset.get());
edit.valueOffset(edit.valueOffset() + pathLenInBytes.get());
}
public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
throw new UnsupportedOperationException();
}
@Nonnull
public abstract Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor scope,
@Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value);
@Nonnull
public abstract Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor scope,
@Nonnull TypeArgumentList typeArgs,
@Nonnull UpdateOptions options, @Nonnull Out<RowCursor> value);
@Nonnull
public <TContext> Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor scope,
@Nonnull TypeArgumentList typeArgs,
@Nonnull TContext context, @Nullable WriterFunc<TContext> func) {
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT);
}
@Nonnull
public <TContext> Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final TypeArgumentList typeArgs,
@Nullable TContext context,
@Nullable WriterFunc<TContext> func,
@Nonnull UpdateOptions options) {
final Out<RowCursor> out = new Out<>();
Result result = this.writeScope(buffer, scope, typeArgs, options, out);
if (result != Result.SUCCESS) {
return result;
}
final RowCursor childScope = out.get();
if (func != null) {
result = func.invoke(buffer, childScope, context);
if (result != Result.SUCCESS) {
this.deleteScope(buffer, scope);
return result;
}
}
RowCursors.skip(scope, buffer, childScope);
return Result.SUCCESS;
}
/**
* A functional interfaced that can be used to write content to a {@link RowBuffer}
*
* @param <TContext> The type of the context value passed by the caller
*/
@FunctionalInterface
public interface WriterFunc<TContext> {
/**
* Writes content to a {@link RowBuffer}
*
* @param buffer The row to write to
* @param scope The type of the scope to write into
* @param context A context value provided by the caller
* @return The result
*/
@Nonnull
Result invoke(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nullable TContext context);
}
}

View File

@@ -16,8 +16,10 @@ import static com.google.common.base.Preconditions.checkState;
public final class LayoutTypedArray extends LayoutIndexedScope {
public LayoutTypedArray(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE :
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_ARRAY_SCOPE, immutable, true, false, false, true);
super(
immutable ? LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE : LayoutCode.TYPED_ARRAY_SCOPE, immutable,
true, false, false, true
);
}
@Override
@@ -28,7 +30,7 @@ public final class LayoutTypedArray extends LayoutIndexedScope {
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) {
checkState(edit.index() >= 0);
checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
@@ -42,7 +44,7 @@ public final class LayoutTypedArray extends LayoutIndexedScope {
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
public TypeArgumentList readTypeArgumentList(@Nonnull RowBuffer buffer, int offset, @Nonnull Out<Integer> lenInBytes) {
return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lenInBytes));
}

View File

@@ -10,18 +10,20 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public final class LayoutTypedMap extends LayoutUniqueScope {
public LayoutTypedMap(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE :
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_MAP_SCOPE, immutable, isSizedScope():
true, isTypedScope():true)
super(
immutable ? LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE : LayoutCode.TYPED_MAP_SCOPE, immutable,
true, true);
}
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkState(value.count() == 2);
return value.stream()
@@ -31,14 +33,16 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
@Nonnull
@Override
public TypeArgument fieldType(RowCursor scope) {
public TypeArgument fieldType(@Nonnull final RowCursor scope) {
checkNotNull(scope, "expected non-null scope");
return new TypeArgument(
scope.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE,
scope.scopeTypeArgs());
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
return true;
}
@@ -48,39 +52,59 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
}
@Override
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset,
Out<Integer> lenInBytes) {
lenInBytes.setAndGet(0);
TypeArgument[] retval = new TypeArgument[2];
@Nonnull
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
TypeArgument[] typeArguments = new TypeArgument[2];
Out<Integer> length = new Out<>();
int index = 0;
for (int i = 0; i < 2; i++) {
int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
retval[i] = readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
typeArguments[i] = readTypeArgument(buffer, offset + index, length);
index += length.get();
}
return new TypeArgumentList(retval);
lengthInBytes.set(index);
return new TypeArgumentList(typeArguments);
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
edit.cellType(edit.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE);
edit.cellTypeArgs(edit.scopeTypeArgs());
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(value, "expected non-null value");
final Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
@@ -92,14 +116,20 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
}
@Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkState(value.count() == 2);
public int writeTypeArgument(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final TypeArgumentList value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(value, "expected non-null value");
checkArgument(value.count() == 2, "expected value count of 2, not %s", value.count());
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
int lengthInBytes = LayoutCode.BYTES;
for (TypeArgument arg : value.list()) {
lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs());
}
return lenInBytes;
return lengthInBytes;
}
}

View File

@@ -23,7 +23,7 @@ public final class LayoutTypedSet extends LayoutUniqueScope {
}
@Override
public int countTypeArgument(@Nonnull TypeArgumentList value) {
public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value");
checkState(value.count() == 1);
return LayoutCode.BYTES + value.get(0).type().countTypeArgument(value.get(0).typeArgs());
@@ -31,12 +31,14 @@ public final class LayoutTypedSet extends LayoutUniqueScope {
@Nonnull
@Override
public TypeArgument fieldType(RowCursor scope) {
public TypeArgument fieldType(@Nonnull final RowCursor scope) {
checkNotNull(scope, "expected non-null scope");
return scope.scopeTypeArgs().get(0);
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkState(edit.index() >= 0);
checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
@@ -49,47 +51,71 @@ public final class LayoutTypedSet extends LayoutUniqueScope {
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) {
return new TypeArgumentList(readTypeArgument(buffer, offset, lenInBytes));
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer,
final int offset,
@Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
return new TypeArgumentList(readTypeArgument(buffer, offset, lengthInBytes));
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) {
value.setAndGet(null);
return result;
}
buffer.writeTypedSet(edit, this, typeArgs, options, value);
value.set(buffer.writeTypedSet(edit, this, typeArgs, options));
return Result.SUCCESS;
}
@Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
checkArgument(value.count() == 1);
public int writeTypeArgument(
@Nonnull final RowBuffer buffer,
final int offset,
@Nonnull final TypeArgumentList value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(value, "expected non-null value");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
checkArgument(value.count() == 1, "expected a single value count, not %s", value.count());
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
lenInBytes += value.get(0).type().writeTypeArgument(buffer, offset + lenInBytes,
value.get(0).typeArgs());
return lenInBytes;
final TypeArgument typeArg = value.get(0);
int lengthInBytes = LayoutCode.BYTES;
lengthInBytes += typeArg.type().writeTypeArgument(buffer, offset + lengthInBytes, typeArg.typeArgs());
return lengthInBytes;
}
}

View File

@@ -31,7 +31,8 @@ public final class LayoutTypedTuple extends LayoutIndexedScope {
}
@Override
public boolean hasImplicitTypeCode(RowCursor edit) {
public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkArgument(edit.index() >= 0);
checkArgument(edit.scopeTypeArgs().count() > edit.index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode());
@@ -43,40 +44,61 @@ public final class LayoutTypedTuple extends LayoutIndexedScope {
return this.isImmutable() ? "im_tuple_t" : "tuple_t";
}
@Nonnull
@Override
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) {
public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
int numTypeArgs = row.read7BitEncodedUInt(offset, lenInBytes);
TypeArgument[] typeArgs = new TypeArgument[numTypeArgs];
checkNotNull(buffer, "expected non-null buffer");
lengthInBytes
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
final int numTypeArgs = (int) buffer.readVariableUInt(offset, lengthInBytes);
final TypeArgument[] typeArgs = new TypeArgument[numTypeArgs];
final Out<Integer> len = new Out<>();
int sum = lengthInBytes.get();
for (int i = 0; i < numTypeArgs; i++) {
int itemLenInBytes;
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>();
typeArgs[i] = LayoutType.readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
typeArgs[i] = LayoutType.readTypeArgument(buffer, offset + sum, len);
sum += len.get();
}
lengthInBytes.set(sum);
return new TypeArgumentList(typeArgs);
}
@Override
public void setImplicitTypeCode(RowCursor edit) {
public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
edit.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit,
TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(
RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) {
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(edit, "expected non-null edit");
checkNotNull(typeArgs, "expected non-null typeArgs");
checkNotNull(options, "expected non-null options");
checkNotNull(value, "expected non-null value");
Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -90,16 +112,21 @@ public final class LayoutTypedTuple extends LayoutIndexedScope {
}
@Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
public int writeTypeArgument(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final TypeArgumentList value) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(value, "expected non-null value");
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += buffer.write7BitEncodedUInt(offset + lenInBytes, value.count());
for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
int lengthInBytes = LayoutCode.BYTES;
lengthInBytes += buffer.writeVariableUInt(offset + lengthInBytes, value.count());
for (TypeArgument arg : value.list()) {
lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs());
}
return lenInBytes;
return lengthInBytes;
}
}

View File

@@ -33,7 +33,7 @@ public final class LayoutUDT extends LayoutPropertyScope {
@Override
@Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) {
public TypeArgumentList readTypeArgumentList(@Nonnull RowBuffer row, int offset, @Nonnull Out<Integer> lenInBytes) {
SchemaId schemaId = row.readSchemaId(offset);
lenInBytes.set(SchemaId.BYTES);
return new TypeArgumentList(schemaId);
@@ -41,14 +41,14 @@ public final class LayoutUDT extends LayoutPropertyScope {
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) {
public Result writeScope(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
}
@Override
@Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options,
Out<RowCursor> value) {
public Result writeScope(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull UpdateOptions options,
@Nonnull Out<RowCursor> value) {
Layout udt = buffer.resolver().resolve(typeArgs.schemaId());
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -63,7 +63,7 @@ public final class LayoutUDT extends LayoutPropertyScope {
}
@Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) {
public int writeTypeArgument(@Nonnull RowBuffer buffer, int offset, @Nonnull TypeArgumentList value) {
buffer.writeSparseTypeCode(offset, this.layoutCode());
buffer.writeSchemaId(offset + LayoutCode.BYTES, value.schemaId());
return LayoutCode.BYTES + SchemaId.BYTES;

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt16 extends LayoutType<Integer> {
public final class LayoutUInt16 extends LayoutTypePrimitive<Integer> {
public LayoutUInt16() {
super(LayoutCode.UINT_16, Short.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Integer> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Integer> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Integer> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Integer> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Integer value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Integer value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt32 extends LayoutType<Long> {
public final class LayoutUInt32 extends LayoutTypePrimitive<Long> {
public LayoutUInt32() {
super(LayoutCode.UINT_32, Integer.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
@@ -85,7 +85,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt64 extends LayoutType<Long> {
public final class LayoutUInt64 extends LayoutTypePrimitive<Long> {
public LayoutUInt64() {
super(LayoutCode.UINT_64, Long.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -89,7 +89,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt8 extends LayoutType<Short> {
public final class LayoutUInt8 extends LayoutTypePrimitive<Short> {
public LayoutUInt8() {
super(LayoutCode.UINT_8, 1);
@@ -29,7 +29,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Short> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Short> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Short> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Short> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Short value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Short value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -89,7 +89,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -22,7 +22,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
}
@Nonnull
public abstract TypeArgument fieldType(RowCursor scope);
public abstract TypeArgument fieldType(@Nonnull RowCursor scope);
/**
* Search for a matching field within a unique index.
@@ -145,11 +145,4 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
RowCursors.skip(scope, buffer, childScope);
return Result.SUCCESS;
}
@Override
@Nonnull
public <TContext> Result writeScope(
RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func) {
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT);
}
}

View File

@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
public final class LayoutUnixDateTime extends LayoutTypePrimitive<UnixDateTime> {
public LayoutUnixDateTime() {
super(LayoutCode.UNIX_DATE_TIME, UnixDateTime.BYTES);
@@ -30,7 +30,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<UnixDateTime> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<UnixDateTime> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -45,7 +45,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<UnixDateTime> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<UnixDateTime> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) {
value.set(null);
@@ -58,7 +58,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, UnixDateTime value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull UnixDateTime value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UnixDateTime value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UnixDateTime value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
}

View File

@@ -14,7 +14,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8SpanWritable, ILayoutUtf8SpanReadable {
public final class LayoutUtf8 extends LayoutTypePrimitive<String> implements LayoutUtf8SpanWritable, LayoutUtf8SpanReadable {
public LayoutUtf8() {
super(LayoutCode.UTF_8, 0);
@@ -172,13 +172,13 @@ public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8S
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, String value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull String value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, String value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull String value, @Nonnull UpdateOptions options) {
checkArgument(value != null);
return this.writeSparse(buffer, edit, Utf8String.transcodeUtf16(value), options);
}
@@ -205,7 +205,7 @@ public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8S
@Override
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, String value) {
public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull String value) {
checkArgument(value != null);
return this.writeVariable(buffer, scope, column, Utf8String.transcodeUtf16(value));
}

View File

@@ -1,27 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
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.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
*/
public interface ILayoutUtf8SpanReadable extends ILayoutType {
@Nonnull
Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
@Nonnull
Result readSparseSpan(RowBuffer buffer, RowCursor scope, Out<Utf8String> value);
@Nonnull
Result readVariableSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
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.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
*/
public interface LayoutUtf8SpanReadable extends ILayoutType {
@Nonnull
Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
@Nonnull
Result readSparseSpan(RowBuffer buffer, RowCursor scope, Out<Utf8String> value);
@Nonnull
Result readVariableSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
}

View File

@@ -1,29 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Utf8String;
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 javax.annotation.Nonnull;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String}
*/
public interface ILayoutUtf8SpanWritable extends ILayoutType {
@Nonnull
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options);
@Nonnull
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Utf8String;
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 javax.annotation.Nonnull;
/**
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String}
*/
public interface LayoutUtf8SpanWritable extends ILayoutType {
@Nonnull
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value);
@Nonnull
Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options);
@Nonnull
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
}

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutVarInt extends LayoutType<Long> {
public final class LayoutVarInt extends LayoutTypePrimitive<Long> {
public LayoutVarInt() {
super(LayoutCode.VAR_INT, 0);
@@ -33,7 +33,7 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
assert false : "not implemented";
value.set(0L);
return Result.FAILURE;
@@ -41,7 +41,7 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -72,14 +72,14 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) {
assert false : "not implemented";
return Result.FAILURE;
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -93,13 +93,13 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Override
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);

View File

@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutVarUInt extends LayoutType<Long> {
public final class LayoutVarUInt extends LayoutTypePrimitive<Long> {
public LayoutVarUInt() {
super(LayoutCode.VAR_UINT, 0);
@@ -33,7 +33,7 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override
@Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) {
public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
assert false : "not implemented";
value.set(0L);
return Result.FAILURE;
@@ -41,7 +41,7 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override
@Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) {
public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -72,14 +72,14 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override
@Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) {
public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) {
assert false : "not implemented";
return Result.FAILURE;
}
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -93,13 +93,13 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override
@Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) {
public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) {
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Override
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn col, Long value) {
public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn col, @Nonnull Long value) {
checkArgument(scope.scopeType() instanceof LayoutUDT);

View File

@@ -1,47 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
public class SamplingStringComparer implements IEqualityComparer<String> {
public static final SamplingStringComparer Default = new SamplingStringComparer();
public final boolean equals(String x, String y) {
checkArgument(x != null);
checkArgument(y != null);
return x.equals(y);
}
public final int hashCode(String obj) {
checkArgument(obj != null);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
unchecked
{
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash1 = 5381;
int hash1 = 5381;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash2 = hash1;
int hash2 = hash1;
final int numSamples = 4;
final int modulus = 13;
ReadOnlySpan<Character> utf16 = obj.AsSpan();
int max = Math.min(utf16.Length, numSamples);
for (int i = 0; i < max; i++) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint c = utf16[(i * modulus) % utf16.Length];
int c = utf16[(i * modulus) % utf16.Length];
if (i % 2 == 0) {
hash1 = ((hash1 << 5) + hash1) ^ c;
} else {
hash2 = ((hash2 << 5) + hash2) ^ c;
}
}
return hash1 + (hash2 * 1566083941);
}
}
}

View File

@@ -1,49 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.layouts;
public class SamplingUtf8StringComparer implements IEqualityComparer<Utf8String> {
public static final SamplingUtf8StringComparer Default = new SamplingUtf8StringComparer();
public final boolean equals(Utf8String x, Utf8String y) {
checkArgument(x != null);
checkArgument(y != null);
return x.Span.equals(y.Span);
}
public final int hashCode(Utf8String obj) {
checkArgument(obj != null);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
unchecked
{
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash1 = 5381;
int hash1 = 5381;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash2 = hash1;
int hash2 = hash1;
final int numSamples = 4;
final int modulus = 13;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ReadOnlySpan<byte> utf8 = obj.Span.Span;
ReadOnlySpan<Byte> utf8 = obj.Span.Span;
int max = Math.min(utf8.Length, numSamples);
for (int i = 0; i < max; i++) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint c = utf8[(i * modulus) % utf8.Length];
int c = utf8[(i * modulus) % utf8.Length];
if (i % 2 == 0) {
hash1 = ((hash1 << 5) + hash1) ^ c;
} else {
hash2 = ((hash2 << 5) + hash2) ^ c;
}
}
return hash1 + (hash2 * 1566083941);
}
}
}

View File

@@ -14,6 +14,8 @@ import com.google.common.base.Strings;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -104,6 +106,10 @@ public final class TypeArgumentList {
return hash;
}
public List<TypeArgument> list() {
return Collections.unmodifiableList(Arrays.asList(this.args));
}
/**
* For UDT fields, the schema id of the nested layout.
*/

View File

@@ -87,7 +87,7 @@ public final class RecordIOParser {
new Reference<RowReader>(reader);
Out<Segment> tempOut_segment =
new Out<Segment>();
result = SegmentSerializer.Read(tempReference_reader, tempOut_segment);
result = SegmentSerializer.read(tempReference_reader, tempOut_segment);
this.segment = tempOut_segment.get();
reader = tempReference_reader.get();
if (result != Result.SUCCESS) {
@@ -118,7 +118,7 @@ public final class RecordIOParser {
new Reference<RowReader>(reader);
Out<Segment> tempOut_segment2
= new Out<Segment>();
result = SegmentSerializer.Read(tempReference_reader2, tempOut_segment2);
result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2);
this.segment = tempOut_segment2.get();
reader = tempReference_reader2.get();
if (result != Result.SUCCESS) {

View File

@@ -9,49 +9,52 @@ 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.io.RowReader;
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
import io.netty.buffer.ByteBuf;
public final class SegmentSerializer {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public static Result Read(Span<byte> span, LayoutResolver resolver, out Segment obj)
public static Result Read(Span<Byte> span, LayoutResolver resolver, Out<Segment> obj) {
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, resolver);
public static Result read(ByteBuf buffer, LayoutResolver resolver, Out<Segment> segment) {
RowBuffer row = new RowBuffer(buffer, HybridRowVersion.V1, resolver);
Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row);
row = tempReference_row.get();
Reference<RowReader> tempReference_reader =
new Reference<RowReader>(reader);
Result tempVar = SegmentSerializer.Read(tempReference_reader, obj.clone());
Result tempVar = SegmentSerializer.read(tempReference_reader, segment.clone());
reader = tempReference_reader.get();
return tempVar;
}
public static Result Read(Reference<RowReader> reader, Out<Segment> obj) {
obj.setAndGet(null);
while (reader.get().read()) {
public static Result read(RowReader reader, Out<Segment> segment) {
segment.setAndGet(null);
while (reader.read()) {
Result r;
// TODO: use Path tokens here.
switch (reader.get().path().toString()) {
switch (reader.path().toString()) {
case "length":
Out<Integer> tempOut_Length = new Out<Integer>();
r = reader.get().readInt32(tempOut_Length);
obj.get().argValue.Length = tempOut_Length.get();
r = reader.readInt32(tempOut_Length);
segment.get().argValue.Length = tempOut_Length.get();
if (r != Result.SUCCESS) {
return r;
}
// If the RowBuffer isn't big enough to contain the rest of the header, then just
// return the length.
if (reader.get().length() < obj.get().length()) {
if (reader.length() < segment.get().length()) {
return Result.SUCCESS;
}
break;
case "comment":
Out<String> tempOut_Comment = new Out<String>();
r = reader.get().readString(tempOut_Comment);
obj.get().argValue.Comment = tempOut_Comment.get();
r = reader.readString(tempOut_Comment);
segment.get().argValue.Comment = tempOut_Comment.get();
if (r != Result.SUCCESS) {
return r;
}
@@ -59,8 +62,8 @@ public final class SegmentSerializer {
break;
case "sdl":
Out<String> tempOut_SDL = new Out<String>();
r = reader.get().readString(tempOut_SDL);
obj.get().argValue.SDL = tempOut_SDL.get();
r = reader.readString(tempOut_SDL);
segment.get().argValue.SDL = tempOut_SDL.get();
if (r != Result.SUCCESS) {
return r;
}
@@ -72,17 +75,17 @@ public final class SegmentSerializer {
return Result.SUCCESS;
}
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Segment obj) {
public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) {
Result r;
if (obj.comment() != null) {
r = writer.get().WriteString("comment", obj.comment());
if (segment.comment() != null) {
r = writer.WriteString("comment", segment.comment());
if (r != Result.SUCCESS) {
return r;
}
}
if (obj.sdl() != null) {
r = writer.get().WriteString("sdl", obj.sdl());
if (segment.sdl() != null) {
r = writer.WriteString("sdl", segment.sdl());
if (r != Result.SUCCESS) {
return r;
}
@@ -91,13 +94,13 @@ public final class SegmentSerializer {
// Defer writing the length until all other fields of the segment header are written.
// The length is then computed based on the current size of the underlying RowBuffer.
// Because the length field is itself fixed, writing the length can never change the length.
int length = writer.get().getLength();
r = writer.get().WriteInt32("length", length);
int length = writer.getLength();
r = writer.WriteInt32("length", length);
if (r != Result.SUCCESS) {
return r;
}
checkState(length == writer.get().getLength());
checkState(length == writer.getLength());
return Result.SUCCESS;
}
}

View File

@@ -1,84 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.schemas;
import Newtonsoft.Json.*;
import Newtonsoft.Json.Converters.*;
import Newtonsoft.Json.Linq.*;
/**
* Helper class for parsing the polymorphic {@link PropertyType} subclasses from JSON.
*/
public class PropertySchemaConverter extends JsonConverter {
@Override
public boolean getCanWrite() {
return false;
}
@Override
public boolean CanConvert(java.lang.Class objectType) {
return objectType.isAssignableFrom(PropertyType.class);
}
@Override
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
JsonSerializer serializer) {
PropertyType p;
if (reader.TokenType != JsonToken.StartObject) {
throw new JsonSerializationException();
}
JObject propSchema = JObject.Load(reader);
TypeKind propType;
JToken value;
// 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:
if (!propSchema.TryGetValue("type", out value)) {
throw new JsonSerializationException("Required \"type\" property missing.");
}
try (JsonReader typeReader = value.CreateReader()) {
typeReader.Read(); // Move to the start token
propType = TypeKind.forValue((new StringEnumConverter(true)).ReadJson(typeReader, TypeKind.class, null,
serializer));
}
switch (propType) {
case Array:
p = new ArrayPropertyType();
break;
case SET:
p = new SetPropertyType();
break;
case MAP:
p = new MapPropertyType();
break;
case Object:
p = new ObjectPropertyType();
break;
case Tuple:
p = new TuplePropertyType();
break;
case TAGGED:
p = new TaggedPropertyType();
break;
case Schema:
p = new UdtPropertyType();
break;
default:
p = new PrimitivePropertyType();
break;
}
serializer.Populate(propSchema.CreateReader(), p);
return p;
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [ExcludeFromCodeCoverage] public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
@Override
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
}
}

View File

@@ -1,37 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.schemas;
import Newtonsoft.Json.*;
public class StrictBooleanConverter extends JsonConverter {
@Override
public boolean getCanWrite() {
return false;
}
@Override
public boolean CanConvert(java.lang.Class objectType) {
return objectType == Boolean.class;
}
@Override
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
JsonSerializer serializer) {
switch (reader.TokenType) {
case JsonToken.Boolean:
return serializer.Deserialize(reader, objectType);
default:
throw new JsonSerializationException(String.format("Token \"%1$s\" of type %2$s was not a JSON bool",
reader.Value, reader.TokenType));
}
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [ExcludeFromCodeCoverage] public override void WriteJson(JsonWriter writer, object value,
// JsonSerializer serializer)
@Override
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
}
}

View File

@@ -1,47 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.data.cosmos.serialization.hybridrow.schemas;
import Newtonsoft.Json.*;
import java.math.BigInteger;
public class StrictIntegerConverter extends JsonConverter {
@Override
public boolean getCanWrite() {
return false;
}
@Override
public boolean CanConvert(java.lang.Class objectType) {
return StrictIntegerConverter.IsIntegerType(objectType);
}
@Override
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
JsonSerializer serializer) {
switch (reader.TokenType) {
case JsonToken.Integer:
return serializer.Deserialize(reader, objectType);
default:
throw new JsonSerializationException(String.format("Token \"%1$s\" of type %2$s was not a JSON " +
"integer", reader.Value, reader.TokenType));
}
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [ExcludeFromCodeCoverage] public override void WriteJson(JsonWriter writer, object value,
// JsonSerializer serializer)
@Override
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
}
private static boolean IsIntegerType(java.lang.Class type) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: if (type == typeof(long) || type == typeof(ulong) || type == typeof(int) || type == typeof
// (uint) || type == typeof(short) || type == typeof(ushort) || type == typeof(byte) || type == typeof(sbyte)
// || type == typeof(BigInteger))
return type == Long.class || type == Long.class || type == Integer.class || type == Integer.class || type == Short.class || type == Short.class || type == Byte.class || type == Byte.class || type == BigInteger.class;
}
}

View File

@@ -14,7 +14,7 @@ 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;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypeScope;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
@@ -294,7 +294,7 @@ public final class CodeGenRowGenerator {
private static final Utf8String PhoneNumbersName = Utf8String.TranscodeUtf16("phone_numbers");
private static final Utf8String TitleName = Utf8String.TranscodeUtf16("title");
private AddressHybridRowSerializer addressSerializer;
private LayoutScope.WriterFunc<HashMap<Utf8String, Object>> addressSerializerWriter;
private LayoutTypeScope.WriterFunc<HashMap<Utf8String, Object>> addressSerializerWriter;
private LayoutColumn addresses;
private TypeArgumentList addressesFieldType = new TypeArgumentList();
private StringToken addressesToken = new StringToken();

View File

@@ -118,7 +118,7 @@ public final class JsonModelRowGenerator {
//ORIGINAL LINE: case bool x:
case
boolean x:
return writer.get().WriteBool(path, x);
return writer.get().WriteBoolean(path, x);
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
//ORIGINAL LINE: case long x:
case