001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program 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 * This program 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 */
020package org.sonar.api.batch.fs.internal;
021
022import org.sonar.api.batch.fs.FilePredicate;
023import org.sonar.api.batch.fs.FileSystem;
024import 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 */
029public 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}