X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.mapping%2Fsrc%2Forg%2Fsimantics%2Fmapping%2Fconstraint%2FBinaryPredicateConstraint.java;h=f979698f78a2bc6ac42c6fcc5a1d35ab0d00cc00;hb=84b52b5e5dc00fd0ddfab398e420b56b379ee867;hp=1e4f1defe44e2af3e7a542683f9062c93a35f5a8;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.mapping/src/org/simantics/mapping/constraint/BinaryPredicateConstraint.java b/bundles/org.simantics.mapping/src/org/simantics/mapping/constraint/BinaryPredicateConstraint.java index 1e4f1defe..f979698f7 100644 --- a/bundles/org.simantics.mapping/src/org/simantics/mapping/constraint/BinaryPredicateConstraint.java +++ b/bundles/org.simantics.mapping/src/org/simantics/mapping/constraint/BinaryPredicateConstraint.java @@ -1,80 +1,80 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.mapping.constraint; - -import gnu.trove.map.hash.TObjectIntHashMap; - -import org.simantics.db.Resource; -import org.simantics.layer0.utils.binaryPredicates.IBinaryPredicate; -import org.simantics.mapping.constraint.instructions.BinaryPredicateInstruction; -import org.simantics.mapping.constraint.instructions.BinaryPredicateObjectQuery; -import org.simantics.mapping.constraint.instructions.BinaryPredicateSubjectQuery; -import org.simantics.mapping.constraint.instructions.IInstruction; -import org.simantics.utils.datastructures.persistent.ImmutableSet; - -public class BinaryPredicateConstraint implements IConstraint { - - Resource variable0; - Resource variable1; - IBinaryPredicate predicate; - - public BinaryPredicateConstraint(IBinaryPredicate predicate, - Resource variable0, Resource variable1) { - this.predicate = predicate; - this.variable0 = variable0; - this.variable1 = variable1; - } - - @Override - public ImmutableSet binds() { - return ImmutableSet.of(variable0, variable1); - } - - @Override - public IInstruction createInstruction( - TObjectIntHashMap variableIds, - ImmutableSet bound) throws TooManyUnboundVariablesException { - int id0 = variableIds.get(variable0); - int id1 = variableIds.get(variable1); - if(bound.contains(variable0)) { - if(bound.contains(variable1)) - return new BinaryPredicateInstruction(id0, id1, predicate); - else - return new BinaryPredicateObjectQuery(id0, id1, predicate); - } - else { - if(bound.contains(variable1)) - return new BinaryPredicateSubjectQuery(id0, id1, predicate); - else - throw new TooManyUnboundVariablesException(); - } - } - - @Override - public int isApplicable(ImmutableSet bound) { - if(bound.contains(variable0)) { - if(bound.contains(variable1)) - return Integer.MAX_VALUE; - else if(predicate.supportsGetObjects()) - return Integer.MAX_VALUE; - else - return 0; - } - else { - if(bound.contains(variable1) && predicate.supportsGetSubjects()) - return Integer.MAX_VALUE; - else - return 0; - } - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.mapping.constraint; + +import gnu.trove.map.hash.TObjectIntHashMap; + +import org.simantics.db.Resource; +import org.simantics.layer0.utils.binaryPredicates.IBinaryPredicate; +import org.simantics.mapping.constraint.instructions.BinaryPredicateInstruction; +import org.simantics.mapping.constraint.instructions.BinaryPredicateObjectQuery; +import org.simantics.mapping.constraint.instructions.BinaryPredicateSubjectQuery; +import org.simantics.mapping.constraint.instructions.IInstruction; +import org.simantics.utils.datastructures.persistent.ImmutableSet; + +public class BinaryPredicateConstraint implements IConstraint { + + Resource variable0; + Resource variable1; + IBinaryPredicate predicate; + + public BinaryPredicateConstraint(IBinaryPredicate predicate, + Resource variable0, Resource variable1) { + this.predicate = predicate; + this.variable0 = variable0; + this.variable1 = variable1; + } + + @Override + public ImmutableSet binds() { + return ImmutableSet.of(variable0, variable1); + } + + @Override + public IInstruction createInstruction( + TObjectIntHashMap variableIds, + ImmutableSet bound) throws TooManyUnboundVariablesException { + int id0 = variableIds.get(variable0); + int id1 = variableIds.get(variable1); + if(bound.contains(variable0)) { + if(bound.contains(variable1)) + return new BinaryPredicateInstruction(id0, id1, predicate); + else + return new BinaryPredicateObjectQuery(id0, id1, predicate); + } + else { + if(bound.contains(variable1)) + return new BinaryPredicateSubjectQuery(id0, id1, predicate); + else + throw new TooManyUnboundVariablesException(); + } + } + + @Override + public int isApplicable(ImmutableSet bound) { + if(bound.contains(variable0)) { + if(bound.contains(variable1)) + return Integer.MAX_VALUE; + else if(predicate.supportsGetObjects()) + return Integer.MAX_VALUE; + else + return 0; + } + else { + if(bound.contains(variable1) && predicate.supportsGetSubjects()) + return Integer.MAX_VALUE; + else + return 0; + } + } + +}