org.apache.avro.generic
Class GenericData

java.lang.Object
  extended by org.apache.avro.generic.GenericData
Direct Known Subclasses:
SpecificData

public class GenericData
extends Object

Utilities for generic Java data.


Nested Class Summary
static class GenericData.Array<T>
          Default implementation of an array.
static class GenericData.EnumSymbol
          Default implementation of GenericEnumSymbol.
static class GenericData.Fixed
          Default implementation of GenericFixed.
static class GenericData.Record
          Default implementation of GenericRecord.
 
Constructor Summary
protected GenericData()
           
 
Method Summary
 int compare(Object o1, Object o2, Schema s)
          Compare objects according to their schema.
static GenericData get()
          Return the singleton instance.
protected  Schema getRecordSchema(Object record)
          Called to obtain the schema of a record.
 int hashCode(Object o, Schema s)
          Compute a hash code according to a schema, consistent with compare(Object,Object,Schema).
protected  int hashCodeAdd(int hashCode, Object o, Schema s)
          Add the hash code for an object into an accumulated hash code.
 Schema induce(Object datum)
          Create a schema given an example datum.
protected  boolean instanceOf(Schema schema, Object datum)
          Called by resolveUnion(Schema,Object).
protected  boolean isArray(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isBytes(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isEnum(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isFixed(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isMap(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isRecord(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isString(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
 int resolveUnion(Schema union, Object datum)
          Return the index for a datum within a union.
 String toString(Object datum)
          Renders a Java datum as JSON.
protected  void toString(Object datum, StringBuilder buffer)
          Renders a Java datum as JSON.
 boolean validate(Schema schema, Object datum)
          Returns true if a Java datum matches a schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericData

protected GenericData()
Method Detail

get

public static GenericData get()
Return the singleton instance.


validate

public boolean validate(Schema schema,
                        Object datum)
Returns true if a Java datum matches a schema.


toString

public String toString(Object datum)
Renders a Java datum as JSON.


toString

protected void toString(Object datum,
                        StringBuilder buffer)
Renders a Java datum as JSON.


induce

public Schema induce(Object datum)
Create a schema given an example datum.


resolveUnion

public int resolveUnion(Schema union,
                        Object datum)
Return the index for a datum within a union. Implemented with instanceOf(Schema,Object).


instanceOf

protected boolean instanceOf(Schema schema,
                             Object datum)
Called by resolveUnion(Schema,Object). May be overridden for alternate data representations.


isArray

protected boolean isArray(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isRecord

protected boolean isRecord(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


getRecordSchema

protected Schema getRecordSchema(Object record)
Called to obtain the schema of a record. By default calls {GenericContainer#getSchema(). May be overridden for alternate record representations.


isEnum

protected boolean isEnum(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isMap

protected boolean isMap(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isFixed

protected boolean isFixed(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isString

protected boolean isString(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isBytes

protected boolean isBytes(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


hashCode

public int hashCode(Object o,
                    Schema s)
Compute a hash code according to a schema, consistent with compare(Object,Object,Schema).


hashCodeAdd

protected int hashCodeAdd(int hashCode,
                          Object o,
                          Schema s)
Add the hash code for an object into an accumulated hash code.


compare

public int compare(Object o1,
                   Object o2,
                   Schema s)
Compare objects according to their schema. If equal, return zero. If greater-than, return 1, if less than return -1. Order is consistent with that of BinaryData.compare(byte[], int, byte[], int, Schema).



Copyright © 2010 The Apache Software Foundation