001    /*
002     * SonarQube, open source software quality management tool.
003     * Copyright (C) 2008-2014 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * SonarQube is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * SonarQube is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public License
017     * along with this program; if not, write to the Free Software Foundation,
018     * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019     */
020    package org.sonar.api.batch.fs.internal;
021    
022    import org.sonar.api.batch.fs.FilePredicate;
023    import org.sonar.api.batch.fs.FileSystem;
024    import org.sonar.api.batch.fs.InputFile;
025    
026    /**
027     * Optimized version of FilePredicate allowing to speed up query by looking at InputFile by index.
028     */
029    public interface OptimizedFilePredicate extends FilePredicate, Comparable<OptimizedFilePredicate> {
030    
031      /**
032       * Filter provided files to keep only the ones that are valid for this predicate
033       */
034      Iterable<InputFile> filter(Iterable<InputFile> inputFiles);
035    
036      /**
037       * Get all files that are valid for this predicate.
038       */
039      Iterable<InputFile> get(FileSystem.Index index);
040    
041      /**
042       * For optimization. FilePredicates will be applied in priority order. For example when doing
043       * p.and(p1, p2, p3) then p1, p2 and p3 will be applied according to their priority value. Higher priority value
044       * are applied first.
045       * Assign a high priority when the predicate will likely highly reduce the set of InputFiles to filter. Also
046       * {@link RelativePathPredicate} and AbsolutePathPredicate have a high priority since they are using cache index.
047       */
048      int priority();
049    }