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       * Checks these MatchPatterns against a specified string.
44       * <p/>
45       * Uses far less string tokenization than any of the alternatives.
46       *
47       * @param name            The name to look for
48       * @param isCaseSensitive If the comparison is case sensitive
49       * @return true if any of the supplied patterns match
50       */
51      public boolean matches( @Nonnull String name, boolean isCaseSensitive )
52      {
53          String[] tokenized = MatchPattern.tokenizePathToString( name, File.separator );
54          for ( MatchPattern pattern : patterns )
55          {
56              if ( pattern.matchPath( name, tokenized, isCaseSensitive ) )
57              {
58                  return true;
59              }
60          }
61          return false;
62      }
63  
64      /**
65       * @param name The name.
66       * @param isCaseSensitive being case sensetive.
67       * @return true if any of the supplied patterns match start.
68       */
69      public boolean matchesPatternStart( @Nonnull String name, boolean isCaseSensitive )
70      {
71          for ( MatchPattern includesPattern : patterns )
72          {
73              if ( includesPattern.matchPatternStart( name, isCaseSensitive ) )
74              {
75                  return true;
76              }
77          }
78          return false;
79      }
80  
81      /**
82       * @param sources The sources
83       * @return Converted match patterns.
84       */
85      public static MatchPatterns from( @Nonnull String... sources )
86      {
87          final int length = sources.length;
88          MatchPattern[] result = new MatchPattern[length];
89          for ( int i = 0; i < length; i++ )
90          {
91              result[i] = MatchPattern.fromString( sources[i] );
92          }
93          return new MatchPatterns( result );
94      }
95  
96  }