View Javadoc
1   /*
2    * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> 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.revwalk.filter;
12  
13  import java.io.IOException;
14  
15  import org.eclipse.jgit.errors.IncorrectObjectTypeException;
16  import org.eclipse.jgit.errors.MissingObjectException;
17  import org.eclipse.jgit.revwalk.RevCommit;
18  import org.eclipse.jgit.revwalk.RevWalk;
19  
20  /**
21   * Includes a commit only if the subfilter does not include the commit.
22   */
23  public class NotRevFilter extends RevFilter {
24  	/**
25  	 * Create a filter that negates the result of another filter.
26  	 *
27  	 * @param a
28  	 *            filter to negate.
29  	 * @return a filter that does the reverse of <code>a</code>.
30  	 */
31  	public static RevFilter../../../../../org/eclipse/jgit/revwalk/filter/RevFilter.html#RevFilter">RevFilter create(RevFilter a) {
32  		return new NotRevFilter(a);
33  	}
34  
35  	private final RevFilter a;
36  
37  	private NotRevFilter(RevFilter one) {
38  		a = one;
39  	}
40  
41  	/** {@inheritDoc} */
42  	@Override
43  	public RevFilter negate() {
44  		return a;
45  	}
46  
47  	/** {@inheritDoc} */
48  	@Override
49  	public boolean include(RevWalk walker, RevCommit c)
50  			throws MissingObjectException, IncorrectObjectTypeException,
51  			IOException {
52  		return !a.include(walker, c);
53  	}
54  
55  	/** {@inheritDoc} */
56  	@Override
57  	public boolean requiresCommitBody() {
58  		return a.requiresCommitBody();
59  	}
60  
61  	/** {@inheritDoc} */
62  	@Override
63  	public RevFilter clone() {
64  		return new NotRevFilter(a.clone());
65  	}
66  
67  	/** {@inheritDoc} */
68  	@Override
69  	public String toString() {
70  		return "NOT " + a.toString(); //$NON-NLS-1$
71  	}
72  }