public class Schema<T> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Schema.Builder<T> |
static class |
Schema.Values<T> |
Constructor and Description |
---|
Schema(int version,
Iterable<FieldDef<T,?>> fields) |
Schema(Iterable<FieldDef<T,?>> fields) |
Modifier and Type | Method and Description |
---|---|
Iterable<Schema.Values<T>> |
buildFields(T obj,
FieldDef.FillArgs fillArgs)
Build all fields in the schema from an input object.
|
Optional<FieldDef<T,?>> |
getField(FieldDef<T,?> first,
FieldDef<T,?>... rest)
Look up fields in this schema.
|
com.google.common.collect.ImmutableMap<String,FieldDef<T,?>> |
getFields()
Get all fields in this schema.
|
com.google.common.collect.ImmutableMap<String,FieldDef<T,?>> |
getStoredFields() |
int |
getVersion() |
boolean |
hasField(FieldDef<T,?> field)
Check whether a field is present in this schema.
|
void |
setVersion(int version) |
String |
toString() |
public final int getVersion()
public final com.google.common.collect.ImmutableMap<String,FieldDef<T,?>> getFields()
This is primarily useful for iteration. Most callers should prefer one of the helper methods
getField(FieldDef, FieldDef...)
or hasField(FieldDef)
to looking up fields by
name
public final com.google.common.collect.ImmutableMap<String,FieldDef<T,?>> getStoredFields()
FieldDef.isStored()
is true.@SafeVarargs public final Optional<FieldDef<T,?>> getField(FieldDef<T,?> first, FieldDef<T,?>... rest)
first
- the preferred field to look up.rest
- additional fields to look up.first
or rest
, in order, or
absent if no field matches.public final boolean hasField(FieldDef<T,?> field)
field
- field to look up.public final Iterable<Schema.Values<T>> buildFields(T obj, FieldDef.FillArgs fillArgs)
Null values are omitted, as are fields which cause errors, which are logged.
obj
- input object.fillArgs
- arguments for filling fields.public void setVersion(int version)