Class RecordBuilderBase<T extends IndexedRecord>

java.lang.Object
org.apache.avro.data.RecordBuilderBase<T>
All Implemented Interfaces:
RecordBuilder<T>
Direct Known Subclasses:
GenericRecordBuilder, SpecificErrorBuilderBase, SpecificRecordBuilderBase

public abstract class RecordBuilderBase<T extends IndexedRecord> extends Object implements RecordBuilder<T>
Abstract base class for RecordBuilder implementations. Not thread-safe.
  • Constructor Details

    • RecordBuilderBase

      protected RecordBuilderBase(Schema schema, GenericData data)
      Creates a RecordBuilderBase for building records of the given type.
      Parameters:
      schema - the schema associated with the record class.
    • RecordBuilderBase

      protected RecordBuilderBase(RecordBuilderBase<T> other, GenericData data)
      RecordBuilderBase copy constructor. Makes a deep copy of the values in the other builder.
      Parameters:
      other - RecordBuilderBase instance to copy.
  • Method Details

    • schema

      protected final Schema schema()
    • fields

      protected final Schema.Field[] fields()
    • fieldSetFlags

      protected final boolean[] fieldSetFlags()
    • data

      protected final GenericData data()
    • validate

      protected void validate(Schema.Field field, Object value)
      Validates that a particular value for a given field is valid according to the following algorithm: 1. If the value is not null, or the field type is null, or the field type is a union which accepts nulls, returns. 2. Else, if the field has a default value, returns. 3. Otherwise throws AvroRuntimeException.
      Parameters:
      field - the field to validate.
      value - the value to validate.
      Throws:
      AvroRuntimeException - if value is null and the given field does not accept null values.
    • isValidValue

      protected static boolean isValidValue(Schema.Field f, Object value)
      Tests whether a value is valid for a specified field.
      Parameters:
      f - the field for which to test the value.
      value - the value to test.
      Returns:
      true if the value is valid for the given field; false otherwise.
    • defaultValue

      protected Object defaultValue(Schema.Field field) throws IOException
      Gets the default value of the given field, if any.
      Parameters:
      field - the field whose default value should be retrieved.
      Returns:
      the default value associated with the given field, or null if none is specified in the schema.
      Throws:
      IOException
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object