Package com.google.mu.protobuf.util
Class StructBuilder
java.lang.Object
com.google.mu.protobuf.util.StructBuilder
A builder that supports building heterogeneous
Struct
more conveniently,
while eliding most of the intermediary and verbose Value
creation.
Unlike Struct.Builder
, the add()
methods will throw upon duplicate keys.
- Since:
- 5.8
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds a(name, value)
field.Adds a(name, value)
field.add
(String name, StructBuilder struct) Adds a(name, struct)
field.Adds a(name, value)
field.Adds a(name, struct)
field.Adds a(name, value)
field.Adds a(name, values) field
, withvalues
wrapped inListValue
.Adds a(name, value)
field.Adds a(name, map)
field.Adds all distinct keys frommultimap
into this builder.Adds all rows fromtable
into this builder.Adds all key-value pairs frommap
into this builder.addAllFields
(StructBuilder that) Adds all fields fromthat
into this builder.addAllFields
(com.google.protobuf.Struct that) Adds all fields fromthat
into this builder.com.google.protobuf.Struct
build()
Returns a newStruct
instance with all added fields.toString()
-
Constructor Details
-
StructBuilder
public StructBuilder()
-
-
Method Details
-
add
Adds a(name, value)
field.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
Adds a(name, value)
field.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
Adds a(name, value)
field.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
Adds a(name, value)
field.See
MoreValues
for helpers that create commonListValue
conveniently.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
@CanIgnoreReturnValue public StructBuilder add(String name, Iterable<com.google.protobuf.Value> values) Adds a(name, values) field
, withvalues
wrapped inListValue
.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
@CanIgnoreReturnValue public StructBuilder add(String name, Map<String, com.google.protobuf.Value> map) Adds a(name, map)
field.map
is converted to a nested Struct.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
Adds a(name, struct)
field.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
Adds a(name, struct)
field.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
add
Adds a(name, value)
field.To add a null value, use
MoreValues.NULL
as inadd("name", NULL)
.- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifname
is duplicate
-
addAll
Adds all key-value pairs frommap
into this builder.- Returns:
- this builder
- Throws:
IllegalArgumentException
- if any key is duplicate
-
addAll
@CanIgnoreReturnValue public StructBuilder addAll(com.google.common.collect.Multimap<String, com.google.protobuf.Value> multimap) Adds all distinct keys frommultimap
into this builder. Values mapping to the same key are grouped together inListValue
.- Returns:
- this builder
- Throws:
IllegalArgumentException
- if any key is duplicate
-
addAll
@CanIgnoreReturnValue public StructBuilder addAll(com.google.common.collect.Table<String, String, com.google.protobuf.Value> table) Adds all rows fromtable
into this builder. Columns of each row are grouped together inStruct
, keyed by column name.- Returns:
- this builder
- Throws:
IllegalArgumentException
- if any row key is duplicate
-
addAllFields
Adds all fields fromthat
into this builder.- Returns:
- this builder
- Throws:
IllegalArgumentException
- if duplicate field name is encountered
-
addAllFields
Adds all fields fromthat
into this builder.- Returns:
- this builder
- Throws:
IllegalArgumentException
- if duplicate field name is encountered
-
build
public com.google.protobuf.Struct build()Returns a newStruct
instance with all added fields. -
toString
-