001    package net.sf.cpsolver.studentsct.filter;
002    
003    import net.sf.cpsolver.studentsct.model.Student;
004    
005    /**
006     * This student filter combines two given student filters with 
007     * logical operation AND or OR.  
008     * 
009     * @version
010     * StudentSct 1.1 (Student Sectioning)<br>
011     * Copyright (C) 2007 Tomáš Müller<br>
012     * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
013     * Lazenska 391, 76314 Zlin, Czech Republic<br>
014     * <br>
015     * This library is free software; you can redistribute it and/or
016     * modify it under the terms of the GNU Lesser General Public
017     * License as published by the Free Software Foundation; either
018     * version 2.1 of the License, or (at your option) any later version.
019     * <br><br>
020     * This library is distributed in the hope that it will be useful,
021     * but WITHOUT ANY WARRANTY; without even the implied warranty of
022     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
023     * Lesser General Public License for more details.
024     * <br><br>
025     * You should have received a copy of the GNU Lesser General Public
026     * License along with this library; if not, write to the Free Software
027     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
028     */
029    public class CombinedStudentFilter implements StudentFilter {
030        /** AND */
031        public static final int OP_AND = 0;
032        /** OR */
033        public static final int OP_OR = 1;
034        private StudentFilter iFirst, iSecond;
035        private int iOp;
036        
037        /**
038         * Constructor
039         * @param first first filter
040         * @param second second filter
041         * @param op logical operation (either {@link CombinedStudentFilter#OP_AND} or {@link CombinedStudentFilter#OP_OR}}) 
042         */
043        public CombinedStudentFilter(StudentFilter first, StudentFilter second, int op) {
044            iFirst = first;
045            iSecond = second;
046            iOp = op;
047        }
048        
049        /** A student is accepted if it is accepted by the first and/or the second filter */
050        public boolean accept(Student student) {
051            switch (iOp) {
052                case OP_OR :
053                    return iFirst.accept(student) || iSecond.accept(student);
054                case OP_AND : 
055                default:
056                    return iFirst.accept(student) && iSecond.accept(student);
057            }
058        }
059    
060    }