Package org.symphonyoss.s2.canon.runtime
Class EntityBuilder<B extends EntityBuilder<B,T>,T extends IEntity>
- java.lang.Object
-
- org.symphonyoss.s2.canon.runtime.EntityBuilder<B,T>
-
- Type Parameters:
B- Fluent type, determines the type of the "this" reference returned by with methods.
- All Implemented Interfaces:
IBaseEntity,IEntityBuilder,IEntityOrBuilder,org.symphonyoss.s2.common.dom.json.IJsonDomNodeProvider
public abstract class EntityBuilder<B extends EntityBuilder<B,T>,T extends IEntity> extends Object implements IEntityBuilder, org.symphonyoss.s2.common.dom.json.IJsonDomNodeProvider, IBaseEntity
A builder for some entity type. Essentially this is a mutable version of the enclosing entity type.- Author:
- Bruce Skingle
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.symphonyoss.s2.common.dom.DomSerializerSERIALIZER
-
Constructor Summary
Constructors Modifier Constructor Description protectedEntityBuilder(Class<B> type)protectedEntityBuilder(Class<B> type, IBaseEntity other)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tbuild()Build an instance of the immutable built type from the current values of the builder.protected abstract Tconstruct()List<Object>getCanonAllFields()org.symphonyoss.s2.common.dom.json.IImmutableJsonDomNodegetJsonDomNode()voidgetJsonObject(org.symphonyoss.s2.common.dom.json.MutableJsonObject jsonObject)Fill in the JSON representation of the current state of this builder.protected abstract voidpopulateAllFields(List<Object> result)protected voidrequire(Object value, String name)Convenience method to check that the given value is not null.protected Bself()org.symphonyoss.s2.common.immutable.ImmutableByteArrayserialize()Serialize this object.protected voidvalidate()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.symphonyoss.s2.canon.runtime.IEntityOrBuilder
getCanonMajorVersion, getCanonMinorVersion, getCanonType, getJsonObject
-
-
-
-
Constructor Detail
-
EntityBuilder
protected EntityBuilder(Class<B> type, IBaseEntity other)
-
-
Method Detail
-
self
protected B self()
-
getJsonObject
public void getJsonObject(org.symphonyoss.s2.common.dom.json.MutableJsonObject jsonObject)
Fill in the JSON representation of the current state of this builder. Implementations should callsuper.getJsonObject(jsonObject);- Parameters:
jsonObject- the JSON representation of the current state of this builder.
-
getJsonDomNode
public org.symphonyoss.s2.common.dom.json.IImmutableJsonDomNode getJsonDomNode()
- Specified by:
getJsonDomNodein interfaceIBaseEntity- Specified by:
getJsonDomNodein interfaceorg.symphonyoss.s2.common.dom.json.IJsonDomNodeProvider
-
serialize
public org.symphonyoss.s2.common.immutable.ImmutableByteArray serialize()
Description copied from interface:IBaseEntitySerialize this object.- Specified by:
serializein interfaceIBaseEntity- Returns:
- The serialized form of this object.
-
build
public final T build()
Build an instance of the immutable built type from the current values of the builder.- Returns:
- An instance of the immutable built type from the current values of the builder.
-
construct
protected abstract T construct()
-
validate
protected void validate()
-
require
protected void require(Object value, String name)
Convenience method to check that the given value is not null.- Parameters:
value- Some valuename- The name of the value.- Throws:
IllegalStateException- if the given value is null.
-
-