1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.mapping.constraint;
14 import gnu.trove.map.hash.TObjectIntHashMap;
16 import org.simantics.db.Resource;
17 import org.simantics.mapping.constraint.instructions.AndInstruction;
18 import org.simantics.mapping.constraint.instructions.IInstruction;
19 import org.simantics.utils.datastructures.persistent.ImmutableSet;
21 public class ConstraintConjunction implements IConstraint {
23 IConstraint[] constraints;
25 public ConstraintConjunction(IConstraint... constraints) {
26 this.constraints = constraints;
30 public ImmutableSet<Resource> binds() {
31 ImmutableSet<Resource> ret = ImmutableSet.empty();
32 for(IConstraint c : constraints)
33 ret = ret.addAll(c.binds());
38 public IInstruction createInstruction(
39 TObjectIntHashMap<Resource> variableIds,
40 ImmutableSet<Resource> bound) throws TooManyUnboundVariablesException {
41 IInstruction[] instructions = new IInstruction[constraints.length];
42 for(int i=0;i<constraints.length;++i) {
43 instructions[i] = constraints[i].createInstruction(variableIds, bound);
44 bound = bound.addAll(constraints[i].binds());
46 return new AndInstruction(instructions);
50 public int isApplicable(ImmutableSet<Resource> bound) {
51 int ret = Integer.MAX_VALUE;
52 for(int i=0;i<constraints.length;++i) {
53 int temp = constraints[i].isApplicable(bound);
59 bound = bound.addAll(constraints[i].binds());