Package org.apache.avro.generic

# Class GenericRecordBuilder

java.lang.Object
org.apache.avro.data.RecordBuilderBase<GenericData.Record>
org.apache.avro.generic.GenericRecordBuilder

All Implemented Interfaces:
  `RecordBuilder<GenericData.Record>`

public class GenericRecordBuilder extends RecordBuilderBase<GenericData.Record>
A RecordBuilder for generic records. GenericRecordBuilder fills in default values for fields if they are not specified.

## Constructor Summary

Constructors
Constructor
Description
`GenericRecordBuilder(GenericData.Record other)`
Creates a GenericRecordBuilder by copying an existing record instance.
`GenericRecordBuilder(GenericRecordBuilder other)`
Creates a GenericRecordBuilder by copying an existing GenericRecordBuilder.
`GenericRecordBuilder(Schema schema)`
Creates a GenericRecordBuilder for building Record instances.

## Method Summary

Modifier and Type
Method
Description
`GenericData.Record`
`build()`
Constructs a new instance using the values set in the RecordBuilder.
`protected GenericRecordBuilder`
`clear(int pos)`
Clears the value of the given field.
`GenericRecordBuilder`
`clear(String fieldName)`
Clears the value of the given field.
`GenericRecordBuilder`
`clear(Schema.Field field)`
Clears the value of the given field.
`boolean`
`equals(Object obj)`
`protected Object`
`get(int pos)`
Gets the value of a field.
`Object`
`get(String fieldName)`
Gets the value of a field.
`Object`
`get(Schema.Field field)`
Gets the value of a field.
`protected boolean`
`has(int pos)`
Checks whether a field has been set.
`boolean`
`has(String fieldName)`
Checks whether a field has been set.
`boolean`
`has(Schema.Field field)`
Checks whether a field has been set.
`int`
`hashCode()`
`protected GenericRecordBuilder`
`set(int pos, Object value)`
Sets the value of a field.
`GenericRecordBuilder`
`set(String fieldName, Object value)`
Sets the value of a field.
`GenericRecordBuilder`
`set(Schema.Field field, Object value)`
Sets the value of a field.

### Methods inherited from class org.apache.avro.data.RecordBuilderBase

`data, defaultValue, fields, fieldSetFlags, isValidValue, schema, validate`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### GenericRecordBuilder

public GenericRecordBuilder(Schema schema)
Creates a GenericRecordBuilder for building Record instances.

Parameters:
  `schema` - the schema associated with the record class.

### GenericRecordBuilder

public GenericRecordBuilder(GenericRecordBuilder other)
Creates a GenericRecordBuilder by copying an existing GenericRecordBuilder.

Parameters:
  `other` - the GenericRecordBuilder to copy.

### GenericRecordBuilder

public GenericRecordBuilder(GenericData.Record other)
Creates a GenericRecordBuilder by copying an existing record instance.

Parameters:
  `other` - the record instance to copy.

## Method Details

### get

public Object get(String fieldName)
Gets the value of a field.

Parameters:
  `fieldName` - the name of the field to get.
Returns:
  the value of the field with the given name, or null if not set.

### get

public Object get(Schema.Field field)
Gets the value of a field.

Parameters:
  `field` - the field to get.
Returns:
  the value of the given field, or null if not set.

### get

protected Object get(int pos)
Gets the value of a field.

Parameters:
  `pos` - the position of the field to get.
Returns:
  the value of the field with the given position, or null if not set.

### set

public GenericRecordBuilder set(String fieldName, Object value)
Sets the value of a field.

Parameters:
  `fieldName` - the name of the field to set.
  `value` - the value to set.
Returns:
  a reference to the RecordBuilder.

### set

public GenericRecordBuilder set(Schema.Field field, Object value)
Sets the value of a field.

Parameters:
  `field` - the field to set.
  `value` - the value to set.
Returns:
  a reference to the RecordBuilder.

### set

protected GenericRecordBuilder set(int pos, Object value)
Sets the value of a field.

Parameters:
  `pos` - the field to set.
  `value` - the value to set.
Returns:
  a reference to the RecordBuilder.

### has

public boolean has(String fieldName)
Checks whether a field has been set.

Parameters:
  `fieldName` - the name of the field to check.
Returns:
  true if the given field is non-null; false otherwise.

### has

public boolean has(Schema.Field field)
Checks whether a field has been set.

Parameters:
  `field` - the field to check.
Returns:
  true if the given field is non-null; false otherwise.

### has

protected boolean has(int pos)
Checks whether a field has been set.

Parameters:
  `pos` - the position of the field to check.
Returns:
  true if the given field is non-null; false otherwise.

### clear

public GenericRecordBuilder clear(String fieldName)
Clears the value of the given field.

Parameters:
  `fieldName` - the name of the field to clear.
Returns:
  a reference to the RecordBuilder.

### clear

public GenericRecordBuilder clear(Schema.Field field)
Clears the value of the given field.

Parameters:
  `field` - the field to clear.
Returns:
  a reference to the RecordBuilder.

### clear

protected GenericRecordBuilder clear(int pos)
Clears the value of the given field.

Parameters:
  `pos` - the position of the field to clear.
Returns:
  a reference to the RecordBuilder.

### build

public GenericData.Record build()
Description copied from interface: `RecordBuilder`
Constructs a new instance using the values set in the RecordBuilder. If a particular value was not set and the schema defines a default value, the default value will be used.

Returns:
  a new instance using values set in the RecordBuilder.

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `RecordBuilderBase<GenericData.Record>`

### equals

public boolean equals(Object obj)

Overrides:
  `equals` in class `RecordBuilderBase<GenericData.Record>`