public class Schema<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Schema.Builder<T> |
static class |
Schema.Values<T> |
Constructor and Description |
---|
Schema(int version,
java.lang.Iterable<FieldDef<T,?>> fields) |
Schema(java.lang.Iterable<FieldDef<T,?>> fields) |
Modifier and Type | Method and Description |
---|---|
java.lang.Iterable<Schema.Values<T>> |
buildFields(T obj)
Build all fields in the schema from an input object.
|
java.util.Optional<FieldDef<T,?>> |
getField(FieldDef<T,?> first,
FieldDef<T,?>... rest)
Look up fields in this schema.
|
com.google.common.collect.ImmutableMap<java.lang.String,FieldDef<T,?>> |
getFields()
Get all fields in this schema.
|
com.google.common.collect.ImmutableMap<java.lang.String,FieldDef<T,?>> |
getStoredFields() |
int |
getVersion() |
boolean |
hasField(FieldDef<T,?> field)
Check whether a field is present in this schema.
|
void |
setVersion(int version) |
java.lang.String |
toString() |
public final int getVersion()
public final com.google.common.collect.ImmutableMap<java.lang.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<java.lang.String,FieldDef<T,?>> getStoredFields()
FieldDef.isStored()
is true.@SafeVarargs public final java.util.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 java.lang.Iterable<Schema.Values<T>> buildFields(T obj)
Null values are omitted, as are fields which cause errors, which are logged.
obj
- input object.public java.lang.String toString()
toString
in class java.lang.Object
public void setVersion(int version)