File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
java/util/src/main/java/com/google/protobuf/util Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,17 @@ public final class Values {
1717
1818 private static final Value NULL_VALUE =
1919 Value .newBuilder ().setNullValue (NullValue .NULL_VALUE ).build ();
20+ private static final Value TRUE_VALUE = Value .newBuilder ().setBoolValue (true ).build ();
21+ private static final Value FALSE_VALUE = Value .newBuilder ().setBoolValue (false ).build ();
22+ private static final Value EMPTY_STR_VALUE = Value .newBuilder ().setStringValue ("" ).build ();
2023
2124 public static Value ofNull () {
2225 return NULL_VALUE ;
2326 }
2427
2528 /** Returns a Value object with number set to value. */
2629 public static Value of (boolean value ) {
27- return Value . newBuilder (). setBoolValue ( value ). build () ;
30+ return value ? TRUE_VALUE : FALSE_VALUE ;
2831 }
2932
3033 /** Returns a Value object with number set to value. */
@@ -34,7 +37,7 @@ public static Value of(double value) {
3437
3538 /** Returns a Value object with string set to value. */
3639 public static Value of (String value ) {
37- return Value .newBuilder ().setStringValue (value ).build ();
40+ return value . isEmpty () ? EMPTY_STR_VALUE : Value .newBuilder ().setStringValue (value ).build ();
3841 }
3942
4043 /** Returns a Value object with struct set to value. */
You can’t perform that action at this time.
0 commit comments