Switch jgit library to the EDL (3-clause BSD)
[egit/zawir.git] / org.spearce.jgit / src / org / spearce / jgit / revwalk / AbstractRevQueue.java
blob4cf7dae35e331820818fb6a04d64a5fd34bf7450
1 /*
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
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
21 * written permission.
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. */
44 int outputType;
46 /**
47 * Add a commit to the queue.
48 * <p>
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)}.
53 * @param c
54 * commit to add.
56 public abstract void add(RevCommit c);
58 /**
59 * Add a commit if it does not have a flag set yet, then set the flag.
60 * <p>
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
64 * being added twice.
66 * @param c
67 * commit to add.
68 * @param queueControl
69 * flag that controls admission to the queue.
71 public final void add(final RevCommit c, final RevFlag queueControl) {
72 if (!c.has(queueControl)) {
73 c.add(queueControl);
74 add(c);
78 /**
79 * Add a commit's parents if one does not have a flag set yet.
80 * <p>
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
84 * being added twice.
86 * @param c
87 * commit whose parents should be added.
88 * @param queueControl
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;
93 if (pList == null)
94 return;
95 for (RevCommit p : pList)
96 add(p, queueControl);
99 /**
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);
113 @Override
114 int outputType() {
115 return outputType;
118 private static class AlwaysEmptyQueue extends AbstractRevQueue {
119 @Override
120 public void add(RevCommit c) {
121 throw new UnsupportedOperationException();
124 @Override
125 public RevCommit next() {
126 return null;
129 @Override
130 boolean anybodyHasFlag(int f) {
131 return true;
134 @Override
135 boolean everbodyHasFlag(int f) {
136 return true;
139 @Override
140 public void clear() {
141 // Nothing to clear, we have no state.