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