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.ecfp;
011    
012    import com.chemaxon.apidiscovery.annotations.BuilderClass;
013    import com.chemaxon.apidiscovery.interfaces.ParameterBuilder;
014    import com.chemaxon.descriptors.common.DescriptorParameters;
015    import java.io.Serializable;
016    
017    /**
018     * Parameters class for {@link ThreadLocalizedEcfpGenerator}.
019     *
020     * <p>We hope efficiency gain from this dangerous workaround. <b>Use with extreme care!</b>.</p>
021     *
022     * <p>
023     * Conventions and contracts related to {@link com.chemaxon.descriptors} and {@link com.chemaxon.apidiscovery} are not
024     * satisfied by this class.</p>
025     *
026     * @author Gabor Imre
027     */
028    @BuilderClass(builderClass = ThreadLocalizedEcfpParameters.Builder.class)
029    public class ThreadLocalizedEcfpParameters implements DescriptorParameters, Serializable {
030    
031        /**
032         * Serial version.
033         */
034        private static final long serialVersionUID = 0;
035    
036        /**
037         * Represented diameter.
038         */
039        private final int diameter;
040    
041        /**
042         * Parametrize from a builder.
043         *
044         * @param b Builder to use.
045         */
046        public ThreadLocalizedEcfpParameters(Builder b) {
047            this.diameter = b.diameter;
048        }
049    
050        /**
051         * Construct with default parametrization.
052         */
053        public ThreadLocalizedEcfpParameters() {
054            this(new Builder());
055        }
056    
057    
058        @Override
059        public ThreadLocalizedEcfpGenerator getDescriptorGenerator() {
060            return new ThreadLocalizedEcfpGenerator(this);
061            //return new ThreadLocalizedEcfpGenerator((EcfpGeneratorImpl)
062            //        new EcfpParameters.Builder().diameter(this.diameter).build().getDescriptorGenerator());
063        }
064    
065        @Override
066        public String toString() {
067            return "Thread localized ECFP parameters. Diameter: " + this.diameter;
068        }
069    
070        /**
071         * Diameter.
072         *
073         * @return Diameter
074         */
075        public int getDiameter() {
076            return this.diameter;
077        }
078    
079        /**
080         * Construct non thread safe Ecfp generator.
081         *
082         * @return Generator according to the represented parameters
083         */
084        protected EcfpGeneratorImpl constructEcfpGeneratorImpl() {
085            final EcfpParameters p = new EcfpParameters.Builder().diameter(this.diameter).build();
086            final EcfpGeneratorImpl g = (EcfpGeneratorImpl) p.getDescriptorGenerator();
087            return g;
088        }
089    
090        /**
091         * Parameters builder class for {@link ThreadLocalizedEcfpParameters}.
092         */
093        public static class Builder implements ParameterBuilder<ThreadLocalizedEcfpParameters> {
094    
095            /**
096             * Diameter.
097             */
098            private int diameter = EcfpParameters.DEFAULT_ECFP_DIAMETER;
099    
100            /**
101             * Construct.
102             */
103            public Builder() {}
104    
105            /**
106             * Construct from the state of a {@link ThreadLocalizedEcfpParameters}.
107             *
108             * @param params State to reflect.
109             */
110            public Builder(ThreadLocalizedEcfpParameters params) {
111                this.diameter = params.getDiameter();
112            }
113    
114            /**
115             * Update diameter.
116             *
117             * @param diameter New diameter to represent
118             * @return Reference to <code>this</code>
119             */
120            public Builder diameter(int diameter) {
121                this.diameter = diameter;
122                return this;
123            }
124    
125            /**
126             * Build immutable representation.
127             *
128             * @return Immutable parameters object
129             */
130            public ThreadLocalizedEcfpParameters build() {
131                return new ThreadLocalizedEcfpParameters(this);
132            }
133        }
134    }