public interface MutableRecordModel extends RecordModel
RecordV2
data based upon a
Schema
.
An initial version of such a model can be created from a schema using the
Schema.createMutableModel()
method. A model created in this way will
have all mandatory fields set to default values.
The model may then be updated as required and then at any time a
RecordV2
object can be generated from the current state using
the asValue
method. The RecordV2
object may then be used to update a
topic.
When values for integer or decimal type fields are supplied the values are
validated and normalized. All number values will have any insignificant
leading zeroes removed. A decimal value will also be rounded to its specified
scale using half-up
rounding.
All mutator methods return the model so that calls can be chained.
Modifier and Type | Method and Description |
---|---|
MutableRecordModel |
add(String... values)
Adds new values to the end of a variable length field list.
|
MutableRecordModel |
add(String recordName,
int recordIndex,
String... values)
Adds new values to the end of a variable length field list.
|
MutableRecordModel |
addRecord()
Adds a new initialized record occurrence to the end of a variable
multiplicity record list.
|
MutableRecordModel |
clearVariableFields(String recordName,
int recordIndex)
Remove all optional instances of a variable multiplicity field.
|
MutableRecordModel |
clearVariableRecords()
Removes all optional instances of a variable multiplicity record.
|
MutableRecordModel |
removeField(String recordName,
int recordIndex,
int fieldIndex)
Removes the specified occurrence of a variable multiplicity field.
|
MutableRecordModel |
removeRecord(int index)
Removes the specified occurrence of a variable multiplicity record.
|
MutableRecordModel |
set(String recordName,
int recordIndex,
String fieldName,
int fieldIndex,
String value)
Sets a specified field value.
|
MutableRecordModel |
set(String key,
String value)
Sets a specified field value.
|
asValue, fieldCount, get, get, recordCount
MutableRecordModel set(String recordName, int recordIndex, String fieldName, int fieldIndex, String value) throws SchemaViolationException, IndexOutOfBoundsException
recordName
- the name of the record containing the fieldrecordIndex
- the index of the record containing the fieldfieldName
- the name of the fieldfieldIndex
- the index of the fieldvalue
- the new valueSchemaViolationException
- if the details given conflict with the
schema or the value is incompatible with the schema field typeIndexOutOfBoundsException
- if an index is out of boundsMutableRecordModel set(String key, String value) throws SchemaViolationException, IndexOutOfBoundsException, IllegalArgumentException, NumberFormatException
This allows an item to be addressed using a key of the form recordName(recordIndex).fieldName(fieldIndex). Indexes may be omitted in which case 0 is assumed. The record part may also be omitted in which case the first occurrence of the first record is assumed.
key
- the field keyvalue
- the field valueSchemaViolationException
- if the key does not address a valid
fieldIndexOutOfBoundsException
- if a specified index is out of boundsIllegalArgumentException
- of the key format is invalidNumberFormatException
- if a specified index is not a valid numberMutableRecordModel add(String recordName, int recordIndex, String... values) throws SchemaViolationException, IndexOutOfBoundsException
This can only be used for a variable multiplicity field which can only be the last field in a record and therefore the field does not need to be named.
recordName
- the name of the recordrecordIndex
- the index identifying the occurrence of the recordvalues
- the values to addSchemaViolationException
- if details conflict with the schema,
possibly because the last field of the record is not a variable
multiplicity field or the maximum number of occurrences for the
field would be breached. This could also occur if one of the
values is incompatible with the field type.IndexOutOfBoundsException
- if the record index is out of boundsMutableRecordModel add(String... values) throws SchemaViolationException
This is a convenience method for adding to the end of the last record and is therefore useful when there is only one record type.
values
- the valuesSchemaViolationException
- if details conflict with the schema,
possibly because the last field of the last record is not a
variable multiplicity field or the maximum number of occurrences
for the field would be breached. This could also occur if one of
the values is incompatible with the field type.MutableRecordModel addRecord() throws SchemaViolationException
As the only variable multiplicity record can be the last one there is no need to name the record. This method will add to the list of occurrences of the last defined record. The record will be initialized with default values appropriate to the schema definition and may then have individual field items set separately.
SchemaViolationException
- if the last or only record is not a
variable repeating record or has already reached the maximum
number of occurrencesMutableRecordModel removeRecord(int index) throws SchemaViolationException, IndexOutOfBoundsException
A variable multiplicity record must be the last or only record within a schema and therefore the record name is not required.
index
- the index of the record to removeSchemaViolationException
- if the last or only record is not a
variable multiplicity record or can not be removed as it would
violate the minimum number of occurrencesIndexOutOfBoundsException
- if the specified index is out of boundsMutableRecordModel removeField(String recordName, int recordIndex, int fieldIndex) throws SchemaViolationException, IndexOutOfBoundsException
A variable multiplicity field must be the last or only field within a record and therefore the field name is not required.
recordName
- the name of the recordrecordIndex
- the record indexfieldIndex
- the index of the field to removeSchemaViolationException
- if the record is not known or the last
or only field within the record is not a variable repeating field
or can not be removed as it would violate the minimum number of
occurrencesIndexOutOfBoundsException
- if one of the specified indexes is out
of boundsMutableRecordModel clearVariableRecords()
As a variable repeating record can only be the last or only record then the record name does not need to be specified.
This will only remove record occurrences down to the minimum number of occurrences specified by the schema.
If the last or only record is not defined as variable multiplicity, this would have no effect.
MutableRecordModel clearVariableFields(String recordName, int recordIndex) throws SchemaViolationException, IndexOutOfBoundsException
As a variable repeating field can only be the last or only field within a record then the field name does not need to be specified.
This will only remove field occurrences down to the minimum number of occurrences specified by the schema.
If the last or only field within the record is not defined as variable multiplicity, this would have no effect.
recordName
- the name of the recordrecordIndex
- the index of the recordSchemaViolationException
- if the record is not known.IndexOutOfBoundsException
- if the specified index is out
of boundsCopyright © 2022 Push Technology Ltd. All Rights Reserved.