Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-08-30 13:49:25 -07:00
parent 1ac2c33a15
commit 4dbaf6f08f
26 changed files with 1211 additions and 1260 deletions

View File

@@ -0,0 +1,24 @@
package com.azure.data.cosmos.core;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import static com.google.common.base.Strings.lenientFormat;
public final class Json {
private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectWriter writer = mapper.writer();
private Json() {
}
public static String toString(Object object) {
try {
return writer.writeValueAsString(object);
} catch (JsonProcessingException error) {
return lenientFormat("{\"error\": \"%s\"}", error);
}
}
}

View File

@@ -39,16 +39,9 @@ public final class Float128 {
* The size (in bytes) of a {@link Float128}. * The size (in bytes) of a {@link Float128}.
*/ */
public static final int Size = (Long.SIZE / Byte.SIZE) + (Long.SIZE / Byte.SIZE); public static final int Size = (Long.SIZE / Byte.SIZE) + (Long.SIZE / Byte.SIZE);
/**
* The high-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID private final long high;
* encoding scheme. private final long low;
*/
public long High;
/**
* The low-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID
* encoding scheme.
*/
public long Low;
/** /**
* Initializes a new instance of the {@link Float128} struct. * Initializes a new instance of the {@link Float128} struct.
@@ -56,20 +49,24 @@ public final class Float128 {
* @param high the high-order 64 bits. * @param high the high-order 64 bits.
* @param low the low-order 64 bits. * @param low the low-order 64 bits.
*/ */
public Float128() {
}
public Float128(long high, long low) { public Float128(long high, long low) {
this.High = high; this.high = high;
this.Low = low; this.low = low;
} }
public Float128 clone() { /**
Float128 varCopy = new Float128(); * The high-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID
* encoding scheme.
*/
public long high() {
return this.high;
}
varCopy.Low = this.Low; /**
varCopy.High = this.High; * The low-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID
* encoding scheme.
return varCopy; */
public long low() {
return this.low;
} }
} }

View File

@@ -24,7 +24,7 @@ public final class HybridRowHeader {
*/ */
public HybridRowHeader(HybridRowVersion version, SchemaId schemaId) { public HybridRowHeader(HybridRowVersion version, SchemaId schemaId) {
this.version = version; this.version = version;
this.schemaId = new SchemaId(schemaId.id()); this.schemaId = SchemaId.from(schemaId.value());
} }
/** /**

View File

@@ -38,7 +38,7 @@ public final class RowCursor implements Cloneable {
private UtfAnyString writePath; private UtfAnyString writePath;
private StringToken writePathToken; private StringToken writePathToken;
private RowCursor() { RowCursor() {
} }
protected RowCursor clone() { protected RowCursor clone() {
@@ -97,6 +97,11 @@ public final class RowCursor implements Cloneable {
return this.cellTypeArgs; return this.cellTypeArgs;
} }
public RowCursor cellTypeArgs(TypeArgumentList value) {
this.cellTypeArgs = value;
return this;
}
/** /**
* For sized scopes (e.g. Typed Array), the number of elements. * For sized scopes (e.g. Typed Array), the number of elements.
*/ */

View File

@@ -4,6 +4,8 @@
package com.azure.data.cosmos.serialization.hybridrow; package com.azure.data.cosmos.serialization.hybridrow;
import java.util.HashMap;
/** /**
* Describes the desired behavior when mutating a hybrid row. * Describes the desired behavior when mutating a hybrid row.
*/ */
@@ -53,27 +55,27 @@ public enum RowOptions {
Delete(5); Delete(5);
public static final int SIZE = java.lang.Integer.SIZE; public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, RowOptions> mappings; private static HashMap<Integer, RowOptions> mappings;
private int intValue; private int value;
RowOptions(int value) { RowOptions(int value) {
intValue = value; this.value = value;
getMappings().put(value, this); mappings().put(value, this);
} }
public int getValue() { public int getValue() {
return intValue; return this.value;
} }
public static RowOptions forValue(int value) { public static RowOptions from(int value) {
return getMappings().get(value); return mappings().get(value);
} }
private static java.util.HashMap<Integer, RowOptions> getMappings() { private static HashMap<Integer, RowOptions> mappings() {
if (mappings == null) { if (mappings == null) {
synchronized (RowOptions.class) { synchronized (RowOptions.class) {
if (mappings == null) { if (mappings == null) {
mappings = new java.util.HashMap<Integer, RowOptions>(); mappings = new HashMap<>();
} }
} }
} }

View File

@@ -34,15 +34,15 @@ public final class SchemaId {
public static final int SIZE = (Integer.SIZE / Byte.SIZE); public static final int SIZE = (Integer.SIZE / Byte.SIZE);
private static long MAX_VALUE = 0x00000000FFFFFFFFL; private static long MAX_VALUE = 0x00000000FFFFFFFFL;
private final int id; private final int value;
/** /**
* Initializes a new instance of the {@link SchemaId} struct. * Initializes a new instance of the {@link SchemaId} struct.
* *
* @param id The underlying globally unique identifier of the schema. * @param value The underlying globally unique identifier of the schema.
*/ */
private SchemaId(int id) { private SchemaId(int value) {
this.id = id; this.value = value;
} }
@Override @Override
@@ -60,12 +60,12 @@ public final class SchemaId {
if (null == other) { if (null == other) {
return false; return false;
} }
return this.id() == other.id(); return this.value() == other.value();
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Integer.valueOf(this.id()).hashCode(); return Integer.valueOf(this.value()).hashCode();
} }
/** /**
@@ -73,8 +73,8 @@ public final class SchemaId {
* *
* @return The integer value of this {@link SchemaId} * @return The integer value of this {@link SchemaId}
*/ */
public int id() { public int value() {
return this.id; return this.value;
} }
/** /**
@@ -82,13 +82,13 @@ public final class SchemaId {
* *
* @return The integer value of this {@link SchemaId} * @return The integer value of this {@link SchemaId}
*/ */
public static SchemaId from(int id) { public static SchemaId from(int value) {
return new SchemaId(id); return new SchemaId(value);
} }
@Override @Override
public String toString() { public String toString() {
return String.valueOf(this.id()); return String.valueOf(this.value());
} }
static final class JsonDeserializer extends StdDeserializer<SchemaId> { static final class JsonDeserializer extends StdDeserializer<SchemaId> {
@@ -119,7 +119,7 @@ public final class SchemaId {
@Override @Override
public void serialize(final SchemaId value, final JsonGenerator generator, final SerializerProvider provider) throws IOException { public void serialize(final SchemaId value, final JsonGenerator generator, final SerializerProvider provider) throws IOException {
generator.writeNumber((long) value.id() & MAX_VALUE); generator.writeNumber((long) value.value() & MAX_VALUE);
} }
} }
} }

View File

@@ -140,7 +140,7 @@ public final class RowReader {
case Sparse: case Sparse:
if (this.cursor.cellType() instanceof LayoutNullable) { if (this.cursor.cellType() instanceof LayoutNullable) {
Reference<RowCursor> cursor = new Reference<>(this.cursor); Reference<RowCursor> cursor = new Reference<>(this.cursor);
RowCursor nullableScope = this.row.SparseIteratorReadScope(cursor, true).clone(); RowCursor nullableScope = this.row.sparseIteratorReadScope(cursor, true).clone();
this.cursor = cursor.get(); this.cursor = cursor.get();
Reference<RowBuffer> row = new Reference<>(this.row); Reference<RowBuffer> row = new Reference<>(this.row);
Reference<RowCursor> tempReference_nullableScope = new Reference<>(nullableScope); Reference<RowCursor> tempReference_nullableScope = new Reference<>(nullableScope);
@@ -744,7 +744,7 @@ public final class RowReader {
public RowReader ReadScope() { public RowReader ReadScope() {
Reference<RowCursor> tempReference_cursor = Reference<RowCursor> tempReference_cursor =
new Reference<RowCursor>(this.cursor); new Reference<RowCursor>(this.cursor);
RowCursor newScope = this.row.SparseIteratorReadScope(tempReference_cursor, true).clone(); RowCursor newScope = this.row.sparseIteratorReadScope(tempReference_cursor, true).clone();
this.cursor = tempReference_cursor.get(); this.cursor = tempReference_cursor.get();
Reference<RowBuffer> tempReference_row = Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(this.row); new Reference<RowBuffer>(this.row);
@@ -763,7 +763,7 @@ public final class RowReader {
public <TContext> Result ReadScope(TContext context, ReaderFunc<TContext> func) { public <TContext> Result ReadScope(TContext context, ReaderFunc<TContext> func) {
Reference<RowCursor> tempReference_cursor = Reference<RowCursor> tempReference_cursor =
new Reference<RowCursor>(this.cursor); new Reference<RowCursor>(this.cursor);
RowCursor childScope = this.row.SparseIteratorReadScope(tempReference_cursor, true).clone(); RowCursor childScope = this.row.sparseIteratorReadScope(tempReference_cursor, true).clone();
this.cursor = tempReference_cursor.get(); this.cursor = tempReference_cursor.get();
Reference<RowBuffer> tempReference_row = Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(this.row); new Reference<RowBuffer>(this.row);

View File

@@ -60,7 +60,7 @@ public final class LayoutFloat128 extends LayoutType<com.azure.data.cosmos.seria
return Result.InsufficientPermissions; return Result.InsufficientPermissions;
} }
b.get().WriteFloat128(scope.get().start() + col.getOffset(), value.clone()); b.get().writeFloat128(scope.get().start() + col.getOffset(), value);
b.get().SetBit(scope.get().start(), col.getNullBit().clone()); b.get().SetBit(scope.get().start(), col.getNullBit().clone());
return Result.Success; return Result.Success;
} }

View File

@@ -75,7 +75,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
return result; return result;
} }
b.get().WriteSparseFloat32(edit, value, options); b.get().writeSparseFloat32(edit, value, options);
return Result.Success; return Result.Success;
} }

View File

@@ -59,7 +59,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
return Result.InsufficientPermissions; return Result.InsufficientPermissions;
} }
b.get().WriteInt16(scope.get().start() + col.getOffset(), value); b.get().writeInt16(scope.get().start() + col.getOffset(), value);
b.get().SetBit(scope.get().start(), col.getNullBit().clone()); b.get().SetBit(scope.get().start(), col.getNullBit().clone());
return Result.Success; return Result.Success;
} }

View File

@@ -59,7 +59,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
return Result.InsufficientPermissions; return Result.InsufficientPermissions;
} }
b.get().WriteInt32(scope.get().start() + col.getOffset(), value); b.get().writeInt32(scope.get().start() + col.getOffset(), value);
b.get().SetBit(scope.get().start(), col.getNullBit().clone()); b.get().SetBit(scope.get().start(), col.getNullBit().clone());
return Result.Success; return Result.Success;
} }

View File

@@ -59,7 +59,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
return Result.InsufficientPermissions; return Result.InsufficientPermissions;
} }
b.get().WriteInt64(scope.get().start() + col.getOffset(), value); b.get().writeInt64(scope.get().start() + col.getOffset(), value);
b.get().SetBit(scope.get().start(), col.getNullBit().clone()); b.get().SetBit(scope.get().start(), col.getNullBit().clone());
return Result.Success; return Result.Success;
} }

View File

@@ -59,7 +59,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
return Result.InsufficientPermissions; return Result.InsufficientPermissions;
} }
b.get().WriteInt8(scope.get().start() + col.getOffset(), value); b.get().writeInt8(scope.get().start() + col.getOffset(), value);
b.get().SetBit(scope.get().start(), col.getNullBit().clone()); b.get().SetBit(scope.get().start(), col.getNullBit().clone());
return Result.Success; return Result.Success;
} }

View File

@@ -50,7 +50,7 @@ public final class LayoutResolverNamespace extends LayoutResolver {
// ConcurrentDictionary method: // ConcurrentDictionary method:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these // 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: // cannot be converted using the 'Out' helper class unless the method is within the code being modified:
if (this.layoutCache.TryGetValue(schemaId.id(), out layout)) { if (this.layoutCache.TryGetValue(schemaId.value(), out layout)) {
return layout; return layout;
} }
@@ -58,7 +58,7 @@ public final class LayoutResolverNamespace extends LayoutResolver {
if (SchemaId.opEquals(s.getSchemaId().clone(), if (SchemaId.opEquals(s.getSchemaId().clone(),
schemaId.clone())) { schemaId.clone())) {
layout = s.Compile(this.schemaNamespace); layout = s.Compile(this.schemaNamespace);
layout = this.layoutCache.putIfAbsent(schemaId.id(), layout); layout = this.layoutCache.putIfAbsent(schemaId.value(), layout);
return layout; return layout;
} }
} }
@@ -67,7 +67,7 @@ public final class LayoutResolverNamespace extends LayoutResolver {
if (layout != null) { if (layout != null) {
// TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET // TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET
// ConcurrentDictionary method: // ConcurrentDictionary method:
boolean succeeded = this.layoutCache.TryAdd(schemaId.id(), layout); boolean succeeded = this.layoutCache.TryAdd(schemaId.value(), layout);
checkState(succeeded); checkState(succeeded);
return layout; return layout;
} }

View File

@@ -105,7 +105,7 @@ public abstract class LayoutScope extends LayoutType {
return result; return result;
} }
value.setAndGet(b.get().SparseIteratorReadScope(edit, value.setAndGet(b.get().sparseIteratorReadScope(edit,
this.Immutable || edit.get().immutable() || edit.get().scopeType().isUniqueScope()).clone()); this.Immutable || edit.get().immutable() || edit.get().scopeType().isUniqueScope()).clone());
return Result.Success; return Result.Success;

View File

@@ -26,7 +26,7 @@ public final class LayoutTuple extends LayoutIndexedScope {
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count); //ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.Count7BitEncodedUInt(value.count()); lenInBytes += RowBuffer.count7BitEncodedUInt(value.count());
for (TypeArgument arg : value) { for (TypeArgument arg : value) {
lenInBytes += arg.type().CountTypeArgument(arg.typeArgs().clone()); lenInBytes += arg.type().CountTypeArgument(arg.typeArgs().clone());
} }
@@ -78,7 +78,7 @@ public final class LayoutTuple extends LayoutIndexedScope {
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count); //ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += row.get().Write7BitEncodedUInt(offset + lenInBytes, value.count()); lenInBytes += row.get().write7BitEncodedUInt(offset + lenInBytes, value.count());
for (TypeArgument arg : value) { for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(row, offset + lenInBytes, arg.typeArgs().clone()); lenInBytes += arg.type().writeTypeArgument(row, offset + lenInBytes, arg.typeArgs().clone());
} }

View File

@@ -65,7 +65,7 @@ public abstract class LayoutType<T> implements ILayoutType {
* The entire edit can still be replaced. * The entire edit can still be replaced.
*/ */
public boolean isImmutable() { public boolean isImmutable() {
return immutable; return this.immutable;
} }
/** /**
@@ -306,37 +306,38 @@ public abstract class LayoutType<T> implements ILayoutType {
* @param options The write options. * @param options The write options.
* @return Success if the write is permitted, the error code otherwise. * @return Success if the write is permitted, the error code otherwise.
*/ */
public static Result prepareSparseWrite(Reference<RowBuffer> b, Reference<RowCursor> edit, public static Result prepareSparseWrite(
TypeArgument typeArg, UpdateOptions options) { RowBuffer b, RowCursor edit, TypeArgument typeArg, UpdateOptions options
if (edit.get().immutable() || (edit.get().scopeType().isUniqueScope() && !edit.get().deferUniqueIndex())) { ) {
if (edit.immutable() || (edit.scopeType().isUniqueScope() && !edit.deferUniqueIndex())) {
return Result.InsufficientPermissions; return Result.InsufficientPermissions;
} }
if (edit.get().scopeType().isFixedArity() && !(edit.get().scopeType() instanceof LayoutNullable)) { if (edit.scopeType().isFixedArity() && !(edit.scopeType() instanceof LayoutNullable)) {
if ((edit.get().index() < edit.get().scopeTypeArgs().count()) && !typeArg.equals(edit.get().scopeTypeArgs().get(edit.get().index()))) { if ((edit.index() < edit.scopeTypeArgs().count()) && !typeArg.equals(edit.scopeTypeArgs().get(edit.index()))) {
return Result.TypeConstraint; return Result.TypeConstraint;
} }
} else if (edit.get().scopeType() instanceof LayoutTypedMap) { } else if (edit.scopeType() instanceof LayoutTypedMap) {
if (!((typeArg.type() instanceof LayoutTypedTuple) && typeArg.typeArgs().equals(edit.get().scopeTypeArgs()))) { if (!((typeArg.type() instanceof LayoutTypedTuple) && typeArg.typeArgs().equals(edit.scopeTypeArgs()))) {
return Result.TypeConstraint; return Result.TypeConstraint;
} }
} else if (edit.get().scopeType().isTypedScope() && !typeArg.equals(edit.get().scopeTypeArgs().get(0))) { } else if (edit.scopeType().isTypedScope() && !typeArg.equals(edit.scopeTypeArgs().get(0))) {
return Result.TypeConstraint; return Result.TypeConstraint;
} }
if ((options == UpdateOptions.InsertAt) && edit.get().scopeType().isFixedArity()) { if ((options == UpdateOptions.InsertAt) && edit.scopeType().isFixedArity()) {
return Result.TypeConstraint; return Result.TypeConstraint;
} }
if ((options == UpdateOptions.InsertAt) && !edit.get().scopeType().isFixedArity()) { if ((options == UpdateOptions.InsertAt) && !edit.scopeType().isFixedArity()) {
edit.get().exists = false; // InsertAt never overwrites an existing item. edit.exists(false); // InsertAt never overwrites an existing item.
} }
if ((options == UpdateOptions.Update) && (!edit.get().exists())) { if ((options == UpdateOptions.Update) && (!edit.exists())) {
return Result.NotFound; return Result.NotFound;
} }
if ((options == UpdateOptions.Insert) && edit.get().exists()) { if ((options == UpdateOptions.Insert) && edit.exists()) {
return Result.Exists; return Result.Exists;
} }
@@ -371,7 +372,7 @@ public abstract class LayoutType<T> implements ILayoutType {
* If fixed, the fixed size of the type's serialization in bytes, otherwise undefined. * If fixed, the fixed size of the type's serialization in bytes, otherwise undefined.
*/ */
public int size() { public int size() {
return size; return this.size;
} }
/** /**

View File

@@ -26,7 +26,7 @@ public final class LayoutTypedTuple extends LayoutIndexedScope {
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count); //ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.Count7BitEncodedUInt(value.count()); lenInBytes += RowBuffer.count7BitEncodedUInt(value.count());
for (TypeArgument arg : value) { for (TypeArgument arg : value) {
lenInBytes += arg.type().CountTypeArgument(arg.typeArgs().clone()); lenInBytes += arg.type().CountTypeArgument(arg.typeArgs().clone());
} }
@@ -91,7 +91,7 @@ public final class LayoutTypedTuple extends LayoutIndexedScope {
int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE); int lenInBytes = (com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count); //ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += row.get().Write7BitEncodedUInt(offset + lenInBytes, value.count()); lenInBytes += row.get().write7BitEncodedUInt(offset + lenInBytes, value.count());
for (TypeArgument arg : value) { for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(row, offset + lenInBytes, arg.typeArgs().clone()); lenInBytes += arg.type().writeTypeArgument(row, offset + lenInBytes, arg.typeArgs().clone());
} }

View File

@@ -13,13 +13,13 @@ public abstract class LayoutTypes {
public static final int BitsPerByte = 8; public static final int BitsPerByte = 8;
public static final LayoutBoolean Boolean = new LayoutBoolean(true); public static final LayoutBoolean Boolean = new LayoutBoolean(true);
public static final LayoutBoolean BooleanFalse = new LayoutBoolean(false); public static final LayoutBoolean BooleanFalse = new LayoutBoolean(false);
public static final LayoutDateTime DateTime = new LayoutDateTime(); public static final LayoutDateTime DATE_TIME = new LayoutDateTime();
public static final LayoutDecimal Decimal = new LayoutDecimal(); public static final LayoutDecimal DECIMAL = new LayoutDecimal();
public static final LayoutEndScope EndScope = new LayoutEndScope(); public static final LayoutEndScope EndScope = new LayoutEndScope();
public static final LayoutFloat128 Float128 = new LayoutFloat128(); public static final LayoutFloat128 FLOAT_128 = new LayoutFloat128();
public static final LayoutFloat32 Float32 = new LayoutFloat32(); public static final LayoutFloat32 FLOAT_32 = new LayoutFloat32();
public static final LayoutFloat64 Float64 = new LayoutFloat64(); public static final LayoutFloat64 FLOAT_64 = new LayoutFloat64();
public static final LayoutGuid Guid = new LayoutGuid(); public static final LayoutGuid GUID = new LayoutGuid();
public static final LayoutArray ImmutableArray = new LayoutArray(true); public static final LayoutArray ImmutableArray = new LayoutArray(true);
public static final LayoutNullable ImmutableNullable = new LayoutNullable(true); public static final LayoutNullable ImmutableNullable = new LayoutNullable(true);
public static final LayoutObject ImmutableObject = new LayoutObject(true); public static final LayoutObject ImmutableObject = new LayoutObject(true);
@@ -31,10 +31,10 @@ public abstract class LayoutTypes {
public static final LayoutTypedSet ImmutableTypedSet = new LayoutTypedSet(true); public static final LayoutTypedSet ImmutableTypedSet = new LayoutTypedSet(true);
public static final LayoutTypedTuple ImmutableTypedTuple = new LayoutTypedTuple(true); public static final LayoutTypedTuple ImmutableTypedTuple = new LayoutTypedTuple(true);
public static final LayoutUDT ImmutableUDT = new LayoutUDT(true); public static final LayoutUDT ImmutableUDT = new LayoutUDT(true);
public static final LayoutInt16 Int16 = new LayoutInt16(); public static final LayoutInt16 INT_16 = new LayoutInt16();
public static final LayoutInt32 Int32 = new LayoutInt32(); public static final LayoutInt32 INT_32 = new LayoutInt32();
public static final LayoutInt64 Int64 = new LayoutInt64(); public static final LayoutInt64 INT_64 = new LayoutInt64();
public static final LayoutInt8 Int8 = new LayoutInt8(); public static final LayoutInt8 INT_8 = new LayoutInt8();
public static final LayoutMongoDbObjectId MongoDbObjectId = new LayoutMongoDbObjectId(); public static final LayoutMongoDbObjectId MongoDbObjectId = new LayoutMongoDbObjectId();
public static final LayoutNull Null = new LayoutNull(); public static final LayoutNull Null = new LayoutNull();
public static final LayoutNullable Nullable = new LayoutNullable(false); public static final LayoutNullable Nullable = new LayoutNullable(false);
@@ -47,11 +47,11 @@ public abstract class LayoutTypes {
public static final LayoutTypedSet TypedSet = new LayoutTypedSet(false); public static final LayoutTypedSet TypedSet = new LayoutTypedSet(false);
public static final LayoutTypedTuple TypedTuple = new LayoutTypedTuple(false); public static final LayoutTypedTuple TypedTuple = new LayoutTypedTuple(false);
public static final LayoutUDT UDT = new LayoutUDT(false); public static final LayoutUDT UDT = new LayoutUDT(false);
public static final LayoutUInt16 UInt16 = new LayoutUInt16(); public static final LayoutUInt16 UINT_16 = new LayoutUInt16();
public static final LayoutUInt32 UInt32 = new LayoutUInt32(); public static final LayoutUInt32 UINT_32 = new LayoutUInt32();
public static final LayoutUInt64 UInt64 = new LayoutUInt64(); public static final LayoutUInt64 UINT_64 = new LayoutUInt64();
public static final LayoutUInt8 UInt8 = new LayoutUInt8(); public static final LayoutUInt8 UINT_8 = new LayoutUInt8();
public static final LayoutUnixDateTime UnixDateTime = new LayoutUnixDateTime(); public static final LayoutUnixDateTime UNIX_DATE_TIME = new LayoutUnixDateTime();
public static final LayoutUtf8 Utf8 = new LayoutUtf8(); public static final LayoutUtf8 Utf8 = new LayoutUtf8();
public static final LayoutVarInt VarInt = new LayoutVarInt(); public static final LayoutVarInt VarInt = new LayoutVarInt();
public static final LayoutVarUInt VarUInt = new LayoutVarUInt(); public static final LayoutVarUInt VarUInt = new LayoutVarUInt();

View File

@@ -68,7 +68,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
// Perform the move. // Perform the move.
Reference<RowCursor> tempReference_dstEdit = Reference<RowCursor> tempReference_dstEdit =
new Reference<RowCursor>(dstEdit); new Reference<RowCursor>(dstEdit);
b.get().TypedCollectionMoveField(tempReference_dstEdit, sourceEdit, RowOptions.forValue(options)); b.get().TypedCollectionMoveField(tempReference_dstEdit, sourceEdit, RowOptions.from(options));
dstEdit = tempReference_dstEdit.get(); dstEdit = tempReference_dstEdit.get();
// TODO: it would be "better" if the destinationScope were updated to point to the // TODO: it would be "better" if the destinationScope were updated to point to the

View File

@@ -4,56 +4,79 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.core.Json;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId; import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.google.common.base.Strings;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@JsonSerialize(using = TypeArgumentList.JsonSerializer.class)
public final class TypeArgumentList {
public final class TypeArgumentList
{
public static final TypeArgumentList EMPTY = new TypeArgumentList(); public static final TypeArgumentList EMPTY = new TypeArgumentList();
private final TypeArgument[] args; private final TypeArgument[] args;
private final SchemaId schemaId; private final SchemaId schemaId;
private TypeArgumentList() { /**
this.args = new TypeArgument[] {}; * Initializes a new instance of the {@link TypeArgumentList} class
this.schemaId = SchemaId.NONE; *
} * @param args arguments in the list
*/
public TypeArgumentList(TypeArgument[] args) { public TypeArgumentList(@Nonnull final TypeArgument... args) {
checkArgument(args != null); checkNotNull(args);
this.args = args; this.args = args;
this.schemaId = SchemaId.INVALID; this.schemaId = SchemaId.INVALID;
} }
/** /**
* Initializes a new instance of the {@link TypeArgumentList} struct. * Initializes a new instance of the {@link TypeArgumentList} class
* *
* @param schemaId For UDT fields, the schema id of the nested layout. * @param schemaId for UDT fields, the schema id of the nested layout
*/ */
public TypeArgumentList(SchemaId schemaId, TypeArgument...args) { public TypeArgumentList(@Nonnull final SchemaId schemaId) {
this.args = args.length == 0 ? EMPTY.args : args; checkNotNull(schemaId);
this.args = EMPTY.args;
this.schemaId = schemaId; this.schemaId = schemaId;
} }
private TypeArgumentList() {
this.args = new TypeArgument[] {};
this.schemaId = SchemaId.INVALID;
}
/**
* Number of elements in this {@link TypeArgumentList}
* <p>
* @return number of arguments in the list
*/
public int count() { public int count() {
return this.args.length; return this.args.length;
} }
/** /**
* For UDT fields, the schema id of the nested layout. * Stream for iterating over elements in this {@link TypeArgumentList}
* <p>
* @return a stream for iterating over elements in this {@link TypeArgumentList}
*/ */
public SchemaId schemaId() { public Stream<TypeArgument> elements() {
return this.schemaId; if (this.args.length == 0) {
} return Stream.empty();
}
/** return StreamSupport.stream(Arrays.spliterator(this.args), false);
* Gets an enumerator for this span.
*/
public Enumerator GetEnumerator() {
return new Enumerator(this.args);
} }
public boolean equals(TypeArgumentList other) { public boolean equals(TypeArgumentList other) {
@@ -71,8 +94,14 @@ public final class TypeArgumentList
return other instanceof TypeArgumentList && this.equals((TypeArgumentList) other); return other instanceof TypeArgumentList && this.equals((TypeArgumentList) other);
} }
public TypeArgument get(int i) { /**
return this.args[i].clone(); * Element at the specified position in this {@link TypeArgumentList}
* <p>
* @param index index of the element to return
* @return element at the specified position in this {@link TypeArgumentList}
*/
public TypeArgument get(int index) {
return this.args[index];
} }
@Override @Override
@@ -88,89 +117,36 @@ public final class TypeArgumentList
return hash; return hash;
} }
public static boolean opEquals(TypeArgumentList left, TypeArgumentList right) { /**
return left.equals(right); * For UDT fields, the schema id of the nested layout.
} */
public SchemaId schemaId() {
public static boolean opNotEquals(TypeArgumentList left, TypeArgumentList right) { return this.schemaId;
return !left.equals(right);
} }
@Override @Override
public String toString() { public String toString() {
return Json.toString(this);
if (this.schemaId.equals(SchemaId.INVALID)) {
return String.format("<%1$s>", this.schemaId().toString());
}
if (this.args == null || this.args == null ? null : this.args.length == 0) {
return "";
}
return String.format("<%1$s>", tangible.StringHelper.join(", ", this.args));
} }
/** static class JsonSerializer extends StdSerializer<TypeArgumentList> {
* Enumerates the elements of a {@link TypeArgumentList}.
*/
//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 struct Enumerator
public final static class Enumerator {
/**
* The next index to yield.
*/
private int index;
/**
* The list being enumerated.
*/
private TypeArgument[] list;
/** private JsonSerializer() {
* Initializes a new instance of the {@link Enumerator} struct. super(TypeArgumentList.class);
*
* @param list The list to enumerate.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Enumerator(TypeArgument[] list)
public Enumerator() {
} }
public Enumerator(TypeArgument[] list) { @Override
this.list = list; public void serialize(TypeArgumentList value, JsonGenerator generator, SerializerProvider provider) throws IOException {
this.index = -1;
}
/** generator.writeStartObject();
* Advances the enumerator to the next element of the span. generator.writeObjectField("schemaId", value.schemaId);
*/ generator.writeArrayFieldStart("args");
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() for (TypeArgument element : value.args) {
public boolean MoveNext() { generator.writeString(element.toString());
int i = this.index + 1;
if (i < this.list.length) {
this.index = i;
return true;
} }
return false; generator.writeEndArray();
}
/**
* Gets the element at the current position of the enumerator.
*/
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public ref readonly TypeArgument Current
// {
// [MethodImpl(MethodImplOptions.AggressiveInlining)] get => ref this.list[this.index];
// }
public Enumerator clone() {
Enumerator varCopy = new Enumerator();
varCopy.list = this.list.clone();
varCopy.index = this.index;
return varCopy;
} }
} }
} }

View File

@@ -4,10 +4,13 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
import java.util.HashMap;
/** /**
* Describes the desired behavior when writing a {@link LayoutType}. * Describes the desired behavior when writing a {@link LayoutType}.
*/ */
public enum UpdateOptions { public enum UpdateOptions {
None(0), None(0),
/** /**
@@ -46,26 +49,26 @@ public enum UpdateOptions {
public static final int SIZE = java.lang.Integer.SIZE; public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, UpdateOptions> mappings; private static java.util.HashMap<Integer, UpdateOptions> mappings;
private int intValue; private int value;
UpdateOptions(int value) { UpdateOptions(int value) {
intValue = value; this.value = value;
getMappings().put(value, this); mappings().put(value, this);
} }
public int getValue() { public int value() {
return intValue; return this.value;
} }
public static UpdateOptions forValue(int value) { public static UpdateOptions from(int value) {
return getMappings().get(value); return mappings().get(value);
} }
private static java.util.HashMap<Integer, UpdateOptions> getMappings() { private static java.util.HashMap<Integer, UpdateOptions> mappings() {
if (mappings == null) { if (mappings == null) {
synchronized (UpdateOptions.class) { synchronized (UpdateOptions.class) {
if (mappings == null) { if (mappings == null) {
mappings = new java.util.HashMap<Integer, UpdateOptions>(); mappings = new HashMap<>();
} }
} }
} }

View File

@@ -230,7 +230,7 @@ public final class BsonRowGenerator implements Closeable {
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
//ORIGINAL LINE: d128 = unchecked(Decimal128.FromIEEEBits((ulong)f128.High, (ulong)f128.Low)); //ORIGINAL LINE: d128 = unchecked(Decimal128.FromIEEEBits((ulong)f128.High, (ulong)f128.Low));
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
d128 = Decimal128.FromIEEEBits((long)f128.High, (long)f128.Low); d128 = Decimal128.FromIEEEBits((long) f128.high(), (long) f128.low());
} }
this.writer.WriteDecimal128(d128); this.writer.WriteDecimal128(d128);

View File

@@ -42,8 +42,8 @@ public class RowBufferUnitTests {
private void RoundTripVarInt(short s) { private void RoundTripVarInt(short s) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s); //ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s);
long encoded = RowBuffer.RotateSignToLsb(s); long encoded = RowBuffer.rotateSignToLsb(s);
long decoded = RowBuffer.RotateSignToMsb(encoded); long decoded = RowBuffer.rotateSignToMsb(encoded);
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
//ORIGINAL LINE: short t = unchecked((short)decoded); //ORIGINAL LINE: short t = unchecked((short)decoded);
short t = (short)decoded; short t = (short)decoded;
@@ -53,8 +53,8 @@ public class RowBufferUnitTests {
private void RoundTripVarInt(int s) { private void RoundTripVarInt(int s) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s); //ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s);
long encoded = RowBuffer.RotateSignToLsb(s); long encoded = RowBuffer.rotateSignToLsb(s);
long decoded = RowBuffer.RotateSignToMsb(encoded); long decoded = RowBuffer.rotateSignToMsb(encoded);
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context: // TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
//ORIGINAL LINE: int t = unchecked((int)decoded); //ORIGINAL LINE: int t = unchecked((int)decoded);
int t = (int)decoded; int t = (int)decoded;
@@ -64,8 +64,8 @@ public class RowBufferUnitTests {
private void RoundTripVarInt(long s) { private void RoundTripVarInt(long s) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s); //ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s);
long encoded = RowBuffer.RotateSignToLsb(s); long encoded = RowBuffer.rotateSignToLsb(s);
long decoded = RowBuffer.RotateSignToMsb(encoded); long decoded = RowBuffer.rotateSignToMsb(encoded);
Assert.AreEqual(s, decoded, "Value: {0}", s); Assert.AreEqual(s, decoded, "Value: {0}", s);
} }
} }

View File

@@ -17,10 +17,10 @@ public class SchemaIdUnitTests {
SchemaId b = new SchemaId(2); SchemaId b = new SchemaId(2);
SchemaId c = new SchemaId(); SchemaId c = new SchemaId();
assert 1 == a.id(); assert 1 == a.value();
assert 2 == b.id(); assert 2 == b.value();
assert SchemaId.INVALID == c.clone(); assert SchemaId.INVALID == c.clone();
assert 2 != a.id(); assert 2 != a.value();
assert a.clone() != b.clone(); assert a.clone() != b.clone();
assert SchemaId.opEquals(a.clone(), a.clone()); assert SchemaId.opEquals(a.clone(), a.clone());
assert SchemaId.opNotEquals(a.clone(), b.clone()); assert SchemaId.opNotEquals(a.clone(), b.clone());