mirror of
https://github.com/microsoft/HybridRow.git
synced 2026-01-29 22:33:25 +00:00
Progressed on port from dotnet to java.
This commit is contained in:
@@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
|||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.base.Utf8;
|
import com.google.common.base.Utf8;
|
||||||
|
import com.google.common.collect.Streams;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufHolder;
|
import io.netty.buffer.ByteBufHolder;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
@@ -145,30 +146,14 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
|
|||||||
return other == null ? 0 : -1;
|
return other == null ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int length = this.length();
|
// TODO: DANOBLE: Consider optimizing this method based on the cost of zipping boxed int streams
|
||||||
final int otherLength = other.length();
|
|
||||||
final int limit = Math.min(length, otherLength);
|
|
||||||
|
|
||||||
if (limit > 0) {
|
Optional<Integer> compare = Streams
|
||||||
|
.zip(this.codePoints().boxed(), other.codePoints().boxed(), (x, y) -> x - y)
|
||||||
|
.filter(delta -> delta != 0)
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
final CodePointIterable iterable = new CodePointIterable(this.buffer, this.utf16CodeUnitCount.get());
|
return compare.orElse(this.length() - other.length());
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
for (int codePoint : iterable) {
|
|
||||||
|
|
||||||
final int otherCodePoint = other.codePointAt(index++);
|
|
||||||
|
|
||||||
if (codePoint != otherCodePoint) {
|
|
||||||
return codePoint - otherCodePoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index >= limit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return length - otherLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -547,7 +532,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
|
|||||||
private int skip = 0;
|
private int skip = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean process(byte value) throws Exception {
|
public boolean process(byte value) {
|
||||||
|
|
||||||
if (this.skip > 0) {
|
if (this.skip > 0) {
|
||||||
this.skip--;
|
this.skip--;
|
||||||
@@ -678,7 +663,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
|
|||||||
|
|
||||||
if (!Character.isDefined(this.codePoint)) {
|
if (!Character.isDefined(this.codePoint)) {
|
||||||
this.codePoint = REPLACEMENT_CHARACTER;
|
this.codePoint = REPLACEMENT_CHARACTER;
|
||||||
};
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// Licensed under the MIT License.
|
|
||||||
|
|
||||||
package tangible;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface Func0Param<TResult> {
|
|
||||||
TResult invoke();
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// Licensed under the MIT License.
|
|
||||||
|
|
||||||
package tangible;
|
|
||||||
|
|
||||||
import com.azure.data.cosmos.core.Out;
|
|
||||||
|
|
||||||
public final class TryParseHelper {
|
|
||||||
public static boolean tryParseBoolean(String s, Out<Boolean> result) {
|
|
||||||
try {
|
|
||||||
result.setAndGet(Boolean.parseBoolean(s));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean tryParseByte(String s, Out<Byte> result) {
|
|
||||||
try {
|
|
||||||
result.setAndGet(Byte.parseByte(s));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean tryParseDouble(String s, Out<Double> result) {
|
|
||||||
try {
|
|
||||||
result.setAndGet(Double.parseDouble(s));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean tryParseFloat(String s, Out<Float> result) {
|
|
||||||
try {
|
|
||||||
result.setAndGet(Float.parseFloat(s));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean tryParseInt(String s, Out<Integer> result) {
|
|
||||||
try {
|
|
||||||
result.setAndGet(Integer.parseInt(s));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean tryParseLong(String s, Out<Long> result) {
|
|
||||||
try {
|
|
||||||
result.setAndGet(Long.parseLong(s));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean tryParseShort(String s, Out<Short> result) {
|
|
||||||
try {
|
|
||||||
result.setAndGet(Short.parseShort(s));
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user