001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojavax.bio.db.biosql;
023import java.lang.reflect.InvocationTargetException;
024import java.lang.reflect.Method;
025import java.util.Collections;
026import java.util.Map;
027
028import org.biojava.bio.seq.Feature;
029
030/**
031 * The class that accepts all features.
032 * <p>
033 * Use the FeatureFilter.all member.
034 *
035 * @author Thomas Down
036 * @author Matthew Pocock
037 * @author Richard Holland
038 * @since 1.5
039 */
040public class BioSQLAcceptAllFilter implements BioSQLFeatureFilter {
041    private Method isNotNull;
042    
043    protected BioSQLAcceptAllFilter() {
044        super();
045        try {
046            // Lazy load the Restrictions class.
047            Class restrictions = Class.forName("org.hibernate.criterion.Restrictions");
048            // Lookup the isNull method
049            this.isNotNull = restrictions.getMethod("isNotNull", new Class[]{String.class});
050        } catch (ClassNotFoundException e) {
051            throw new RuntimeException(e);
052        } catch (NoSuchMethodException e) {
053            throw new RuntimeException(e);
054        }
055    }
056    
057    public Object asCriterion() {
058        try {
059            // All feature have parents, so checking for not-null means all will be returned.
060            return this.isNotNull.invoke(null,new Object[]{"parent"});
061        } catch (InvocationTargetException e) {
062            throw new RuntimeException(e);
063        } catch (IllegalAccessException e) {
064            throw new RuntimeException(e);
065        }
066    }
067    
068    public Map criterionAliasMap() {
069        return Collections.EMPTY_MAP;
070    }
071    
072    public boolean equals(Object o) {
073        return o instanceof BioSQLAcceptAllFilter;
074    }
075    
076    public boolean accept(Feature f) { return true; }
077    
078    public int hashCode() {
079        return 0;
080    }
081    
082    public String toString() {
083        return "All";
084    }
085}
086