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}.
*/
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
* encoding scheme.
*/
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;
private final long high;
private final long low;
/**
* 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 low the low-order 64 bits.
*/
public Float128() {
}
public Float128(long high, long low) {
this.High = high;
this.Low = low;
this.high = high;
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;
return varCopy;
/**
* The low-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID
* encoding scheme.
*/
public long low() {
return this.low;
}
}

View File

@@ -24,7 +24,7 @@ public final class HybridRowHeader {
*/
public HybridRowHeader(HybridRowVersion version, SchemaId schemaId) {
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 StringToken writePathToken;
private RowCursor() {
RowCursor() {
}
protected RowCursor clone() {
@@ -97,6 +97,11 @@ public final class RowCursor implements Cloneable {
return this.cellTypeArgs;
}
public RowCursor cellTypeArgs(TypeArgumentList value) {
this.cellTypeArgs = value;
return this;
}
/**
* For sized scopes (e.g. Typed Array), the number of elements.
*/

View File

@@ -4,6 +4,8 @@
package com.azure.data.cosmos.serialization.hybridrow;
import java.util.HashMap;
/**
* Describes the desired behavior when mutating a hybrid row.
*/
@@ -53,27 +55,27 @@ public enum RowOptions {
Delete(5);
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, RowOptions> mappings;
private int intValue;
private static HashMap<Integer, RowOptions> mappings;
private int value;
RowOptions(int value) {
intValue = value;
getMappings().put(value, this);
this.value = value;
mappings().put(value, this);
}
public int getValue() {
return intValue;
return this.value;
}
public static RowOptions forValue(int value) {
return getMappings().get(value);
public static RowOptions from(int value) {
return mappings().get(value);
}
private static java.util.HashMap<Integer, RowOptions> getMappings() {
private static HashMap<Integer, RowOptions> mappings() {
if (mappings == null) {
synchronized (RowOptions.class) {
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);
private static long MAX_VALUE = 0x00000000FFFFFFFFL;
private final int id;
private final int value;
/**
* 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) {
this.id = id;
private SchemaId(int value) {
this.value = value;
}
@Override
@@ -60,12 +60,12 @@ public final class SchemaId {
if (null == other) {
return false;
}
return this.id() == other.id();
return this.value() == other.value();
}
@Override
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}
*/
public int id() {
return this.id;
public int value() {
return this.value;
}
/**
@@ -82,13 +82,13 @@ public final class SchemaId {
*
* @return The integer value of this {@link SchemaId}
*/
public static SchemaId from(int id) {
return new SchemaId(id);
public static SchemaId from(int value) {
return new SchemaId(value);
}
@Override
public String toString() {
return String.valueOf(this.id());
return String.valueOf(this.value());
}
static final class JsonDeserializer extends StdDeserializer<SchemaId> {
@@ -119,7 +119,7 @@ public final class SchemaId {
@Override
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:
if (this.cursor.cellType() instanceof LayoutNullable) {
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();
Reference<RowBuffer> row = new Reference<>(this.row);
Reference<RowCursor> tempReference_nullableScope = new Reference<>(nullableScope);
@@ -744,7 +744,7 @@ public final class RowReader {
public RowReader ReadScope() {
Reference<RowCursor> tempReference_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();
Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(this.row);
@@ -763,7 +763,7 @@ public final class RowReader {
public <TContext> Result ReadScope(TContext context, ReaderFunc<TContext> func) {
Reference<RowCursor> tempReference_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();
Reference<RowBuffer> tempReference_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;
}
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());
return Result.Success;
}

View File

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

View File

@@ -59,7 +59,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
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());
return Result.Success;
}

View File

@@ -59,7 +59,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
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());
return Result.Success;
}

View File

@@ -59,7 +59,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
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());
return Result.Success;
}

View File

@@ -59,7 +59,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
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());
return Result.Success;
}

View File

@@ -50,7 +50,7 @@ public final class LayoutResolverNamespace extends LayoutResolver {
// ConcurrentDictionary method:
// 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 (this.layoutCache.TryGetValue(schemaId.id(), out layout)) {
if (this.layoutCache.TryGetValue(schemaId.value(), out layout)) {
return layout;
}
@@ -58,7 +58,7 @@ public final class LayoutResolverNamespace extends LayoutResolver {
if (SchemaId.opEquals(s.getSchemaId().clone(),
schemaId.clone())) {
layout = s.Compile(this.schemaNamespace);
layout = this.layoutCache.putIfAbsent(schemaId.id(), layout);
layout = this.layoutCache.putIfAbsent(schemaId.value(), layout);
return layout;
}
}
@@ -67,7 +67,7 @@ public final class LayoutResolverNamespace extends LayoutResolver {
if (layout != null) {
// TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET
// ConcurrentDictionary method:
boolean succeeded = this.layoutCache.TryAdd(schemaId.id(), layout);
boolean succeeded = this.layoutCache.TryAdd(schemaId.value(), layout);
checkState(succeeded);
return layout;
}

View File

@@ -105,7 +105,7 @@ public abstract class LayoutScope extends LayoutType {
return result;
}
value.setAndGet(b.get().SparseIteratorReadScope(edit,
value.setAndGet(b.get().sparseIteratorReadScope(edit,
this.Immutable || edit.get().immutable() || edit.get().scopeType().isUniqueScope()).clone());
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);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.Count7BitEncodedUInt(value.count());
lenInBytes += RowBuffer.count7BitEncodedUInt(value.count());
for (TypeArgument arg : value) {
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);
//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 += row.get().Write7BitEncodedUInt(offset + lenInBytes, value.count());
lenInBytes += row.get().write7BitEncodedUInt(offset + lenInBytes, value.count());
for (TypeArgument arg : value) {
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.
*/
public boolean isImmutable() {
return immutable;
return this.immutable;
}
/**
@@ -306,37 +306,38 @@ public abstract class LayoutType<T> implements ILayoutType {
* @param options The write options.
* @return Success if the write is permitted, the error code otherwise.
*/
public static Result prepareSparseWrite(Reference<RowBuffer> b, Reference<RowCursor> edit,
TypeArgument typeArg, UpdateOptions options) {
if (edit.get().immutable() || (edit.get().scopeType().isUniqueScope() && !edit.get().deferUniqueIndex())) {
public static Result prepareSparseWrite(
RowBuffer b, RowCursor edit, TypeArgument typeArg, UpdateOptions options
) {
if (edit.immutable() || (edit.scopeType().isUniqueScope() && !edit.deferUniqueIndex())) {
return Result.InsufficientPermissions;
}
if (edit.get().scopeType().isFixedArity() && !(edit.get().scopeType() instanceof LayoutNullable)) {
if ((edit.get().index() < edit.get().scopeTypeArgs().count()) && !typeArg.equals(edit.get().scopeTypeArgs().get(edit.get().index()))) {
if (edit.scopeType().isFixedArity() && !(edit.scopeType() instanceof LayoutNullable)) {
if ((edit.index() < edit.scopeTypeArgs().count()) && !typeArg.equals(edit.scopeTypeArgs().get(edit.index()))) {
return Result.TypeConstraint;
}
} else if (edit.get().scopeType() instanceof LayoutTypedMap) {
if (!((typeArg.type() instanceof LayoutTypedTuple) && typeArg.typeArgs().equals(edit.get().scopeTypeArgs()))) {
} else if (edit.scopeType() instanceof LayoutTypedMap) {
if (!((typeArg.type() instanceof LayoutTypedTuple) && typeArg.typeArgs().equals(edit.scopeTypeArgs()))) {
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;
}
if ((options == UpdateOptions.InsertAt) && edit.get().scopeType().isFixedArity()) {
if ((options == UpdateOptions.InsertAt) && edit.scopeType().isFixedArity()) {
return Result.TypeConstraint;
}
if ((options == UpdateOptions.InsertAt) && !edit.get().scopeType().isFixedArity()) {
edit.get().exists = false; // InsertAt never overwrites an existing item.
if ((options == UpdateOptions.InsertAt) && !edit.scopeType().isFixedArity()) {
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;
}
if ((options == UpdateOptions.Insert) && edit.get().exists()) {
if ((options == UpdateOptions.Insert) && edit.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.
*/
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);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.Count7BitEncodedUInt(value.count());
lenInBytes += RowBuffer.count7BitEncodedUInt(value.count());
for (TypeArgument arg : value) {
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);
//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 += row.get().Write7BitEncodedUInt(offset + lenInBytes, value.count());
lenInBytes += row.get().write7BitEncodedUInt(offset + lenInBytes, value.count());
for (TypeArgument arg : value) {
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 LayoutBoolean Boolean = new LayoutBoolean(true);
public static final LayoutBoolean BooleanFalse = new LayoutBoolean(false);
public static final LayoutDateTime DateTime = new LayoutDateTime();
public static final LayoutDecimal Decimal = new LayoutDecimal();
public static final LayoutDateTime DATE_TIME = new LayoutDateTime();
public static final LayoutDecimal DECIMAL = new LayoutDecimal();
public static final LayoutEndScope EndScope = new LayoutEndScope();
public static final LayoutFloat128 Float128 = new LayoutFloat128();
public static final LayoutFloat32 Float32 = new LayoutFloat32();
public static final LayoutFloat64 Float64 = new LayoutFloat64();
public static final LayoutGuid Guid = new LayoutGuid();
public static final LayoutFloat128 FLOAT_128 = new LayoutFloat128();
public static final LayoutFloat32 FLOAT_32 = new LayoutFloat32();
public static final LayoutFloat64 FLOAT_64 = new LayoutFloat64();
public static final LayoutGuid GUID = new LayoutGuid();
public static final LayoutArray ImmutableArray = new LayoutArray(true);
public static final LayoutNullable ImmutableNullable = new LayoutNullable(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 LayoutTypedTuple ImmutableTypedTuple = new LayoutTypedTuple(true);
public static final LayoutUDT ImmutableUDT = new LayoutUDT(true);
public static final LayoutInt16 Int16 = new LayoutInt16();
public static final LayoutInt32 Int32 = new LayoutInt32();
public static final LayoutInt64 Int64 = new LayoutInt64();
public static final LayoutInt8 Int8 = new LayoutInt8();
public static final LayoutInt16 INT_16 = new LayoutInt16();
public static final LayoutInt32 INT_32 = new LayoutInt32();
public static final LayoutInt64 INT_64 = new LayoutInt64();
public static final LayoutInt8 INT_8 = new LayoutInt8();
public static final LayoutMongoDbObjectId MongoDbObjectId = new LayoutMongoDbObjectId();
public static final LayoutNull Null = new LayoutNull();
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 LayoutTypedTuple TypedTuple = new LayoutTypedTuple(false);
public static final LayoutUDT UDT = new LayoutUDT(false);
public static final LayoutUInt16 UInt16 = new LayoutUInt16();
public static final LayoutUInt32 UInt32 = new LayoutUInt32();
public static final LayoutUInt64 UInt64 = new LayoutUInt64();
public static final LayoutUInt8 UInt8 = new LayoutUInt8();
public static final LayoutUnixDateTime UnixDateTime = new LayoutUnixDateTime();
public static final LayoutUInt16 UINT_16 = new LayoutUInt16();
public static final LayoutUInt32 UINT_32 = new LayoutUInt32();
public static final LayoutUInt64 UINT_64 = new LayoutUInt64();
public static final LayoutUInt8 UINT_8 = new LayoutUInt8();
public static final LayoutUnixDateTime UNIX_DATE_TIME = new LayoutUnixDateTime();
public static final LayoutUtf8 Utf8 = new LayoutUtf8();
public static final LayoutVarInt VarInt = new LayoutVarInt();
public static final LayoutVarUInt VarUInt = new LayoutVarUInt();

View File

@@ -68,7 +68,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
// Perform the move.
Reference<RowCursor> tempReference_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();
// 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;
import com.azure.data.cosmos.core.Json;
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.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();
private final TypeArgument[] args;
private final SchemaId schemaId;
private TypeArgumentList() {
this.args = new TypeArgument[] {};
this.schemaId = SchemaId.NONE;
}
public TypeArgumentList(TypeArgument[] args) {
checkArgument(args != null);
/**
* Initializes a new instance of the {@link TypeArgumentList} class
*
* @param args arguments in the list
*/
public TypeArgumentList(@Nonnull final TypeArgument... args) {
checkNotNull(args);
this.args = args;
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) {
this.args = args.length == 0 ? EMPTY.args : args;
public TypeArgumentList(@Nonnull final SchemaId schemaId) {
checkNotNull(schemaId);
this.args = EMPTY.args;
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() {
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() {
return this.schemaId;
}
/**
* Gets an enumerator for this span.
*/
public Enumerator GetEnumerator() {
return new Enumerator(this.args);
public Stream<TypeArgument> elements() {
if (this.args.length == 0) {
return Stream.empty();
}
return StreamSupport.stream(Arrays.spliterator(this.args), false);
}
public boolean equals(TypeArgumentList other) {
@@ -71,8 +94,14 @@ public final class TypeArgumentList
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
@@ -88,89 +117,36 @@ public final class TypeArgumentList
return hash;
}
public static boolean opEquals(TypeArgumentList left, TypeArgumentList right) {
return left.equals(right);
}
public static boolean opNotEquals(TypeArgumentList left, TypeArgumentList right) {
return !left.equals(right);
/**
* For UDT fields, the schema id of the nested layout.
*/
public SchemaId schemaId() {
return this.schemaId;
}
@Override
public String toString() {
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));
return Json.toString(this);
}
/**
* 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;
static class JsonSerializer extends StdSerializer<TypeArgumentList> {
/**
* Initializes a new instance of the {@link Enumerator} struct.
*
* @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() {
private JsonSerializer() {
super(TypeArgumentList.class);
}
public Enumerator(TypeArgument[] list) {
this.list = list;
this.index = -1;
}
@Override
public void serialize(TypeArgumentList value, JsonGenerator generator, SerializerProvider provider) throws IOException {
/**
* Advances the enumerator to the next element of the span.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext()
public boolean MoveNext() {
int i = this.index + 1;
if (i < this.list.length) {
this.index = i;
return true;
generator.writeStartObject();
generator.writeObjectField("schemaId", value.schemaId);
generator.writeArrayFieldStart("args");
for (TypeArgument element : value.args) {
generator.writeString(element.toString());
}
return false;
}
/**
* 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;
generator.writeEndArray();
}
}
}

View File

@@ -4,10 +4,13 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts;
import java.util.HashMap;
/**
* Describes the desired behavior when writing a {@link LayoutType}.
*/
public enum UpdateOptions {
None(0),
/**
@@ -46,26 +49,26 @@ public enum UpdateOptions {
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, UpdateOptions> mappings;
private int intValue;
private int value;
UpdateOptions(int value) {
intValue = value;
getMappings().put(value, this);
this.value = value;
mappings().put(value, this);
}
public int getValue() {
return intValue;
public int value() {
return this.value;
}
public static UpdateOptions forValue(int value) {
return getMappings().get(value);
public static UpdateOptions from(int value) {
return mappings().get(value);
}
private static java.util.HashMap<Integer, UpdateOptions> getMappings() {
private static java.util.HashMap<Integer, UpdateOptions> mappings() {
if (mappings == null) {
synchronized (UpdateOptions.class) {
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:
//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:
d128 = Decimal128.FromIEEEBits((long)f128.High, (long)f128.Low);
d128 = Decimal128.FromIEEEBits((long) f128.high(), (long) f128.low());
}
this.writer.WriteDecimal128(d128);

View File

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

View File

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