/*
 * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.actions;

/**
 * Provides methods to automatically generated condition tree for a specified
 * number of arguments.
 * 
 * @since 0.6
 * @author chris
 */
public abstract class ConditionTreeFactory {
    
    /**
     * Retrieves a condition tree for the specified number of arguments.
     * 
     * @param args The number of arguments in the {@link Action}
     * @return A ConditionTree for the specified number of args
     */
    public abstract ConditionTree getConditionTree(final int args);
    
    /**
     * Creates condition trees where the arguments are conjoined together.
     */
    public static class ConjunctionFactory extends ConditionTreeFactory {

        /** {@inheritDoc} */
        @Override
        public ConditionTree getConditionTree(final int args) {
            return ConditionTree.createConjunction(args);
        }
        
    }

    /**
     * Creates condition trees where the arguments are disjoined together.
     */
    public static class DisjunctionFactory extends ConditionTreeFactory {

        /** {@inheritDoc} */
        @Override
        public ConditionTree getConditionTree(final int args) {
            return ConditionTree.createDisjunction(args);
        }
        
    }
    
    /**
     * Creates condition trees with a custom structure.
     */
    public static class CustomFactory extends ConditionTreeFactory {
        
        /** The condition tree to use. */
        protected final ConditionTree tree;

        /**
         * Creates a new CustomFactory for the specified tree.
         * 
         * @param tree The tree to use
         */
        public CustomFactory(final ConditionTree tree) {
            this.tree = tree;
        }

        /** {@inheritDoc} */
        @Override
        public ConditionTree getConditionTree(final int args) {
            return tree;
        }
        
    }
    
    /**
     * Retrieves a factory that will extrapolate the specified
     * {@link ConditionTree} for different number of arguments, if applicable.
     * 
     * @param tree The {@link ConditionTree} that's in use
     * @param args The number of conditions currently in use
     * @return A {@link ConditionTreeFactory} that will create relevant
     * {@link ConditionTree}s
     */
    public static ConditionTreeFactory getFactory(final ConditionTree tree, final int args) {
        if (tree.equals(ConditionTree.createConjunction(args))) {
            return new ConjunctionFactory();
        } else if (tree.equals(ConditionTree.createDisjunction(args))) {
            return new DisjunctionFactory();
        } else {
            return new CustomFactory(tree);
        }
    }

}

@@ -1368,25 +1368,29 @@
 ctory %7B%0A    
+    
 %0A
-
     /**%0A    
@@ -1676,32 +1676,559 @@
 );%0A    %0A    /**%0A
+     * Retrieves the type this of factory.%0A     * %0A     * @return This factory's type%0A     */%0A    public abstract ConditionTreeFactoryType getType();%0A    %0A    /**%0A     * The possible types of ConditionTreeFactories%0A     */%0A    public static enum ConditionTreeFactoryType %7B%0A        /** Factories that produce disjunction (OR) trees. */%0A        DISJUNCTION,%0A        /** Factories that produce conjunction (AND) trees. */%0A        CONJUNCTION,%0A        /** Factories that produce custom trees. */%0A        CUSTOM,%0A    %7D%0A    %0A    /**%0A
      * Creates c
@@ -2539,32 +2539,199 @@
 args);%0A        %7D
+%0A%0A        /** %7B@inheritDoc%7D */%0A        @Override%0A        public ConditionTreeFactoryType getType() %7B%0A            return ConditionTreeFactoryType.CONJUNCTION;%0A        %7D
 %0A        %0A    %7D%0A
@@ -3077,32 +3077,207 @@
      %7D%0A        %0A
+        /** %7B@inheritDoc%7D */%0A        @Override%0A        public ConditionTreeFactoryType getType() %7B%0A            return ConditionTreeFactoryType.DISJUNCTION;%0A        %7D%0A        %0A
     %7D%0A    %0A    /
@@ -3847,32 +3847,32 @@
 nal int args) %7B%0A
-
             retu
@@ -3891,32 +3891,202 @@
      %7D%0A        %0A
+        /** %7B@inheritDoc%7D */%0A        @Override%0A        public ConditionTreeFactoryType getType() %7B%0A            return ConditionTreeFactoryType.CUSTOM;%0A        %7D%0A        %0A
     %7D%0A    %0A    /

Add ConditionTreeFactory{Type,.getType} Additional work on issue 1566