001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * troger 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.ecm.core.api.impl; 016 017import java.util.ArrayList; 018import java.util.Arrays; 019import java.util.List; 020 021import org.nuxeo.ecm.core.api.DocumentModel; 022import org.nuxeo.ecm.core.api.Filter; 023 024/** 025 * A filter based on a list of others filters. To accept a document, all the registered filters must accept it. 026 * 027 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 028 */ 029public class CompoundFilter implements Filter { 030 031 private static final long serialVersionUID = 5755619357049775017L; 032 033 private final List<Filter> filters; 034 035 /** 036 * Generic constructor. 037 * 038 * @param filters 039 */ 040 public CompoundFilter(Filter... filters) { 041 this(Arrays.asList(filters)); 042 } 043 044 /** 045 * Generic constructor. 046 * 047 * @param filters 048 */ 049 public CompoundFilter(List<Filter> filters) { 050 if (filters == null) { 051 this.filters = new ArrayList<Filter>(); 052 } else { 053 this.filters = filters; 054 } 055 } 056 057 @Override 058 public boolean accept(DocumentModel docModel) { 059 for (Filter filter : filters) { 060 if (!filter.accept(docModel)) { 061 return false; 062 } 063 } 064 return true; 065 } 066 067}