1 /**
2 * Copyright (C) 2015, Google Inc. 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.lib.AnyObjectId;
18 import org.eclipse.jgit.revwalk.ObjectWalk;
19
20 /**
21 * Selects interesting objects when walking.
22 * <p>
23 * Applications should install the filter on an ObjectWalk by
24 * {@link org.eclipse.jgit.revwalk.ObjectWalk#setObjectFilter(ObjectFilter)}
25 * prior to starting traversal.
26 *
27 * @since 4.0
28 */
29 public abstract class ObjectFilter {
30 /** Default filter that always returns true. */
31 public static final ObjectFilter ALL = new AllFilter();
32
33 private static final class AllFilter extends ObjectFilter {
34 @Override
35 public boolean include(ObjectWalk walker, AnyObjectId o) {
36 return true;
37 }
38 }
39
40 /**
41 * Determine if the named object should be included in the walk.
42 *
43 * @param walker
44 * the active walker this filter is being invoked from within.
45 * @param objid
46 * the object currently being tested.
47 * @return {@code true} if the named object should be included in the walk.
48 * @throws org.eclipse.jgit.errors.MissingObjectException
49 * an object the filter needed to consult to determine its
50 * answer was missing
51 * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
52 * an object the filter needed to consult to determine its
53 * answer was of the wrong type
54 * @throws java.io.IOException
55 * an object the filter needed to consult to determine its
56 * answer could not be read.
57 */
58 public abstract boolean include(ObjectWalk walker, AnyObjectId objid)
59 throws MissingObjectException, IncorrectObjectTypeException,
60 IOException;
61 }