1 /** 2 * Copyright 2005 Steve Molloy 3 * 4 * This file is part of OV4J. 5 * 6 * OV4J is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 8 * 9 * OV4J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License along with OV4J; if not, write to the Free Software 13 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 * 15 */ 16 package org.ov4j.db4oImpl; 17 18 import java.util.TreeSet; 19 import java.util.logging.Level; 20 import java.util.logging.Logger; 21 22 import org.ov4j.data.Item; 23 24 import com.db4o.query.Candidate; 25 import com.db4o.query.Evaluation; 26 27 /** 28 * This class is used to validate multiple IDs at once. 29 * 30 * @author smolloy 31 * 32 */ 33 public class MultipleIDValidator<C extends Comparable<? super C>> implements Evaluation { 34 /** 35 * Logger for this class 36 */ 37 private static final Logger logger = Logger.getLogger(MultipleIDValidator.class.getName()); 38 39 /** Serial Version UID. */ 40 private static final long serialVersionUID = 4121131424788460597L; 41 42 /** IDs to used for validation. */ 43 private final TreeSet<C> ids = new TreeSet<C>(); 44 45 /** 46 * Constructor. 47 * 48 * @param ids 49 * IDs to use for validation. 50 */ 51 public MultipleIDValidator(final C[] ids) { 52 if (ids != null) { 53 for (int i = 0; i < ids.length; i++) { 54 if (ids[i] != null) { 55 this.ids.add(ids[i]); 56 } 57 } 58 } 59 } 60 61 /** 62 * Evaluates whether or not the candidate should be included in the results. 63 */ 64 public void evaluate(final Candidate c) { 65 if (MultipleIDValidator.logger.isLoggable(Level.FINEST)) { 66 MultipleIDValidator.logger.entering("MultipleIDValidator", "evaluate(Candidate=" + c + ")", "start"); 67 } 68 69 c.include((c.getObject() instanceof MappedField && ids.contains(((MappedField) c.getObject()).getObject())) 70 || (c.getObject() instanceof Item && ids.contains(((Item<?, C>) c.getObject()).getId()))); 71 72 if (MultipleIDValidator.logger.isLoggable(Level.FINEST)) { 73 MultipleIDValidator.logger.exiting("MultipleIDValidator", "evaluate(Candidate=" + c + ")", "end"); 74 } 75 } 76 }