001    package org.hd.d.pg2k.ai.scorer;
002    
003    import java.util.List;
004    
005    /**Simple abstract super class for some non-parameterised Scorers.
006     * Prevents creation of parameterised instances.
007     *
008     * @author dhd
009     */
010    public abstract class AbstractNonParamScorer extends AbstractScorer
011        {
012        /**Default constructor uses class-based name and allows no parameterisation. */
013        protected AbstractNonParamScorer()
014            { }
015    
016        /**Construct instance with name and optional parameters.
017         * Insists on the parameter being exactly the default (non-parameterised) name.
018         *
019         * @throws IllegalArgumentException  if parameter is wrong
020         */
021        protected AbstractNonParamScorer(final String nameAndParameters)
022            throws IllegalArgumentException
023            {
024            this();
025            if(!getDefaultName().equals(nameAndParameters))
026                { throw new IllegalArgumentException(); }
027            }
028    
029        /**Construct instance with name and optional parameters.
030         * Insists on the parameter being exactly the default (non-parameterised) name.
031         *
032         * @throws IllegalArgumentException  if parameter is wrong
033         */
034        protected AbstractNonParamScorer(final String baseName, final List<ScorerParam> parameters)
035            throws IllegalArgumentException
036            {
037            this();
038            if(!parameters.isEmpty()) { throw new IllegalArgumentException(); }
039            if(!getDefaultName().equals(baseName))
040                { throw new IllegalArgumentException(); }
041            }
042    
043        /**Insists that the name is the default non-parameterised name, and returns the original. */
044        public ScorerIF createVariant(final String nameAndParameters) throws IllegalArgumentException
045            {
046            if(!this.nameAndParameters.equals(nameAndParameters))
047                { throw new IllegalArgumentException(); }
048            return(this); // Saves creating new instances.
049            }
050    
051        /**Insists that the base name is correct, and that there are no parameters, and returns the original. */
052        public ScorerIF createVariant(final String baseName, final List<ScorerParam> parameters) throws IllegalArgumentException
053            {
054            if(!parameters.isEmpty()) { throw new IllegalArgumentException(); }
055            if(!nameAndParameters.equals(baseName))
056                { throw new IllegalArgumentException(); }
057            return(this); // Saves creating new instances.
058            }
059        }