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;
023
024import java.lang.reflect.InvocationTargetException;
025import java.lang.reflect.Method;
026import java.util.Collections;
027import java.util.Map;
028
029import org.biojava.bio.seq.Feature;
030
031/**
032 * The class that accepts no features.
033 * <p>
034 * Use the FeatureFilter.none member.
035 *
036 * @author Matthew Pocock
037 * @author Richard Holland
038 * @since 1.5
039 */
040public class BioSQLAcceptNoneFilter implements BioSQLFeatureFilter {
041    private Method isNull;
042    
043    protected BioSQLAcceptNoneFilter() {
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.isNull = restrictions.getMethod("isNull", 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 null means none will ever be returned.
060            return this.isNull.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 BioSQLAcceptNoneFilter;
074    }
075    
076    public boolean accept(Feature f) { return false; }
077    
078    public int hashCode() {
079        return 1;
080    }
081    
082    public String toString() {
083        return "None";
084    }
085}
086