/*
 * Copyright (c) 1999-2012, Ecole des Mines de Nantes
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Ecole des Mines de Nantes nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package parser.flatzinc.ast.ext;

import gnu.trove.map.hash.THashMap;
import solver.constraints.Constraint;
import solver.propagation.generator.Arc;
import solver.variables.Variable;

import java.util.ArrayList;
import java.util.List;

/**
 * <br/>
 *
 * @author Charles Prud'homme
 * @since 19/10/12
 */
public class ExtPredicate extends Predicate {

    List<Variable> vars;
    Constraint cstr;

    public ExtPredicate(List<String> ids, THashMap<String, Object> map) {
        vars = new ArrayList<Variable>(ids.size());
        for (int i = 0; i < ids.size(); i++) {
            Object o = map.get(ids.get(i));
            if (o instanceof Variable) {
                vars.add((Variable) o);
            } else if (o instanceof Constraint) {
                cstr = (Constraint) o;
            }else if(o instanceof Variable[]){
                Variable[] allvars = (Variable[])o;
                for(int j = 0; j < allvars.length; j++){
                    vars.add(allvars[j]);
                }
            }
        }
    }

    @Override
    public boolean evaluate(Arc p) {
        return vars.contains(p.var) && (cstr == null || cstr == p.prop.getConstraint());
    }
}

@@ -1981,16 +1981,21 @@
 rs;%0A    
+List%3C
 Constrai
@@ -1996,21 +1996,23 @@
 nstraint
+%3E
  cstr
+s
 ;%0A%0A    p
@@ -2128,24 +2128,79 @@
 ds.size());%0A
+        cstrs = new ArrayList%3CConstraint%3E(ids.size());%0A
         for 
@@ -2429,19 +2429,22 @@
     cstr
- = 
+s.add(
 (Constra
@@ -2449,16 +2449,17 @@
 raint) o
+)
 ;%0A      
@@ -2465,23 +2465,25 @@
        %7D
+ 
 else if
+ 
 (o insta
@@ -2499,16 +2499,17 @@
 iable%5B%5D)
+ 
 %7B%0A      
@@ -2551,16 +2551,17 @@
 iable%5B%5D)
+ 
 o;%0A     
@@ -2574,16 +2574,17 @@
      for
+ 
 (int j =
@@ -2611,16 +2611,17 @@
 th; j++)
+ 
 %7B%0A      
@@ -2700,132 +2700,539 @@
     
-%7D%0A    %7D%0A%0A    @Override%0A    public boolean evaluate(Arc p) %7B%0A        return vars.contains(p.var) && (cstr == null %7C%7C cstr == 
+    if (o instanceof Constraint%5B%5D) %7B%0A                Constraint%5B%5D allcstrs = (Constraint%5B%5D) o;%0A                for (int j = 0; j %3C allcstrs.length; j++) %7B%0A                    cstrs.add(allcstrs%5Bj%5D);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Override%0A    public boolean evaluate(Arc p) %7B%0A        if (cstrs.isEmpty()) %7B%0A            return vars.contains(p.var);%0A        %7D else if (vars.isEmpty()) %7B%0A            return cstrs.contains(p.prop.getConstraint());%0A        %7D%0A        return vars.contains(p.var) && cstrs.contains(
 p.pr

Update ExtPredicate