]> gerrit.simantics Code Review - simantics/platform.git/blob
7b2bfc60909cd984029fc53f546ab55d0f343222
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.query.compilation;
2
3 import gnu.trove.impl.Constants;
4 import gnu.trove.map.hash.TObjectIntHashMap;
5
6 import java.util.ArrayList;
7
8 import org.simantics.scl.compiler.elaboration.expressions.Variable;
9
10 public class ConstraintCollectionContext {
11     QueryCompilationContext context;
12     ArrayList<Variable> variables = new ArrayList<Variable>();
13     TObjectIntHashMap<Variable> variableMap = new TObjectIntHashMap<Variable>(
14             Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1);
15     ArrayList<QueryConstraint> constraints = new ArrayList<QueryConstraint>(); 
16     
17     public ConstraintCollectionContext(QueryCompilationContext context) {
18         this.context = context;
19     }
20
21     public int addVariable(Variable variable) {
22         int id = variables.size();
23         variables.add(variable);
24         variableMap.put(variable, id);
25         return id;
26     }
27     
28     public TObjectIntHashMap<Variable> getVariableMap() {
29         return variableMap;
30     }
31     
32     public void addConstraint(QueryConstraint constraint) {
33         constraints.add(constraint);
34     }
35
36     public QueryConstraint[] getConstraints() {
37         return constraints.toArray(new QueryConstraint[constraints.size()]);
38     }
39     
40     public QueryCompilationContext getQueryCompilationContext() {
41         return context;
42     }
43     
44     public Variable getVariable(int id) {
45         return variables.get(id);
46     }
47 }