public static interface Record.StructuredBuilder
Metadata
.
Such a builder can be created using
Record.Factory.newRecordBuilder(MRecord)
.
A single builder may be used to build any number of records and after a build all previously set values are retained.
Initially all fields will be set to initial values as described by the metadata. Field values may then be changed to any values permitted by the metadata.
If a metadata field allows an empty value
,
it may be set to either a zero length string or the
default empty field value
. A different
empty field value may be specified using emptyFieldValue(String)
.
Modifier and Type | Method and Description |
---|---|
Record.StructuredBuilder |
add(String name,
Collection<?> values)
Appends one or more values to a repeating field.
|
Record.StructuredBuilder |
add(String name,
Object... values)
Appends one or more values to a repeating field.
|
Record |
build()
Builds the record.
|
Record.StructuredBuilder |
emptyFieldValue(String value)
Sets the value to be used to indicate empty fields.
|
Record.StructuredBuilder |
reset()
Resets the builder to its initial state.
|
Record.StructuredBuilder |
set(String name,
Collection<?> values)
As
set(String, Object...) but allowing a collection of
values to be supplied. |
Record.StructuredBuilder |
set(String name,
int index,
Object value)
Sets a field value by name and index.
|
Record.StructuredBuilder |
set(String name,
Object... values)
Set field value(s) by name.
|
Record.StructuredBuilder set(String name, Object... values) throws IllegalArgumentException, MetadataViolationException
When used for a single
multiplicity
field only a single value may be specified. If no value (or null) is
specified, the field will be set to the default value as indicated by
the metadata.
When used for a repeating
multiplicity field, multiple values may be specified. No more than
the maximum
number of values may be
supplied.
name
- the field namevalues
- the value or values which are parsed according to the
data type as specified in the metadata. Specifying no values
will cause the field to be initialized to defaults (repeating
fields will have the minimum number of occurrences set to
default). A null value is also interpreted as defaultIllegalArgumentException
- if name
is nullMetadataViolationException
- if the metadata does not specify a
field of the given name or the value(s) can not be parsed or
the number of values violates the metadata definitionRecord.StructuredBuilder set(String name, Collection<?> values) throws IllegalArgumentException, MetadataViolationException
set(String, Object...)
but allowing a collection of
values to be supplied.name
- the field name.values
- the value or values which are parsed according to the
data type as specified in the metadata. Specifying no values
will cause the field to be initialized to defaults (repeating
fields will have the minimum number of occurrences set to
default). A null value is also interpreted as default.IllegalArgumentException
- if name
is nullMetadataViolationException
- if the metadata does not specify a
field of the given name or the value(s) can not be parsed or
the number of values violates the metadata definition.Record.StructuredBuilder add(String name, Object... values) throws IllegalArgumentException, MetadataViolationException
This can only be used for a repeating
multiplicity field.
Adding the values must not cause the maximum
number of values to be exceeded.
name
- the field namevalues
- the value or values which are parsed according to the
data type as specified in the metadata. If null or no values
supplied, this call has no effectIllegalArgumentException
- if name
is nullMetadataViolationException
- if the metadata does not specify a
repeating field of the given name or the value(s) can not be
parsed or the number of values causes the metadata definition
to be violated.Record.StructuredBuilder add(String name, Collection<?> values) throws IllegalArgumentException, MetadataViolationException
This is equivalent to set(String, Object...)
but with a
collection of values.
name
- the field namevalues
- the value or values which are parsed according to the
data type as specified in the metadata. If null or no values
supplied, this call has no effectIllegalArgumentException
- if name
is nullMetadataViolationException
- if the metadata does not specify a
repeating field of the given name or the value(s) can not be
parsed or the number of values causes the metadata definition
to be violatedRecord.StructuredBuilder set(String name, int index, Object value) throws IllegalArgumentException, IndexOutOfBoundsException, MetadataViolationException
This can only be used for a repeating
multiplicity field.
name
- the field nameindex
- the index of the field occurrence to setvalue
- the new field value which is parsed according to the
data type indicated by the metadata. null is interpreted as
the default value for the field as indicated by the metadataIllegalArgumentException
- if name
is nullIndexOutOfBoundsException
- if index
is out of boundsMetadataViolationException
- if the metadata has no field of
the given name, or the named field is not declared as
repeating, or the index violates metadata rules or the value
can not be parsedRecord.StructuredBuilder emptyFieldValue(String value) throws IllegalArgumentException
When a field indicates that it allows an empty value, this may be used to specify what that value is. Setting of non-string field values will therefore allow this value.
If not explicitly set, the empty field value is assumed to be "" (zero length string) to match the default for record topics. However, this should be changed to whatever is used for the target topic.
value
- the empty field valueIllegalArgumentException
- if value
is nullRecord.StructuredBuilder reset()
Record build()
Copyright © 2016 Push Technology Ltd. All Rights Reserved.