001/** 002 * Equal.java 003 * jCOLIBRI2 framework. 004 * @author Juan A. Recio-Garc�a. 005 * GAIA - Group for Artificial Intelligence Applications 006 * http://gaia.fdi.ucm.es 007 * 28/10/2007 008 */ 009package es.ucm.fdi.gaia.jcolibri.method.retrieve.FilterBasedRetrieval.predicates; 010 011import es.ucm.fdi.gaia.jcolibri.exception.NoApplicableFilterPredicateException; 012 013/** 014 * Predicate that compares if the query object is less than the case object. 015 * Only applicable to enums and numbers. 016 * @author Juan A. Recio-Garcia 017 * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge. 018 * @version 1.0 019 * @see FilterBasedRetrievalMethod 020 * @see FilterConfig 021 */ 022public class QueryLess implements FilterPredicate 023{ 024 public boolean compute(Object caseObject, Object queryObject) throws NoApplicableFilterPredicateException 025 { 026 if((caseObject == null)&&(queryObject==null)) 027 return true; 028 else if(caseObject == null) 029 return false; 030 else if(queryObject == null) 031 return true; 032 else if (! ((caseObject instanceof Number)||(caseObject instanceof Enum))) 033 throw new NoApplicableFilterPredicateException(this.getClass(), caseObject.getClass()); 034 else if (! ((queryObject instanceof Number)||(queryObject instanceof Enum))) 035 throw new NoApplicableFilterPredicateException(this.getClass(), queryObject.getClass()); 036 else 037 { 038 double caseValue; 039 double queryValue; 040 if((caseObject instanceof Number)&&(queryObject instanceof Number)) 041 { 042 Number n1 = (Number) caseObject; 043 caseValue = n1.doubleValue(); 044 Number n2 = (Number) queryObject; 045 queryValue = n2.doubleValue(); 046 } 047 else 048 { 049 Enum<?> enum1 = (Enum<?>)caseObject; 050 caseValue = enum1.ordinal(); 051 Enum<?> enum2 = (Enum<?>)queryObject; 052 queryValue = enum2.ordinal(); 053 } 054 return queryValue<caseValue; 055 } 056 } 057 058}