Java List Include isIndexable(String filename, List includes, List excludes)

Here you can find the source of isIndexable(String filename, List includes, List excludes)

Description

We check if we can index the file or if we should ignore it

License

Apache License

Parameter

Parameter Description
filename The filename to scan
includes include rules, may be empty not null
excludes exclude rules, may be empty not null

Declaration

public static boolean isIndexable(String filename, List<String> includes, List<String> excludes) 

Method Source Code


//package com.java2s;
/*//from w  w  w  . j a va  2  s.c  o m
 * Licensed to David Pilato (the "Author") under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. Author licenses this
 * file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.util.List;

public class Main {
    /**
     * We check if we can index the file or if we should ignore it
     * @param filename The filename to scan
     * @param includes include rules, may be empty not null
     * @param excludes exclude rules, may be empty not null
     * @return
     */
    public static boolean isIndexable(String filename, List<String> includes, List<String> excludes) {
        // No rules ? Fine, we index everything
        if (includes.isEmpty() && excludes.isEmpty())
            return true;

        // Exclude rules : we know that whatever includes rules are, we should exclude matching files
        for (String exclude : excludes) {
            String regex = exclude.replace("?", ".?").replace("*", ".*?");
            if (filename.matches(regex))
                return false;
        }

        // Include rules : we should add document if it match include rules
        if (includes.isEmpty())
            return true;

        for (String include : includes) {
            String regex = include.replace("?", ".?").replace("*", ".*?");
            if (filename.matches(regex))
                return true;
        }

        return false;
    }
}

Related

  1. addToken(String sequence, String delim, int[] markers, boolean includeDelim, List tokens)
  2. currentPackageIncludedInExcludePatterns(final String fullyQualifiedName, final List excludePatterns)
  3. getPrefixesAndSuffixes(List items, int minSize, int maxSize, T paddingSymbol, boolean includePrefixes, boolean includeSuffixes)
  4. isAcceptedCountry(String country, List countryInclude, List countryExclude)
  5. isIncluded(List list, String src)
  6. isIndexable(String key, List includes, List excludes)