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.rule;
14 import gnu.trove.map.hash.TObjectIntHashMap;
16 import org.simantics.db.Resource;
17 import org.simantics.mapping.constraint.TooManyUnboundVariablesException;
18 import org.simantics.mapping.rule.instructions.AndRuleInstruction;
19 import org.simantics.mapping.rule.instructions.IRuleInstruction;
20 import org.simantics.utils.datastructures.persistent.ImmutableSet;
22 public class AndRule implements IRule {
26 public AndRule(IRule ... rules) {
31 public ImmutableSet<Resource> binds() {
32 ImmutableSet<Resource> ret = ImmutableSet.empty();
33 for(IRule rule : rules)
34 ret = ret.addAll(rule.binds());
39 public IRuleInstruction createInstruction(
40 TObjectIntHashMap<Resource> variableIds, ImmutableSet<Resource> bound) throws TooManyUnboundVariablesException {
41 IRuleInstruction[] instructions = new IRuleInstruction[rules.length];
42 for(int i=0;i<rules.length;++i)
43 instructions[i] = rules[i].createInstruction(variableIds, bound);
44 return new AndRuleInstruction(instructions);