aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/AbstractMatcher.java
blob: a3f365ea0eb785a24e200e7f9e67c9e9aa96be77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (C) 2014, Andrey Loskutov <loskutov@gmx.de> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.ignore.internal;

import org.eclipse.jgit.ignore.IMatcher;

/**
 * Base class for default methods as {@link #toString()} and such.
 * <p>
 * This class is immutable and thread safe.
 */
public abstract class AbstractMatcher implements IMatcher {

	final boolean dirOnly;

	final String pattern;

	/**
	 * @param pattern
	 *            string to parse
	 * @param dirOnly
	 *            true if this matcher should match only directories
	 */
	AbstractMatcher(String pattern, boolean dirOnly) {
		this.pattern = pattern;
		this.dirOnly = dirOnly;
	}

	@Override
	public String toString() {
		return pattern;
	}

	@Override
	public int hashCode() {
		return pattern.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof AbstractMatcher))
			return false;
		AbstractMatcher other = (AbstractMatcher) obj;
		return dirOnly == other.dirOnly && pattern.equals(other.pattern);
	}
}