Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-09-05 01:15:35 -07:00
parent 9d2e1c80f3
commit 0f0dfc8fc4
26 changed files with 1157 additions and 1121 deletions

View File

@@ -56,7 +56,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
}
private Utf8String(@Nonnull final ByteBuf buffer, final int decodedLength) {
checkNotNull(buffer);
checkNotNull(buffer, "expected non-null buffer");
this.buffer = buffer.asReadOnly();
this.length = decodedLength;
}
@@ -75,114 +75,6 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return this.buffer == null;
}
/**
* Returns a reference to the read-only {@link ByteBuf} holding the content of this {@link Utf8String}
* <p>
* A value of {@code null} is returns, if this {@link Utf8String} is null.
* @return reference to the read-only {@link ByteBuf} holding the content of this {@link Utf8String}.
*/
@Nullable
public ByteBuf content() {
return this.buffer;
}
/**
* Creates a deep copy of this {@link Utf8String}
*/
@Override
public Utf8String copy() {
throw new UnsupportedOperationException();
}
/**
* Duplicates this {@link Utf8String}
* <p>
* Be aware that this will not automatically call {@link #retain()}.
*/
@Override
public Utf8String duplicate() {
throw new UnsupportedOperationException();
}
/**
* Duplicates this {@link Utf8String}
* <p>
* This method returns a retained duplicate unlike {@link #duplicate()}.
*
* @see ByteBuf#retainedDuplicate()
*/
@Override
public Utf8String retainedDuplicate() {
throw new UnsupportedOperationException();
}
/**
* Returns a new {@link Utf8String} which contains the specified {@code content}
*
* @param content text of the {@link Utf8String} to be created.
*/
@Override
public Utf8String replace(ByteBuf content) {
throw new UnsupportedOperationException();
}
/**
* Returns the reference count of this {@link Utf8String}
* <p>
* If {@code 0}, it means this object has been deallocated.
*/
@Override
public int refCnt() {
return this.buffer.refCnt();
}
@Override
public Utf8String retain() {
this.buffer.retain();
return this;
}
@Override
public Utf8String retain(int increment) {
this.buffer.retain(increment);
return this;
}
@Override
public Utf8String touch() {
this.buffer.touch();
return this;
}
@Override
public Utf8String touch(Object hint) {
this.buffer.touch(hint);
return this;
}
/**
* Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at
* {@code 0}.
*
* @return {@code true} if and only if the reference count became {@code 0} and this object has been deallocated
*/
@Override
public boolean release() {
return this.buffer.release();
}
/**
* Decreases the reference count by the specified {@code decrement} and deallocates this object if the reference
* count reaches at {@code 0}.
*
* @param decrement
* @return {@code true} if and only if the reference count became {@code 0} and this object has been deallocated
*/
@Override
public boolean release(int decrement) {
return false;
}
@Override
public char charAt(final int index) {
throw new UnsupportedOperationException();
@@ -208,7 +100,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
public final int compareTo(@Nonnull final Utf8String other) {
checkNotNull(other);
checkNotNull(other, "expected non-null other");
if (other.buffer == this.buffer) {
return 0;
@@ -257,6 +149,35 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return length - otherLength;
}
/**
* Returns a reference to the read-only {@link ByteBuf} holding the content of this {@link Utf8String}
* <p>
* A value of {@code null} is returns, if this {@link Utf8String} is null.
* @return reference to the read-only {@link ByteBuf} holding the content of this {@link Utf8String}.
*/
@Nullable
public ByteBuf content() {
return this.buffer;
}
/**
* Creates a deep copy of this {@link Utf8String}
*/
@Override
public Utf8String copy() {
throw new UnsupportedOperationException();
}
/**
* Duplicates this {@link Utf8String}
* <p>
* Be aware that this will not automatically call {@link #retain()}.
*/
@Override
public Utf8String duplicate() {
throw new UnsupportedOperationException();
}
public final boolean equals(ByteBuf other) {
return this.buffer.equals(other);
}
@@ -298,6 +219,35 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return false;
}
/**
* Creates a new {@link Utf8String} from a {@link ByteBuf} with UTF-8 character validation
* <p>
* The {@link Utf8String} created retains the {@link ByteBuf}. (No data is transferred.)
*
* @param buffer The {@link ByteBuf} to validate and assign to the {@link Utf8String} created.
* @return A {@link Utf8String} instance, if the @{code buffer} validates or a value of @{link Optional#empty}
* otherwise.
*/
@Nonnull
public static Optional<Utf8String> from(@Nonnull final ByteBuf buffer) {
checkNotNull(buffer, "expected non-null buffer");
return Utf8.isWellFormed(buffer.array()) ? Optional.of(new Utf8String(buffer)) : Optional.empty();
}
/**
* Creates a new {@link Utf8String} from a {@link ByteBuf} without UTF-8 character validation
* <p>
* The {@link Utf8String} created retains the {@link ByteBuf}. (No data is transferred.)
*
* @param buffer The {@link ByteBuf} to assign to the {@link Utf8String} created.
* @return a new {@link Utf8String}
*/
@Nonnull
public static Utf8String fromUnsafe(@Nonnull ByteBuf buffer) {
checkNotNull(buffer, "expected non-null buffer");
return new Utf8String(buffer);
}
@Override
public int hashCode() {
return this.buffer.hashCode();
@@ -312,6 +262,73 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return this.length;
}
/**
* Returns the reference count of this {@link Utf8String}
* <p>
* If {@code 0}, it means this object has been deallocated.
*/
@Override
public int refCnt() {
return this.buffer.refCnt();
}
/**
* Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at
* {@code 0}.
*
* @return {@code true} if and only if the reference count became {@code 0} and this object has been deallocated
*/
@Override
public boolean release() {
return this.buffer.release();
}
/**
* Decreases the reference count by the specified {@code decrement} and deallocates this object if the reference
* count reaches at {@code 0}.
*
* @param decrement
* @return {@code true} if and only if the reference count became {@code 0} and this object has been deallocated
*/
@Override
public boolean release(int decrement) {
return false;
}
/**
* Returns a new {@link Utf8String} which contains the specified {@code content}
*
* @param content text of the {@link Utf8String} to be created.
*/
@Override
public Utf8String replace(ByteBuf content) {
throw new UnsupportedOperationException();
}
@Override
public Utf8String retain() {
this.buffer.retain();
return this;
}
@Override
public Utf8String retain(int increment) {
this.buffer.retain(increment);
return this;
}
/**
* Duplicates this {@link Utf8String}
* <p>
* This method returns a retained duplicate unlike {@link #duplicate()}.
*
* @see ByteBuf#retainedDuplicate()
*/
@Override
public Utf8String retainedDuplicate() {
throw new UnsupportedOperationException();
}
@Override
public CharSequence subSequence(int start, int end) {
checkArgument(start < 0 || end < 0 || start > end || end > this.length, "start: %s, end: %s", start, end);
@@ -328,6 +345,18 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return this.buffer.getCharSequence(0, this.buffer.capacity(), UTF_8).toString();
}
@Override
public Utf8String touch() {
this.buffer.touch();
return this;
}
@Override
public Utf8String touch(Object hint) {
this.buffer.touch(hint);
return this;
}
/**
* Creates a {@link Utf8String} from a UTF16 encoding string
* <p>
@@ -356,35 +385,6 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return new Utf8String(buffer, string.length());
}
/**
* Creates a new {@link Utf8String} from a {@link ByteBuf} with UTF-8 character validation
* <p>
* The {@link Utf8String} created retains the {@link ByteBuf}. (No data is transferred.)
*
* @param buffer The {@link ByteBuf} to validate and assign to the {@link Utf8String} created.
* @return A {@link Utf8String} instance, if the @{code buffer} validates or a value of @{link Optional#empty}
* otherwise.
*/
@Nonnull
public static Optional<Utf8String> from(@Nonnull final ByteBuf buffer) {
checkNotNull(buffer);
return Utf8.isWellFormed(buffer.array()) ? Optional.of(new Utf8String(buffer)) : Optional.empty();
}
/**
* Creates a new {@link Utf8String} from a {@link ByteBuf} without UTF-8 character validation
* <p>
* The {@link Utf8String} created retains the {@link ByteBuf}. (No data is transferred.)
*
* @param buffer The {@link ByteBuf} to assign to the {@link Utf8String} created.
* @return a new {@link Utf8String}
*/
@Nonnull
public static Utf8String fromUnsafe(@Nonnull ByteBuf buffer) {
checkNotNull(buffer);
return new Utf8String(buffer);
}
private static int decodedLength(final ByteBuf buffer) {
final CodePointIterable iterable = new CodePointIterable(buffer, -1);
@@ -498,7 +498,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
@Override
public boolean tryAdvance(@Nonnull final IntConsumer action) {
checkNotNull(action);
checkNotNull(action, "expected non-null action");
if (this.hasNext()) {
action.accept(this.next());

View File

@@ -26,7 +26,7 @@ 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);
public static final int BYTES = 2 * Long.BYTES;
private final long high;
private final long low;

View File

@@ -386,7 +386,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope =
new Out<RowCursor>();
this.row.WriteSparseObject(tempRef_cursor, scopeType, UpdateOptions.Upsert, tempOut_nestedScope);
this.row.writeSparseObject(tempRef_cursor, scopeType, UpdateOptions.Upsert, tempOut_nestedScope);
nestedScope = tempOut_nestedScope.get();
this.cursor = tempRef_cursor.argValue;
break;
@@ -398,7 +398,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope2 =
new Out<RowCursor>();
this.row.writeSparseArray(tempRef_cursor2, scopeType, UpdateOptions.Upsert, tempOut_nestedScope2);
this.row.WriteSparseArray(tempRef_cursor2, scopeType, UpdateOptions.Upsert, tempOut_nestedScope2);
nestedScope = tempOut_nestedScope2.get();
this.cursor = tempRef_cursor2.argValue;
break;
@@ -480,7 +480,7 @@ public final class RowWriter {
new Reference<RowCursor>(this.cursor);
Out<RowCursor> tempOut_nestedScope8 =
new Out<RowCursor>();
this.row.WriteNullable(tempRef_cursor8, scopeType, typeArg.typeArgs().clone(),
this.row.writeNullable(tempRef_cursor8, scopeType, typeArg.typeArgs().clone(),
UpdateOptions.Upsert, func != null, tempOut_nestedScope8);
nestedScope = tempOut_nestedScope8.get();
this.cursor = tempRef_cursor8.argValue;

View File

@@ -45,7 +45,7 @@ public final class LayoutArray extends LayoutIndexedScope {
return result;
}
b.writeSparseArray(edit, this, options, value);
b.WriteSparseArray(edit, this, options, value);
return Result.SUCCESS;
}
}

View File

@@ -203,7 +203,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return result;
}
b.get().WriteSparseBinary(edit, value, options);
b.get().writeSparseBinary(edit, value, options);
return Result.SUCCESS;
}
@@ -223,7 +223,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return result;
}
b.get().WriteSparseBinary(edit, value, options);
b.get().writeSparseBinary(edit, value, options);
return Result.SUCCESS;
}
@@ -259,7 +259,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
b.get().WriteVariableBinary(varOffset, value, exists, tempOut_shift);
b.get().writeVariableBinary(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);
@@ -287,7 +287,7 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
b.get().WriteVariableBinary(varOffset, value, exists, tempOut_shift);
b.get().writeVariableBinary(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);

View File

@@ -83,7 +83,7 @@ public final class LayoutBoolean extends LayoutType<Boolean> {
return result;
}
b.get().WriteSparseBool(edit, value, options);
b.get().writeSparseBoolean(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -87,7 +87,7 @@ public enum LayoutCode {
END_SCOPE((byte)70);
public static final int SIZE = Byte.SIZE;
public static final int BYTES = Byte.BYTES;
private static Map<Byte, LayoutCode> mappings;
private byte value;

View File

@@ -75,7 +75,7 @@ public final class LayoutDateTime extends LayoutType<DateTime> {
return result;
}
b.get().WriteSparseDateTime(edit, value, options);
b.get().writeSparseDateTime(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -74,7 +74,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

@@ -74,7 +74,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
return result;
}
b.get().WriteSparseFloat64(edit, value, options);
b.get().writeSparseFloat64(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -74,7 +74,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
return result;
}
b.get().WriteSparseInt16(edit, value, options);
b.get().writeSparseInt16(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -74,7 +74,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
return result;
}
b.get().WriteSparseInt32(edit, value, options);
b.get().writeSparseInt32(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -74,7 +74,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
return result;
}
b.get().WriteSparseInt64(edit, value, options);
b.get().writeSparseInt64(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -74,7 +74,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
return result;
}
b.get().WriteSparseInt8(edit, value, options);
b.get().writeSparseInt8(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -80,7 +80,7 @@ public final class LayoutNullable extends LayoutIndexedScope {
return result;
}
b.get().WriteNullable(edit, this, typeArgs.clone(), options, hasValue, value.clone());
b.get().writeNullable(edit, this, typeArgs.clone(), options, hasValue, value.clone());
return Result.SUCCESS;
}

View File

@@ -79,7 +79,7 @@ public abstract class LayoutScope extends LayoutType {
return result;
}
b.DeleteSparse(edit);
b.deleteSparse(edit);
return Result.SUCCESS;
}

View File

@@ -127,7 +127,7 @@ public abstract class LayoutType<T> implements ILayoutType {
return result;
}
b.DeleteSparse(edit);
b.deleteSparse(edit);
return Result.SUCCESS;
}
@@ -245,19 +245,19 @@ public abstract class LayoutType<T> implements ILayoutType {
}
if (destinationScope.immutable()) {
b.DeleteSparse(srcEdit);
b.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
return Result.INSUFFICIENT_PERMISSIONS;
}
if (!srcEdit.cellTypeArgs().equals(elementType.typeArgs())) {
b.DeleteSparse(srcEdit);
b.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
return Result.TYPE_CONSTRAINT;
}
if (options == UpdateOptions.InsertAt) {
b.DeleteSparse(srcEdit);
b.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
return Result.TYPE_CONSTRAINT;
}
@@ -265,13 +265,13 @@ public abstract class LayoutType<T> implements ILayoutType {
// Prepare the insertion at the destination.
dstEdit.setAndGet(b.prepareSparseMove(destinationScope, srcEdit));
if ((options == UpdateOptions.Update) && (!dstEdit.get().exists())) {
b.DeleteSparse(srcEdit);
b.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
return Result.NOT_FOUND;
}
if ((options == UpdateOptions.Insert) && dstEdit.get().exists()) {
b.DeleteSparse(srcEdit);
b.deleteSparse(srcEdit);
dstEdit.setAndGet(null);
return Result.EXISTS;
}

View File

@@ -10,7 +10,7 @@ public abstract class LayoutTypes {
public static final LayoutArray ARRAY = new LayoutArray(false);
public static final LayoutBinary BINARY = new LayoutBinary();
public static final LayoutBoolean BOOLEAN = new LayoutBoolean(true);
public static final LayoutBoolean BooleanFalse = new LayoutBoolean(false);
public static final LayoutBoolean BOOLEAN_FALSE = new LayoutBoolean(false);
public static final LayoutDateTime DATE_TIME = new LayoutDateTime();
public static final LayoutDecimal DECIMAL = new LayoutDecimal();
public static final LayoutEndScope END_SCOPE = new LayoutEndScope();

View File

@@ -85,7 +85,7 @@ public final class LayoutUInt16 extends LayoutType<Short> {
return result;
}
b.get().WriteSparseUInt16(edit, value, options);
b.get().writeSparseUInt16(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -85,7 +85,7 @@ public final class LayoutUInt32 extends LayoutType<Integer> {
return result;
}
b.get().WriteSparseUInt32(edit, value, options);
b.get().writeSparseUInt32(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -85,7 +85,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
return result;
}
b.get().WriteSparseUInt64(edit, value, options);
b.get().writeSparseUInt64(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -85,7 +85,7 @@ public final class LayoutUInt8 extends LayoutType<Byte> {
return result;
}
b.get().WriteSparseUInt8(edit, value, options);
b.get().writeSparseUInt8(edit, value, options);
return Result.SUCCESS;
}

View File

@@ -43,7 +43,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
}
// Check if the search found the result.
b.get().DeleteSparse(patternScope);
b.get().deleteSparse(patternScope);
return Result.SUCCESS;
}

View File

@@ -80,7 +80,7 @@ public final class LayoutVarInt extends LayoutType<Long> {
return result;
}
b.get().WriteSparseVarInt(edit, value, options);
b.get().writeSparseVarInt(edit, value, options);
return Result.SUCCESS;
}
@@ -102,7 +102,7 @@ public final class LayoutVarInt extends LayoutType<Long> {
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
b.get().WriteVariableInt(varOffset, value, exists, tempOut_shift);
b.get().writeVariableInt(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);

View File

@@ -94,7 +94,7 @@ public final class LayoutVarUInt extends LayoutType<Long> {
return result;
}
b.get().WriteSparseVarUInt(edit, value, options);
b.get().writeSparseVarUInt(edit, value, options);
return Result.SUCCESS;
}
@@ -119,7 +119,7 @@ public final class LayoutVarUInt extends LayoutType<Long> {
col.getOffset());
int shift;
Out<Integer> tempOut_shift = new Out<Integer>();
b.get().WriteVariableUInt(varOffset, value, exists, tempOut_shift);
b.get().writeVariableUInt(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.get();
b.get().setBit(scope.get().start(), col.getNullBit().clone());
scope.get().metaOffset(scope.get().metaOffset() + shift);