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

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

Description

Tells if an Aamzon S3 file is indexable from its key (file name), based on includes and excludes rules.

License

Apache License

Return

true if file should be indexed, false otherwise

Declaration

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

Method Source Code


//package com.java2s;
/*//from  w  w w  .  j a  v  a2 s  . c om
 * Licensed to Laurent Broudoux (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 {
    /**
     * Tells if an Aamzon S3 file is indexable from its key (file name), based on includes
     * and excludes rules. 
     * @return true if file should be indexed, false otherwise
     */
    public static boolean isIndexable(String key, List<String> includes, List<String> excludes) {
        // If no rules specified, we index everything !
        if ((includes == null && excludes == null) || (includes.isEmpty() && excludes.isEmpty())) {
            return true;
        }

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

        // Include rules : we should add document if it match include rules.
        if (includes == null || includes.isEmpty()) {
            return true;
        }
        if (includes != null) {
            for (String include : includes) {
                String regex = include.replace("?", ".?").replace("*", ".*");
                if (key.matches(regex)) {
                    return true;
                }
            }
        }

        return false;
    }
}

Related

  1. currentPackageIncludedInExcludePatterns(final String fullyQualifiedName, final List excludePatterns)
  2. getPrefixesAndSuffixes(List items, int minSize, int maxSize, T paddingSymbol, boolean includePrefixes, boolean includeSuffixes)
  3. isAcceptedCountry(String country, List countryInclude, List countryExclude)
  4. isIncluded(List list, String src)
  5. isIndexable(String filename, List includes, List excludes)