]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.mapping/src/org/simantics/mapping/constraint/instructions/PrintStateInstruction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.mapping / src / org / simantics / mapping / constraint / instructions / PrintStateInstruction.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.constraint.instructions;
13
14 import gnu.trove.map.hash.TIntIntHashMap;
15 import gnu.trove.set.hash.TIntHashSet;
16
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.mapping.IContextualModification;
20
21 public class PrintStateInstruction implements IInstruction {
22         String position;
23
24         public PrintStateInstruction(String position) {
25                 this.position = position;
26         }
27         
28         private void print(ReadGraph g, Object[] bindings) {
29                 System.out.print(position + ": ");
30                 boolean first = true;
31                 for(Object obj : bindings) {
32                         if(first)
33                                 first = false;
34                         else
35                                 System.out.print(", ");
36                         System.out.print(obj);
37                 }
38                 System.out.println();
39         }
40         
41         @Override
42         public Object query(ReadGraph g, Object[] bindings) {
43                 print(g, bindings);
44                 return null;
45         }
46         
47         @Override
48         public Object next(ReadGraph g, Object[] bindings, Object continuation) {               
49                 return IInstruction.FAILURE;
50         }       
51
52         @Override
53         public IContextualModification claim(ReadGraph g, Object[] bindings) {
54                 print(g, bindings);
55                 return null;
56         }
57
58         @Override
59         public IContextualModification deny(ReadGraph g, Object[] bindings) {
60                 print(g, bindings);
61                 return null;
62         }
63
64         @Override
65         public void doClaim(WriteGraph g, Object[] bindings) {
66                 print(g, bindings);
67         }
68
69         @Override
70         public void doDeny(WriteGraph g, Object[] bindings) {
71                 print(g, bindings);
72         }
73
74         @Override
75         public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
76                 /* Because this instruction is for debugging, it doesn't affect
77                    to the set of read variables. */
78         }
79
80         @Override
81         public void mapVariables(TIntIntHashMap map) {
82         }       
83         
84         @Override
85         public void toString(StringBuilder b, int indent) {
86                 
87         }
88         
89 }