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.constraint.instructions;
14 import gnu.trove.set.hash.TIntHashSet;
16 import java.util.Collection;
17 import java.util.Iterator;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.layer0.utils.binaryPredicates.IBinaryPredicate;
24 public class BinaryPredicateSubjectQuery extends BinaryPredicateInstruction {
26 public BinaryPredicateSubjectQuery(int variable0, int variable1,
27 IBinaryPredicate predicate) {
28 super(variable0, variable1, predicate);
32 public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {
33 Resource r1 = (Resource)bindings[variable1];
34 Collection<Resource> result = predicate.getSubjects(g, r1);
36 return IInstruction.FAILURE;
37 Iterator<Resource> it = result.iterator();
38 bindings[variable0] = it.next();
45 @SuppressWarnings("unchecked")
47 public Object next(ReadGraph g, Object[] bindings, Object continuation) {
48 Iterator<Resource> it = (Iterator<Resource>)continuation;
50 bindings[variable0] = it.next();
57 return IInstruction.FAILURE;
61 public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
62 super.collectVariables(reads, writes);
63 writes.add(variable0);