001 /*
002 * This file is part of muCommander, http://www.mucommander.com
003 * Copyright (C) 2002-2008 Maxence Bernard
004 *
005 * muCommander is free software; you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation; either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * muCommander is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
017 */
018
019 package com.mucommander.file.filter;
020
021 import java.util.Iterator;
022 import java.util.Vector;
023
024 /**
025 * ChainedFileFilter combines one or several {@link FileFilter} to act as just one.
026 *{@link #addFileFilter(FileFilter)} and {@link #removeFileFilter(FileFilter)} allow to add or remove a
027 * <code>FileFilter</code>, {@link #getFileFilterIterator()} to iterate through all the registered filters.
028 *
029 * <p>The {@link AndFileFilter} and {@link OrFileFilter} implementations match files that respectively match all of
030 * the registered filters, or any of them</p>.
031 *
032 * @see AndFileFilter
033 * @see OrFileFilter
034 * @author Maxence Bernard
035 */
036 public abstract class ChainedFileFilter extends FileFilter {
037
038 /** List of registered FileFilter */
039 protected Vector filters = new Vector();
040
041 /**
042 * Creates a new ChainedFileFilter that initially contains no {@link FileFilter}.
043 */
044 public ChainedFileFilter() {
045 }
046
047 /**
048 * Adds a new {@link FileFilter} to the list of chained filters.
049 *
050 * @param filter the FileFilter to add
051 */
052 public void addFileFilter(FileFilter filter) {
053 filters.add(filter);
054 }
055
056 /**
057 * Removes a {@link FileFilter} to the list of chained filters. Does nothing if the given <code>FileFilter</code>
058 * is not contained by this <code>ChainedFileFilter</code>.
059 *
060 * @param filter the FileFilter to remove
061 */
062 public void removeFileFilter(FileFilter filter) {
063 filters.remove(filter);
064 }
065
066 /**
067 * Returns an <code>Iterator</code> that traverses all the registered filters.
068 *
069 * @return an <code>Iterator</code> that traverses all the registered filters.
070 */
071 public Iterator getFileFilterIterator() {
072 return filters.iterator();
073 }
074
075 /**
076 * Returns <code>true</code> if this chained filter doesn't contain any file filter.
077 *
078 * @return <code>true</code> if this chained filter doesn't contain any file filter.
079 */
080 public boolean isEmpty() {
081 return filters.isEmpty();
082 }
083 }