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.


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
protected  GenericData data()
           
protected  Object defaultValue(Schema.Field field)
          Gets the default value of the given field, if any.
 boolean equals(Object obj)
           
protected  Schema.Field[] fields()
           
protected  boolean[] fieldSetFlags()
           
 int hashCode()
           
protected static boolean isValidValue(Schema.Field f, Object value)
          Tests whether a value is valid for a specified field.
protected  Schema schema()
           
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
 

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

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 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.

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


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