Progressed on port from dotnet to java.

This commit is contained in:
David Noble
2019-09-13 03:52:44 -07:00
parent e942e2076c
commit e8df66f084
3 changed files with 9 additions and 104 deletions

View File

@@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.google.common.base.Objects;
import com.google.common.base.Suppliers;
import com.google.common.base.Utf8;
import com.google.common.collect.Streams;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.Unpooled;
@@ -145,30 +146,14 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return other == null ? 0 : -1;
}
final int length = this.length();
final int otherLength = other.length();
final int limit = Math.min(length, otherLength);
// TODO: DANOBLE: Consider optimizing this method based on the cost of zipping boxed int streams
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());
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;
return compare.orElse(this.length() - other.length());
}
/**
@@ -547,7 +532,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
private int skip = 0;
@Override
public boolean process(byte value) throws Exception {
public boolean process(byte value) {
if (this.skip > 0) {
this.skip--;
@@ -678,7 +663,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
if (!Character.isDefined(this.codePoint)) {
this.codePoint = REPLACEMENT_CHARACTER;
};
}
return false;
}

View File

@@ -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();
}

View File

@@ -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;
}
}
}