]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.mapping/src/org/simantics/mapping/rule/AndRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.mapping / src / org / simantics / mapping / rule / AndRule.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.mapping.rule;
13
14 import gnu.trove.map.hash.TObjectIntHashMap;
15
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;
21
22 public class AndRule implements IRule {
23
24         IRule[] rules;  
25         
26         public AndRule(IRule ... rules) {
27                 this.rules = rules;
28         }
29
30         @Override
31         public ImmutableSet<Resource> binds() {
32                 ImmutableSet<Resource> ret = ImmutableSet.empty();
33                 for(IRule rule : rules)
34                         ret = ret.addAll(rule.binds());
35                 return ret;
36         }
37
38         @Override
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);
45         }
46
47 }