2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org
.spearce
.jgit
.revwalk
;
40 abstract class AbstractRevQueue
extends Generator
{
41 static final AbstractRevQueue EMPTY_QUEUE
= new AlwaysEmptyQueue();
43 /** Current output flags set for this generator instance. */
47 * Add a commit to the queue.
49 * This method always adds the commit, even if it is already in the queue or
50 * previously was in the queue but has already been removed. To control
51 * queue admission use {@link #add(RevCommit, RevFlag)}.
56 public abstract void add(RevCommit c
);
59 * Add a commit if it does not have a flag set yet, then set the flag.
61 * This method permits the application to test if the commit has the given
62 * flag; if it does not already have the flag than the commit is added to
63 * the queue and the flag is set. This later will prevent the commit from
69 * flag that controls admission to the queue.
71 public final void add(final RevCommit c
, final RevFlag queueControl
) {
72 if (!c
.has(queueControl
)) {
79 * Add a commit's parents if one does not have a flag set yet.
81 * This method permits the application to test if the commit has the given
82 * flag; if it does not already have the flag than the commit is added to
83 * the queue and the flag is set. This later will prevent the commit from
87 * commit whose parents should be added.
89 * flag that controls admission to the queue.
91 public final void addParents(final RevCommit c
, final RevFlag queueControl
) {
92 final RevCommit
[] pList
= c
.parents
;
95 for (RevCommit p
: pList
)
100 * Remove the first commit from the queue.
102 * @return the first commit of this queue.
104 public abstract RevCommit
next();
106 /** Remove all entries from this queue. */
107 public abstract void clear();
109 abstract boolean everbodyHasFlag(int f
);
111 abstract boolean anybodyHasFlag(int f
);
118 private static class AlwaysEmptyQueue
extends AbstractRevQueue
{
120 public void add(RevCommit c
) {
121 throw new UnsupportedOperationException();
125 public RevCommit
next() {
130 boolean anybodyHasFlag(int f
) {
135 boolean everbodyHasFlag(int f
) {
140 public void clear() {
141 // Nothing to clear, we have no state.