View Javadoc
1   /*
2    * Copyright (C) 2014, Andrey Loskutov <loskutov@gmx.de> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.ignore.internal;
11  
12  /**
13   * Wildmatch matcher for "double star" (<code>**</code>) pattern only. This
14   * matcher matches any path.
15   * <p>
16   * This class is immutable and thread safe.
17   */
18  public final class WildMatcher extends AbstractMatcher {
19  
20  	static final String WILDMATCH = "**"; //$NON-NLS-1$
21  
22  	// double star for the beginning of pattern
23  	static final String WILDMATCH2 = "/**"; //$NON-NLS-1$
24  
25  	WildMatcher(boolean dirOnly) {
26  		super(WILDMATCH, dirOnly);
27  	}
28  
29  	/** {@inheritDoc} */
30  	@Override
31  	public final boolean matches(String path, boolean assumeDirectory,
32  			boolean pathMatch) {
33  		return !dirOnly || assumeDirectory
34  				|| (!pathMatch && isSubdirectory(path));
35  	}
36  
37  	/** {@inheritDoc} */
38  	@Override
39  	public final boolean matches(String segment, int startIncl, int endExcl) {
40  		return true;
41  	}
42  
43  	private static boolean isSubdirectory(String path) {
44  		final int slashIndex = path.indexOf('/');
45  		return slashIndex >= 0 && slashIndex < path.length() - 1;
46  	}
47  }