Class EntityBuilder<B extends EntityBuilder<B,​T>,​T extends IEntity>

  • 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 Detail

      • SERIALIZER

        protected static final org.symphonyoss.s2.common.dom.DomSerializer SERIALIZER
    • Constructor Detail

      • EntityBuilder

        protected EntityBuilder​(Class<B> type)
    • 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 call super.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:
        getJsonDomNode in interface IBaseEntity
        Specified by:
        getJsonDomNode in interface org.symphonyoss.s2.common.dom.json.IJsonDomNodeProvider
      • serialize

        public org.symphonyoss.s2.common.immutable.ImmutableByteArray serialize()
        Description copied from interface: IBaseEntity
        Serialize this object.
        Specified by:
        serialize in interface IBaseEntity
        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 value
        name - The name of the value.
        Throws:
        IllegalStateException - if the given value is null.
      • getCanonAllFields

        public List<Object> getCanonAllFields()
        Returns:
        a list of all declared fields.
      • populateAllFields

        protected abstract void populateAllFields​(List<Object> result)