001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.filter;
018
019import java.io.Serializable;
020
021import org.apache.commons.vfs2.FileFilter;
022import org.apache.commons.vfs2.FileSelectInfo;
023import org.apache.commons.vfs2.FileSystemException;
024
025/**
026 * Filter that accepts files whose size is >= minimum size and <= maximum
027 * size.
028 *
029 * @since 2.4
030 */
031public class SizeRangeFileFilter implements FileFilter, Serializable {
032
033    private static final long serialVersionUID = 1L;
034
035    /**
036     * File filter for min/max.
037     */
038    private final FileFilter fileFilter;
039
040    /**
041     * Constructor with sizes.
042     *
043     * @param minSizeInclusive the minimum file size (inclusive)
044     * @param maxSizeInclusive the maximum file size (inclusive)
045     */
046    public SizeRangeFileFilter(final long minSizeInclusive, final long maxSizeInclusive) {
047        final FileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true);
048        final FileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false);
049        fileFilter = new AndFileFilter(minimumFilter, maximumFilter);
050    }
051
052    @Override
053    public boolean accept(final FileSelectInfo fileSelectInfo) throws FileSystemException {
054        return fileFilter.accept(fileSelectInfo);
055    }
056
057}