View Javadoc
1   /*
2    * Copyright (C) 2008, Florian Köberle <florianskarten@web.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  
11  package org.eclipse.jgit.fnmatch;
12  
13  import java.util.List;
14  
15  import org.eclipse.jgit.internal.JGitText;
16  
17  abstract class AbstractHead implements Head {
18  	private List<Head> newHeads = null;
19  
20  	private final boolean star;
21  
22  	/**
23  	 * Whether the char matches
24  	 *
25  	 * @param c
26  	 *            a char.
27  	 * @return whether the char matches
28  	 */
29  	protected abstract boolean matches(char c);
30  
31  	AbstractHead(boolean star) {
32  		this.star = star;
33  	}
34  
35  	/**
36  	 * Set {@link org.eclipse.jgit.fnmatch.Head}s which will not be modified.
37  	 *
38  	 * @param newHeads
39  	 *            a list of {@link org.eclipse.jgit.fnmatch.Head}s which will
40  	 *            not be modified.
41  	 */
42  	public final void setNewHeads(List<Head> newHeads) {
43  		if (this.newHeads != null)
44  			throw new IllegalStateException(JGitText.get().propertyIsAlreadyNonNull);
45  		this.newHeads = newHeads;
46  	}
47  
48  	/** {@inheritDoc} */
49  	@Override
50  	public List<Head> getNextHeads(char c) {
51  		if (matches(c)) {
52  			return newHeads;
53  		}
54  		return FileNameMatcher.EMPTY_HEAD_LIST;
55  	}
56  
57  	boolean isStar() {
58  		return star;
59  	}
60  }