001package org.biopax.paxtools.pattern.constraint;
002
003import org.biopax.paxtools.model.level3.*;
004import org.biopax.paxtools.model.level3.Process;
005import org.biopax.paxtools.pattern.Match;
006
007import java.util.Set;
008
009/**
010 * Checks if a controller of this Control is also a participant of the controlled interactions. It
011 * satisfies if not.
012 *
013 * var0 is a Control
014 *
015 * @author Ozgun Babur
016 */
017public class ControlsNotParticipant extends ConstraintAdapter
018{
019        /**
020         * Constructor.
021         */
022        public ControlsNotParticipant()
023        {
024                super(1);
025        }
026
027        /**
028         * Checks if the controlled Interaction contains a controller as a participant. This constraint
029         * filters out such cases.
030         * @param match current pattern match
031         * @param ind mapped indices
032         * @return true if participants of teh controlled Interactions not also a controller of the
033         * Control.
034         */
035        @Override
036        public boolean satisfies(Match match, int... ind)
037        {
038                Control ctrl = (Control) match.get(ind[0]);
039
040                for (Process process : ctrl.getControlled())
041                {
042                        if (process instanceof Interaction)
043                        {
044                                Interaction inter = (Interaction) process;
045                                Set<Entity> participant = inter.getParticipant();
046                                for (Controller controller : ctrl.getController())
047                                {
048                                        if (participant.contains(controller)) return false;
049                                }
050                        }
051                }
052                return true;
053        }
054}