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
Constructors -
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, withvalueswrapped inListValue.Adds a(name, value)field.Adds a(name, map)field.Adds all distinct keys frommultimapinto this builder.Adds all rows fromtableinto this builder.Adds all key-value pairs frommapinto this builder.addAllFields(StructBuilder that) Adds all fields fromthatinto this builder.addAllFields(com.google.protobuf.Struct that) Adds all fields fromthatinto this builder.com.google.protobuf.Structbuild()Returns a newStructinstance with all added fields.toString()
-
Constructor Details
-
StructBuilder
public StructBuilder()
-
-
Method Details
-
add
Adds a(name, value)field.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
Adds a(name, value)field.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
Adds a(name, value)field.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
Adds a(name, value)field.See
MoreValuesfor helpers that create commonListValueconveniently.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
@CanIgnoreReturnValue public StructBuilder add(String name, Iterable<com.google.protobuf.Value> values) Adds a(name, values) field, withvalueswrapped inListValue.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
@CanIgnoreReturnValue public StructBuilder add(String name, Map<String, com.google.protobuf.Value> map) Adds a(name, map)field.mapis converted to a nested Struct.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
Adds a(name, struct)field.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
Adds a(name, struct)field.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
add
Adds a(name, value)field.To add a null value, use
MoreValues.NULLas inadd("name", NULL).- Returns:
- this builder
- Throws:
IllegalArgumentException- ifnameis duplicate
-
addAll
Adds all key-value pairs frommapinto this builder.- Returns:
- this builder
- Throws:
IllegalArgumentException- if any key is duplicate
-
addAll
@CanIgnoreReturnValue public StructBuilder addAll(Multimap<String, com.google.protobuf.Value> multimap) Adds all distinct keys frommultimapinto 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(Table<String, String, com.google.protobuf.Value> table) Adds all rows fromtableinto 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 fromthatinto this builder.- Returns:
- this builder
- Throws:
IllegalArgumentException- if duplicate field name is encountered
-
addAllFields
Adds all fields fromthatinto this builder.- Returns:
- this builder
- Throws:
IllegalArgumentException- if duplicate field name is encountered
-
build
public com.google.protobuf.Struct build()Returns a newStructinstance with all added fields. -
toString
-