// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static boolean canTranspose(ITabularFormula formula, ITier tier, int varName1, int varName2)
// {
//     ITier otherTier = ensureTheOnlyTierWithVariableExistsAndGetTheTier(formula, varName1);
//         
//     if (otherTier != tier)
//     {
//         return false;
//     }
//     otherTier = ensureTheOnlyTierWithVariableExistsAndGetTheTier(formula, varName2);
//     if (otherTier != tier)
//     {
//         return false;
//     }
//     return true;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static boolean endsWith(ITabularFormula formula, int varName1, int varName2)
// {
//     IPermutation permutation = formula.getPermutation();
//         
//     int permutationSize = permutation.size();
//         
//     return permutation.get(permutationSize - 2) == varName1
//         && permutation.get(permutationSize - 1) == varName2;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static ITier ensureTheOnlyTierWithVariableExistsAndGetTheTier(ITabularFormula formula, int varName)
// {
//     ObjectArrayList tiers = formula.findTiersFor(varName);
//     if (tiers == null)
//     {
//         return null;
//     }
//     if (tiers.size() == 1)
//     {
//         return (ITier) tiers.get(0);
//     }
//     return null;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static ITier ensureTheOnlyTierWithVariablesExistsAndGetTheTier(ITabularFormula formula, int varName1, int varName2)
// {
//     ObjectArrayList tiers = formula.findTiersFor(varName1, varName2);
//     if (tiers == null)
//     {
//         return null;
//     }
//     if (tiers.size() == 1)
//     {
//         return (ITier) tiers.get(0);
//     }
//     return null;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static boolean startsWith(ITabularFormula formula, int varName)
// {
//     return formula.getPermutation().get(0) == varName;
// }


import static com.anjlab.sat3.Join2BetweenTiers.canTranspose;
import static com.anjlab.sat3.JoinMethods.endsWith;
import static com.anjlab.sat3.JoinMethods.ensureTheOnlyTierWithVariableExistsAndGetTheTier;
import static com.anjlab.sat3.JoinMethods.ensureTheOnlyTierWithVariablesExistsAndGetTheTier;
import static com.anjlab.sat3.JoinMethods.startsWith;
import cern.colt.list.ObjectArrayList;

/*
 * Copyright (c) 2010 AnjLab
 * 
 * This file is part of 
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem.
 * 
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem 
 * is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem
 * is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem.
 * If not, see <http://www.gnu.org/licenses/>.
 */
package com.anjlab.sat3;


public class JoinMethods
{
    private static final IJoinMethod[] joinMethods = 
                        new IJoinMethod[]
                        {
                            //  The order matters 
                            new Join3AsIs(),
                            new Join3BetweenTiers(),
                            new Join2BetweenTiers(),
                            new Join2Right(),
                            new Join2Left(),
                            new Join1Right(),
                            new Join1Left(),
                            new Join0(),
                        };  
    
    public static IJoinMethod[] getMethods()
    {
        return joinMethods;
    }

    public static boolean missingAll(ITabularFormula formula, int varName1, int varName2)
    {
        IPermutation permutation = formula.getPermutation();
        
        return !permutation.contains(varName1)
            && !permutation.contains(varName2);
    }


// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static boolean canTranspose(ITabularFormula formula, ITier tier, int varName1, int varName2)
// {
//     ITier otherTier = ensureTheOnlyTierWithVariableExistsAndGetTheTier(formula, varName1);
//         
//     if (otherTier != tier)
//     {
//         return false;
//     }
//     otherTier = ensureTheOnlyTierWithVariableExistsAndGetTheTier(formula, varName2);
//     if (otherTier != tier)
//     {
//         return false;
//     }
//     return true;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static boolean endsWith(ITabularFormula formula, int varName1, int varName2)
// {
//     IPermutation permutation = formula.getPermutation();
//         
//     int permutationSize = permutation.size();
//         
//     return permutation.get(permutationSize - 2) == varName1
//         && permutation.get(permutationSize - 1) == varName2;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static ITier ensureTheOnlyTierWithVariableExistsAndGetTheTier(ITabularFormula formula, int varName)
// {
//     ObjectArrayList tiers = formula.findTiersFor(varName);
//     if (tiers == null)
//     {
//         return null;
//     }
//     if (tiers.size() == 1)
//     {
//         return (ITier) tiers.get(0);
//     }
//     return null;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static ITier ensureTheOnlyTierWithVariablesExistsAndGetTheTier(ITabularFormula formula, int varName1, int varName2)
// {
//     ObjectArrayList tiers = formula.findTiersFor(varName1, varName2);
//     if (tiers == null)
//     {
//         return null;
//     }
//     if (tiers.size() == 1)
//     {
//         return (ITier) tiers.get(0);
//     }
//     return null;
// }
// 
// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
// public static boolean startsWith(ITabularFormula formula, int varName)
// {
//     return formula.getPermutation().get(0) == varName;
// }


// Path: 3-sat-core/src/main/java/com/anjlab/sat3/JoinMethods.java
import static com.anjlab.sat3.Join2BetweenTiers.canTranspose;
import static com.anjlab.sat3.JoinMethods.endsWith;
import static com.anjlab.sat3.JoinMethods.ensureTheOnlyTierWithVariableExistsAndGetTheTier;
import static com.anjlab.sat3.JoinMethods.ensureTheOnlyTierWithVariablesExistsAndGetTheTier;
import static com.anjlab.sat3.JoinMethods.startsWith;
import cern.colt.list.ObjectArrayList;

/*
 * Copyright (c) 2010 AnjLab
 * 
 * This file is part of 
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem.
 * 
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem 
 * is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem
 * is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with
 * Reference Implementation of Romanov's Polynomial Algorithm for 3-SAT Problem.
 * If not, see <http://www.gnu.org/licenses/>.
 */
package com.anjlab.sat3;


public class JoinMethods
{
    private static final IJoinMethod[] joinMethods = 
                        new IJoinMethod[]
                        {
                            //  The order matters 
                            new Join3AsIs(),
                            new Join3BetweenTiers(),
                            new Join2BetweenTiers(),
                            new Join2Right(),
                            new Join2Left(),
                            new Join1Right(),
                            new Join1Left(),
                            new Join0(),
                        };  
    
    public static IJoinMethod[] getMethods()
    {
        return joinMethods;
    }

    public static boolean missingAll(ITabularFormula formula, int varName1, int varName2)
    {
        IPermutation permutation = formula.getPermutation();
        
        return !permutation.contains(varName1)
            && !permutation.contains(varName2);
    }


    public static boolean startsWith(ITabularFormula formula, int varName)
