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  import org.eclipse.jgit.ignore.IMatcher;
13  
14  /**
15   * Base class for default methods as {@link #toString()} and such.
16   * <p>
17   * This class is immutable and thread safe.
18   */
19  public abstract class AbstractMatcher implements IMatcher {
20  
21  	final boolean dirOnly;
22  
23  	final String pattern;
24  
25  	/**
26  	 * @param pattern
27  	 *            string to parse
28  	 * @param dirOnly
29  	 *            true if this matcher should match only directories
30  	 */
31  	AbstractMatcher(String pattern, boolean dirOnly) {
32  		this.pattern = pattern;
33  		this.dirOnly = dirOnly;
34  	}
35  
36  	/** {@inheritDoc} */
37  	@Override
38  	public String toString() {
39  		return pattern;
40  	}
41  
42  	/** {@inheritDoc} */
43  	@Override
44  	public int hashCode() {
45  		return pattern.hashCode();
46  	}
47  
48  	/** {@inheritDoc} */
49  	@Override
50  	public boolean equals(Object obj) {
51  		if (this == obj)
52  			return true;
53  		if (!(obj instanceof AbstractMatcher))
54  			return false;
55  		AbstractMatcher other = (AbstractMatcher) obj;
56  		return dirOnly == other.dirOnly && pattern.equals(other.pattern);
57  	}
58  }