001package es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.similarity.local;
002
003
004import es.ucm.fdi.gaia.jcolibri.exception.NoApplicableSimilarityFunctionException;
005import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.similarity.LocalSimilarityFunction;
006
007/**
008 * This function returns 1 if both individuals are equal, otherwise returns 0
009 */
010public class Equal implements LocalSimilarityFunction {
011
012        /**
013         * Applies the similarity function.
014         * 
015         * @param o1
016         *            Object.
017         * @param o2
018         *            Object.
019         * @return the result of apply the similarity function.
020         */
021    public double compute(Object o1, Object o2) throws NoApplicableSimilarityFunctionException {
022        if ((o1 == null) || (o2 == null))
023            return 0;
024        return o1.equals(o2) ? 1 : 0;
025    }
026    
027    /** Applicable to any class */
028        public boolean isApplicable(Object o1, Object o2)
029        {
030                return true;
031        }
032}