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

Return constant Value objects for true, false, and "" #18430

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ public final class Values {

private static final Value NULL_VALUE =
Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
private static final Value TRUE_VALUE = Value.newBuilder().setBoolValue(true).build();
private static final Value FALSE_VALUE = Value.newBuilder().setBoolValue(false).build();
private static final Value EMPTY_STR_VALUE = Value.newBuilder().setStringValue("").build();

public static Value ofNull() {
return NULL_VALUE;
}

/** Returns a Value object with number set to value. */
public static Value of(boolean value) {
return Value.newBuilder().setBoolValue(value).build();
return value ? TRUE_VALUE : FALSE_VALUE;
}

/** Returns a Value object with number set to value. */
Expand All @@ -34,7 +37,7 @@ public static Value of(double value) {

/** Returns a Value object with string set to value. */
public static Value of(String value) {
return Value.newBuilder().setStringValue(value).build();
return value.isEmpty() ? EMPTY_STR_VALUE : Value.newBuilder().setStringValue(value).build();
}

/** Returns a Value object with struct set to value. */
Expand Down
Loading