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 String are the same despite case letters, 0
009 * in the other case
010 */
011public class EqualsStringIgnoreCase implements LocalSimilarityFunction {
012
013        /**
014         * Applies the similarity funciton.
015         * 
016         * @param s
017         *            String
018         * @param t
019         *            String
020         * @return the result of apply the similarity function.
021         */
022        public double compute(Object s, Object t) throws NoApplicableSimilarityFunctionException {
023                if ((s == null) || (t == null))
024                        return 0;
025                if (!(s instanceof String))
026                        throw new NoApplicableSimilarityFunctionException(this.getClass(), s.getClass());
027                if (!(t instanceof String))
028                        throw new NoApplicableSimilarityFunctionException(this.getClass(), t.getClass());
029
030                return (((String) s).equalsIgnoreCase(((String) t)) ? 1 : 0);
031        }
032        
033        /** Applicable to String */
034        public boolean isApplicable(Object o1, Object o2)
035        {
036                if((o1==null)&&(o2==null))
037                        return true;
038                else if(o1==null)
039                        return o2 instanceof String;
040                else if(o2==null)
041                        return o1 instanceof String;
042                else
043                        return (o1 instanceof String)&&(o2 instanceof String);
044        }
045}