Le 19/03/2017 à 17:47, Emmanuel Lecharny a écrit :
> Thanks, Stefan.
>
> I'll have a look at generics tonite.
>
> Regarding the need of a builder for each class, I think it would help
> habing a consistent system across all the SCs.
>
> Otherwise, this idea should apply to the other schema objects.
>
>
> Le dim. 19 mars 2017 à 10:58, Stefan Seelmann <m...@stefan-seelmann.de> a
> écrit :
>
>> On 03/17/2017 11:00 AM, Emmanuel Lécharny wrote:
>> > The only requirement is that each SC has its own builder (we can't put
>> > this code in the abstract SC, because it's abstract...)
>
>> With some generics magic it should at least be possible to move common
>> stuff (setOid) to the parent.

I come with that :

in SyntaxChecker base class :

   
public abstract class SyntaxChecker extends LoadableSchemaObject
{
    ...
    /**
     * A static Builder for this class
     */
    public abstract static class SCBuilder<SC>
    {
        /** The SyntaxChecker OID */
        protected String oid;
       
        /**
         * The Builder constructor
         */
        protected SCBuilder( String oid )
        {
            this.oid = oid;
        }
       
       
        /**
         * Set the SyntaxChecker's OID
         *
         * @param oid The OID
         * @return The Builder's Instance
         */
        public SCBuilder<SC> setOid( String oid )
        {
            this.oid = oid;
           
            return this;
        }
       
        public abstract SC build();
    }


In BooleanSyntaxChecker inherited class :

public class BooleanSyntaxChecker extends SyntaxChecker
{
    /**
     * A static instance of BooleanSyntaxChecker
     */
    public static final BooleanSyntaxChecker INSTANCE = new
BooleanSyntaxChecker( SchemaConstants.BOOLEAN_SYNTAX );
   
    /** A static instance of the builder */
    private static final Builder BUILDER_INSTANCE = new Builder();
   
    /**
     * A static Builder for this class
     */
    public static class Builder extends SCBuilder<BooleanSyntaxChecker>
    {
        /**
         * The Builder constructor
         */
        private Builder()
        {
            super( SchemaConstants.BOOLEAN_SYNTAX );
        }
       
       
        /**
         * Create a new instance of BooleanSyntaxChecker
         * @return A new instance of BooleanSyntaxChecker
         */
        @Override
        public BooleanSyntaxChecker build()
        {
            return new BooleanSyntaxChecker( oid );
        }
    }

   
    /**
     * Creates a new instance of BooleanSyntaxChecker.
     */
    private BooleanSyntaxChecker( String oid )
    {
        super( oid );
    }

   
    /**
     * @return An instance of the Builder for this class
     */
    public static Builder builder()
    {
        return BUILDER_INSTANCE;
    }

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org

Reply via email to