]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.mapping/src/org/simantics/mapping/constraint/instructions/NotInstruction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.mapping / src / org / simantics / mapping / constraint / instructions / NotInstruction.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.db.exception.DatabaseException;
20 import org.simantics.mapping.IContextualModification;
21
22 public class NotInstruction implements IInstruction {
23         IInstruction instruction;
24
25         public NotInstruction(IInstruction instruction) {
26                 this.instruction = instruction;
27         }
28
29         @Override
30         public IContextualModification claim(ReadGraph g, Object[] bindings) throws DatabaseException {
31                 return instruction.deny(g, bindings);
32         }
33
34         @Override
35         public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
36                 instruction.collectVariables(reads, writes);            
37         }
38
39         @Override
40         public IContextualModification deny(ReadGraph g, Object[] bindings) throws DatabaseException {
41                 return instruction.claim(g, bindings);
42         }
43
44         @Override
45         public void doClaim(WriteGraph g, Object[] bindings) throws DatabaseException {
46                 instruction.doDeny(g, bindings);                
47         }
48
49         @Override
50         public void doDeny(WriteGraph g, Object[] bindings) throws DatabaseException {
51                 instruction.doClaim(g, bindings);               
52         }
53
54         @Override
55         public void mapVariables(TIntIntHashMap map) {
56                 instruction.mapVariables(map);          
57         }
58
59         @Override
60         public Object next(ReadGraph g, Object[] bindings, Object continuation) {
61                 return IInstruction.FAILURE;
62         }
63
64         @Override
65         public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {
66                 if(instruction.query(g, bindings)==IInstruction.FAILURE)
67                         return null;
68                 else
69                         return IInstruction.FAILURE;
70         }
71
72         @Override
73         public void toString(StringBuilder b, int indent) {
74                 b.append("not ");
75                 instruction.toString(b, indent);                
76         }       
77         
78 }