Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COMMON] Rewrite common.main by java17 toList and instanceof #1777

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions common/src/main/java/org/astraea/common/ByteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,18 @@ public Set<TopicPartition> topicPartitions() {
* and "char" in Protocol Buffers. Use "int" and "String" instead.
*/
private static PrimitiveOuterClass.Primitive primitive(Object v) throws SerializationException {
if (v instanceof Integer)
return PrimitiveOuterClass.Primitive.newBuilder().setInt((int) v).build();
else if (v instanceof Long)
return PrimitiveOuterClass.Primitive.newBuilder().setLong((long) v).build();
else if (v instanceof Float)
return PrimitiveOuterClass.Primitive.newBuilder().setFloat((float) v).build();
else if (v instanceof Double)
return PrimitiveOuterClass.Primitive.newBuilder().setDouble((double) v).build();
else if (v instanceof Boolean)
return PrimitiveOuterClass.Primitive.newBuilder().setBoolean((boolean) v).build();
else if (v instanceof String)
return PrimitiveOuterClass.Primitive.newBuilder().setStr(v.toString()).build();
if (v instanceof Integer integerV)
return PrimitiveOuterClass.Primitive.newBuilder().setInt(integerV).build();
else if (v instanceof Long longV)
return PrimitiveOuterClass.Primitive.newBuilder().setLong(longV).build();
else if (v instanceof Float floatV)
return PrimitiveOuterClass.Primitive.newBuilder().setFloat(floatV).build();
else if (v instanceof Double doubleV)
return PrimitiveOuterClass.Primitive.newBuilder().setDouble(doubleV).build();
else if (v instanceof Boolean booleanV)
return PrimitiveOuterClass.Primitive.newBuilder().setBoolean(booleanV).build();
else if (v instanceof String stringV)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否通通都叫 value? 不然現在的命名好詭異

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

return PrimitiveOuterClass.Primitive.newBuilder().setStr(stringV).build();
else
throw new SerializationException(
"Type "
Expand Down
3 changes: 1 addition & 2 deletions common/src/main/java/org/astraea/common/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;
import java.util.Spliterators;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.kafka.common.header.Headers;

Expand All @@ -29,7 +28,7 @@ public static List<Header> of(Headers headers) {
if (!iter.hasNext()) return List.of();
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iter, 0), false)
.map(h -> new Header(h.key(), h.value()))
.collect(Collectors.toUnmodifiableList());
.toList();
}

public static Header of(String key, byte[] value) {
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/org/astraea/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public static <R> R packException(Getter<R> getter) {
}

public static void close(Object obj) {
if (obj instanceof AutoCloseable) {
packException(() -> ((AutoCloseable) obj).close());
if (obj instanceof AutoCloseable autoCloseableObj) {
packException(autoCloseableObj::close);
}
}

Expand Down