1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.shared.utils.io; 20 21 import javax.annotation.Nonnull; 22 23 import java.io.File; 24 25 /** 26 * A list of patterns to be matched 27 * 28 * @author Kristian Rosenvold 29 * @deprecated use {@code java.nio.file.DirectoryStream.Filter<T>} and related classes 30 */ 31 @Deprecated 32 public class MatchPatterns { 33 private final MatchPattern[] patterns; 34 35 private MatchPatterns(@Nonnull MatchPattern... patterns) { 36 this.patterns = patterns; 37 } 38 39 /** 40 * <p>Checks these MatchPatterns against a specified string.</p> 41 * <p>Uses far less string tokenization than any of the alternatives.</p> 42 * 43 * @param name The name to look for 44 * @param isCaseSensitive If the comparison is case sensitive 45 * @return true if any of the supplied patterns match 46 */ 47 public boolean matches(@Nonnull String name, boolean isCaseSensitive) { 48 String[] tokenized = MatchPattern.tokenizePathToString(name, File.separator); 49 for (MatchPattern pattern : patterns) { 50 if (pattern.matchPath(name, tokenized, isCaseSensitive)) { 51 return true; 52 } 53 } 54 return false; 55 } 56 57 /** 58 * @param name The name. 59 * @param isCaseSensitive being case sensetive. 60 * @return true if any of the supplied patterns match start. 61 */ 62 public boolean matchesPatternStart(@Nonnull String name, boolean isCaseSensitive) { 63 for (MatchPattern includesPattern : patterns) { 64 if (includesPattern.matchPatternStart(name, isCaseSensitive)) { 65 return true; 66 } 67 } 68 return false; 69 } 70 71 /** 72 * @param sources The sources 73 * @return Converted match patterns. 74 */ 75 public static MatchPatterns from(@Nonnull String... sources) { 76 final int length = sources.length; 77 MatchPattern[] result = new MatchPattern[length]; 78 for (int i = 0; i < length; i++) { 79 result[i] = MatchPattern.fromString(sources[i]); 80 } 81 return new MatchPatterns(result); 82 } 83 }