org.apache.avro.data
Class RecordBuilderBase<T extends IndexedRecord>

java.lang.Object
  extended by 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.


Field Summary
protected  GenericData data
           
protected  Schema.Field[] fields
           
protected  boolean[] fieldSetFlags
           
protected  Schema schema
           
 
Constructor Summary
protected RecordBuilderBase(RecordBuilderBase<T> other, GenericData data)
          RecordBuilderBase copy constructor.
protected RecordBuilderBase(Schema schema, GenericData data)
          Creates a RecordBuilderBase for building records of the given type.
 
Method Summary
 boolean equals(Object obj)
           
protected  Object getDefaultValue(Schema.Field field)
          Gets the default value of the given field, if any.
 int hashCode()
           
protected static boolean isValidValue(Schema.Field f, Object value)
          Tests whether a value is valid for a specified field.
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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.avro.data.RecordBuilder
build
 

Field Detail

schema

protected final Schema schema

fields

protected final Schema.Field[] fields

fieldSetFlags

protected final boolean[] fieldSetFlags

data

protected final GenericData data
Constructor Detail

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 Detail

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 NullPointerException

Parameters:
field - the field to validate.
value - the value to validate.
Throws:
NullPointerException - 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.

getDefaultValue

protected Object getDefaultValue(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


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.