001package org.biopax.paxtools.pattern.constraint;
002
003import org.biopax.paxtools.pattern.Constraint;
004import org.biopax.paxtools.pattern.Match;
005
006/**
007 * Checks if the parameter constraint cannot generate any candidate.
008 *
009 * @author Ozgun Babur
010 */
011public class Empty extends ConstraintAdapter
012{
013        /**
014         * The generative constraint to check if it generates nothing.
015         */
016        Constraint con;
017
018        /**
019         * Constructor with the generative Constraint.
020         * @param con the generative Constraint
021         */
022        public Empty(Constraint con)
023        {
024                if (!con.canGenerate()) throw new IllegalArgumentException(
025                        "The constraint has to be a generative constraint");
026
027                this.con = con;
028        }
029
030        /**
031         * Variable size is one less than the wrapped Constraint.
032         * @return one less than the size of teh wrapped constraint
033         */
034        @Override
035        public int getVariableSize()
036        {
037                return con.getVariableSize() - 1;
038        }
039
040        /**
041         * Cannot generate
042         * @return false
043         */
044        @Override
045        public boolean canGenerate()
046        {
047                return false;
048        }
049
050        /**
051         * Checks if the wrapped Constraint can generate any elements. This satisfies if it cannot.
052         * @param match current pattern match
053         * @param ind mapped indices
054         * @return true if the wrapped Constraint generates nothing
055         */
056        @Override
057        public boolean satisfies(Match match, int... ind)
058        {
059                assertIndLength(ind);
060
061                return con.generate(match, ind).isEmpty();
062        }
063}