Interface MutableRecordModel

All Superinterfaces:
RecordModel

public interface MutableRecordModel extends RecordModel
This is a mutable data model of 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.

Since:
6.0
Author:
DiffusionData Limited
  • Method Details

    • set

      MutableRecordModel set(String recordName, int recordIndex, String fieldName, int fieldIndex, String value) throws SchemaViolationException, IndexOutOfBoundsException
      Sets a specified field value.
      Parameters:
      recordName - the name of the record containing the field
      recordIndex - the index of the record containing the field
      fieldName - the name of the field
      fieldIndex - the index of the field
      value - the new value
      Returns:
      this model
      Throws:
      SchemaViolationException - if the details given conflict with the schema or the value is incompatible with the schema field type
      IndexOutOfBoundsException - if an index is out of bounds
    • set

      Sets a specified field value.

      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.

      Parameters:
      key - the field key
      value - the field value
      Returns:
      this model
      Throws:
      SchemaViolationException - if the key does not address a valid field
      IndexOutOfBoundsException - if a specified index is out of bounds
      IllegalArgumentException - of the key format is invalid
      NumberFormatException - if a specified index is not a valid number
    • add

      MutableRecordModel add(String recordName, int recordIndex, String... values) throws SchemaViolationException, IndexOutOfBoundsException
      Adds new values to the end of a variable length field list.

      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.

      Parameters:
      recordName - the name of the record
      recordIndex - the index identifying the occurrence of the record
      values - the values to add
      Returns:
      this model
      Throws:
      SchemaViolationException - 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 bounds
    • add

      Adds new values to the end of a variable length field list.

      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.

      Parameters:
      values - the values
      Returns:
      this model
      Throws:
      SchemaViolationException - 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.
    • addRecord

      Adds a new initialized record occurrence to the end of a variable multiplicity record list.

      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.

      Returns:
      this model
      Throws:
      SchemaViolationException - if the last or only record is not a variable repeating record or has already reached the maximum number of occurrences
    • removeRecord

      Removes the specified occurrence of a variable multiplicity record.

      A variable multiplicity record must be the last or only record within a schema and therefore the record name is not required.

      Parameters:
      index - the index of the record to remove
      Returns:
      this model
      Throws:
      SchemaViolationException - 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 occurrences
      IndexOutOfBoundsException - if the specified index is out of bounds
    • removeField

      MutableRecordModel removeField(String recordName, int recordIndex, int fieldIndex) throws SchemaViolationException, IndexOutOfBoundsException
      Removes the specified occurrence of a variable multiplicity field.

      A variable multiplicity field must be the last or only field within a record and therefore the field name is not required.

      Parameters:
      recordName - the name of the record
      recordIndex - the record index
      fieldIndex - the index of the field to remove
      Returns:
      this model
      Throws:
      SchemaViolationException - 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 occurrences
      IndexOutOfBoundsException - if one of the specified indexes is out of bounds
    • clearVariableRecords

      MutableRecordModel clearVariableRecords()
      Removes all optional instances of a variable multiplicity record.

      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.

      Returns:
      this model
    • clearVariableFields

      MutableRecordModel clearVariableFields(String recordName, int recordIndex) throws SchemaViolationException, IndexOutOfBoundsException
      Remove all optional instances of a variable multiplicity field.

      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.

      Parameters:
      recordName - the name of the record
      recordIndex - the index of the record
      Returns:
      this model
      Throws:
      SchemaViolationException - if the record is not known.
      IndexOutOfBoundsException - if the specified index is out of bounds