001 package jcolibri.method.retrieve.NNretrieval.similarity.local; 002 003 004 005 import 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 */ 011 public 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 jcolibri.exception.NoApplicableSimilarityFunctionException { 023 if ((s == null) || (t == null)) 024 return 0; 025 if (!(s instanceof java.lang.String)) 026 throw new jcolibri.exception.NoApplicableSimilarityFunctionException(this.getClass(), s.getClass()); 027 if (!(t instanceof java.lang.String)) 028 throw new jcolibri.exception.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 }