001package org.biopax.paxtools.pattern.constraint;
002
003import org.biopax.paxtools.pattern.Match;
004
005/**
006 * Checks identity of two elements.
007 * Size = 2.
008 * Checks if e1 == e2.
009 *
010 * @author Ozgun Babur
011 */
012public class Equality extends ConstraintAdapter
013{
014        /**
015         * Desired output.
016         */
017        private boolean equals;
018
019        /**
020         * Constructor with the desired output.
021         * @param equals the desired output
022         */
023        public Equality(boolean equals)
024        {
025                super(2);
026                this.equals = equals;
027        }
028
029        /**
030         * Checks if the two elements are identical or not identical as desired.
031         * @param match current pattern match
032         * @param ind mapped indices
033         * @return true if identity checks equals the desired value
034         */
035        @Override
036        public boolean satisfies(Match match, int... ind)
037        {
038                assert ind.length == 2;
039
040                return (match.get(ind[0]) == match.get(ind[1])) == equals;
041        }
042}