001    /*
002     * Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
003     *
004     * This software is the confidential and proprietary information of
005     * ChemAxon. You shall not disclose such Confidential Information
006     * and shall use it only in accordance with the terms of the agreements
007     * you entered into with ChemAxon.
008     *
009     */
010    package com.chemaxon.descriptors.fingerprints.pf2d;
011    
012    import com.chemaxon.apidiscovery.annotations.BuilderClass;
013    import com.chemaxon.apidiscovery.annotations.Description;
014    import com.chemaxon.apidiscovery.annotations.Parameter;
015    import com.chemaxon.apidiscovery.annotations.Parametrized;
016    import com.chemaxon.apidiscovery.interfaces.ParameterBuilder;
017    import com.chemaxon.descriptors.common.DescriptorParameters;
018    import com.google.common.base.Optional;
019    
020    /**
021     * Parameters class for {@link ThreadLocalizedPfGenerator}.
022     *
023     * <p>We hope efficiency gain from this dangerous workaround. <b>Use with extreme care!</b>.</p>
024     *
025     * <p>Conventions and contracts related to {@link com.chemaxon.descriptors} and {@link com.chemaxon.apidiscovery} are
026     * not satisfied by this class.</p>
027     *
028     *
029     * @author Gabor Imre
030     * @author Laszlo Antal
031     */
032    @BuilderClass(builderClass = ThreadLocalizedPfParameters.Builder.class)
033    public class ThreadLocalizedPfParameters implements DescriptorParameters {
034    
035        /**
036         * Serial version.
037         */
038        private static final long serialVersionUID = 0;
039    
040        // PARAMETERS ======================================================================================================
041    
042        /**
043         * XML configuration string.
044         */
045        private final Optional<String> xmlConfig;
046    
047        /**
048         * Constructor based on a builder.
049         * @param builder Builder which current state will be represented.
050         */
051        private ThreadLocalizedPfParameters(final Builder builder) {
052            this.xmlConfig = builder.xmlConfig;
053        }
054    
055        /**
056         * Constructor using the default settings.
057         */
058        public ThreadLocalizedPfParameters() {
059            this(new Builder());
060        }
061    
062        /**
063         * Construct a builder for this parameter class, initialized to default.
064         * @return Builder initialized to default settings
065         */
066        public static Builder createNewBuilder() {
067            return new Builder();
068        }
069    
070        @Override
071        public ThreadLocalizedPfGenerator getDescriptorGenerator() {
072            return new ThreadLocalizedPfGenerator(this);
073        }
074    
075        /**
076         * Construct non thread safe Pf generator.
077         *
078         * @return Generator according to the represented parameters
079         */
080        protected PfGeneratorImpl constructPdGeneratorImpl() {
081            final PfParameters p = PfParameters.createNewBuilder().xmlConfig(this.xmlConfig).build();
082            final PfGeneratorImpl g = (PfGeneratorImpl) p.getDescriptorGenerator();
083            return g;
084        }
085    
086        @Override
087        public String toString() {
088            // TODO: Optional has clever toString()
089            return "XML config: " + this.xmlConfig.toString();
090        }
091    
092        // GETTERS =========================================================================================================
093    
094        /**
095         * The XML configuration string.
096         * @return config string
097         */
098        public Optional<String> getXmlConfig() {
099            return this.xmlConfig;
100        }
101    
102        // HELPER INTERFACE FOR DI =========================================================================================
103        /**
104         * Interface representing PF generator constructor.
105         */
106        protected interface ConstructPfGenerator {
107            /**
108             * Constructor invocation.
109             * @param parameters Generator parameters
110             * @return Created generator
111             */
112            PfGenerator constructPfGenerator(PfParameters parameters);
113        }
114    
115        // BUILDER CLASS ===================================================================================================
116    
117        /**
118         * Builder class for the immutable parameter object.
119         */
120        @Parametrized
121        public static class Builder implements ParameterBuilder<ThreadLocalizedPfParameters> {
122    
123            // /**
124            // * Fuzzy smoothing factor.
125            // */
126            // @Parameter(order = 1)
127            // @Description(
128            // shortName = "Fuzzy smoothing factor",
129            // name = "Fuzzy smoothing factor",
130            // description = "Smoothing factor used in the construction of fuzzy fingerprints.")
131            // private int fuzzySmoothingFactor;
132    
133            /**
134             * XML configuration file.
135             */
136            @Parameter(order = 1)
137            @Description(shortName = "XML config", name = "XML configuration string", description = "XML configuration string.")
138            private Optional<String> xmlConfig;
139    
140            /**
141             * Constructor with default settings.
142             */
143            public Builder() {
144                this.xmlConfig = Optional.absent();
145            }
146    
147            /**
148             * Constructor based on a parameter object.
149             * @param parameters Parameter object
150             */
151            public Builder(final ThreadLocalizedPfParameters parameters) {
152                this.xmlConfig = parameters.getXmlConfig();
153            }
154    
155            /**
156             * Sets configuration xml string.
157             * @param xmlConfig configuration string
158             * @return reference to this builder
159             */
160            public Builder xmlConfig(final String xmlConfig) {
161                this.xmlConfig = Optional.of(xmlConfig);
162                return this;
163            }
164    
165            /**
166             * Sets configuration xml string.
167             * @param xmlConfig configuration string
168             * @return reference to this builder
169             */
170            public Builder xmlConfig(Optional<String> xmlConfig) {
171                this.xmlConfig = xmlConfig;
172                return this;
173            }
174    
175            @Override
176            public ThreadLocalizedPfParameters build() {
177                return new ThreadLocalizedPfParameters(this);
178            }
179        }
180    }
181    
182    
183    
184