Class MoreValues

java.lang.Object
com.google.mu.protobuf.util.MoreValues

@CheckReturnValue @RequiresProtobuf public final class MoreValues extends Object
Additional utilities to help create Value and ListValue messages.
Since:
5.8
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.google.protobuf.Value
    The Value for boolean false.
    static final com.google.protobuf.Value
    The Value for null.
    static final com.google.protobuf.Value
    The Value for boolean true.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<Object>
    asList(com.google.protobuf.ListValueOrBuilder listValue)
    Returns a List<Object> view over listValue.
    static @Nullable Object
    fromValue(com.google.protobuf.ValueOrBuilder value)
    Unwraps value.
    static com.google.protobuf.ListValue
    listValueOf(double... values)
    Returns ListValue wrapping values.
    static com.google.protobuf.ListValue
    listValueOf(@Nullable com.google.protobuf.Struct... values)
    Returns ListValue wrapping values.
    static com.google.protobuf.ListValue
    listValueOf(@Nullable String... values)
    Returns ListValue wrapping values.
    static com.google.protobuf.Value
    nullableValueOf(@Nullable String string)
    Returns Value wrapper for string if not null, or else returns NULL.
    static Collector<com.google.protobuf.Value,?,com.google.protobuf.ListValue>
    Returns a Collector that collects the input values into ListValue.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NULL

      public static final com.google.protobuf.Value NULL
      The Value for null.
    • TRUE

      public static final com.google.protobuf.Value TRUE
      The Value for boolean true.
    • FALSE

      public static final com.google.protobuf.Value FALSE
      The Value for boolean false.
  • Method Details

    • nullableValueOf

      public static com.google.protobuf.Value nullableValueOf(@Nullable String string)
      Returns Value wrapper for string if not null, or else returns NULL.
    • listValueOf

      public static com.google.protobuf.ListValue listValueOf(double... values)
      Returns ListValue wrapping values.
    • listValueOf

      public static com.google.protobuf.ListValue listValueOf(@Nullable String... values)
      Returns ListValue wrapping values. Null strings are converted to NULL.
    • listValueOf

      public static com.google.protobuf.ListValue listValueOf(@Nullable com.google.protobuf.Struct... values)
      Returns ListValue wrapping values. Null structs are converted to NULL.
    • toListValue

      public static Collector<com.google.protobuf.Value,?,com.google.protobuf.ListValue> toListValue()
      Returns a Collector that collects the input values into ListValue.
    • fromValue

      public static @Nullable Object fromValue(com.google.protobuf.ValueOrBuilder value)
      Unwraps value.

      For example, Values.of(1) is unwrapped to 1; ListValue is unwrapped as List<Object>; Struct is unwrapped as Map<String, Object>; and NullValue is unwrapped as null, etc.

      Note that integral numbers in the range of int will be unwrapped as Integer; while integral numbers otherwise in the range of long will be unwrapped as Long. All other numbers are unwrapped as Double. If you need to handle all number cases unconditionally, consider to use Number.doubleValue().

      The returned object is immutable. Even if value is an instance of Value.Builder, and the underlying state is changed after this method returns, the returned object remains unchanged.

      Since:
      5.9
      See Also:
    • asList

      public static List<Object> asList(com.google.protobuf.ListValueOrBuilder listValue)
      Returns a List<Object> view over listValue.

      For example, Values.of(1) is unwrapped to 1L; Struct is unwrapped as Map<String, Object>; and NullValue is unwrapped as null, etc.

      Since:
      5.9
      See Also: