Show critical flags in debug toString() descriptions of rev queues
[egit/graphgui.git] / org.spearce.jgit / src / org / spearce / jgit / revwalk / RevObject.java
blob7dadb7bdc8c578019b727c9ba3565796409f0566
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 import java.io.IOException;
42 import org.spearce.jgit.errors.IncorrectObjectTypeException;
43 import org.spearce.jgit.errors.MissingObjectException;
44 import org.spearce.jgit.lib.AnyObjectId;
45 import org.spearce.jgit.lib.Constants;
46 import org.spearce.jgit.lib.ObjectId;
48 /** Base object type accessed during revision walking. */
49 public abstract class RevObject extends ObjectId {
50 static final int PARSED = 1;
52 int flags;
54 RevObject(final AnyObjectId name) {
55 super(name);
58 abstract void parse(RevWalk walk) throws MissingObjectException,
59 IncorrectObjectTypeException, IOException;
61 /**
62 * Get Git object type. See {@link Constants}.
64 * @return object type
66 public abstract int getType();
68 /**
69 * Get the name of this object.
71 * @return unique hash of this object.
73 public ObjectId getId() {
74 return this;
77 @Override
78 public boolean equals(final ObjectId o) {
79 return this == o;
82 @Override
83 public boolean equals(final Object o) {
84 return this == o;
87 /**
88 * Test to see if the flag has been set on this object.
90 * @param flag
91 * the flag to test.
92 * @return true if the flag has been added to this object; false if not.
94 public boolean has(final RevFlag flag) {
95 return (flags & flag.mask) != 0;
98 /**
99 * Test to see if any flag in the set has been set on this object.
101 * @param set
102 * the flags to test.
103 * @return true if any flag in the set has been added to this object; false
104 * if not.
106 public boolean hasAny(final RevFlagSet set) {
107 return (flags & set.mask) != 0;
111 * Test to see if all flags in the set have been set on this object.
113 * @param set
114 * the flags to test.
115 * @return true if all flags of the set have been added to this object;
116 * false if some or none have been added.
118 public boolean hasAll(final RevFlagSet set) {
119 return (flags & set.mask) == set.mask;
123 * Add a flag to this object.
124 * <p>
125 * If the flag is already set on this object then the method has no effect.
127 * @param flag
128 * the flag to mark on this object, for later testing.
130 public void add(final RevFlag flag) {
131 flags |= flag.mask;
135 * Add a set of flags to this object.
137 * @param set
138 * the set of flags to mark on this object, for later testing.
140 public void add(final RevFlagSet set) {
141 flags |= set.mask;
145 * Remove a flag from this object.
146 * <p>
147 * If the flag is not set on this object then the method has no effect.
149 * @param flag
150 * the flag to remove from this object.
152 public void remove(final RevFlag flag) {
153 flags &= ~flag.mask;
157 * Remove a set of flags from this object.
159 * @param set
160 * the flag to remove from this object.
162 public void remove(final RevFlagSet set) {
163 flags &= ~set.mask;
166 /** Release as much memory as possible from this object. */
167 public void dispose() {
168 // Nothing needs to be done for most objects.
171 @Override
172 public String toString() {
173 final StringBuilder s = new StringBuilder();
174 s.append(Constants.typeString(getType()));
175 s.append(name());
176 s.append(' ');
177 appendCoreFlags(s);
178 return s.toString();
182 * @param s
183 * buffer to append a debug description of core RevFlags onto.
185 protected void appendCoreFlags(final StringBuilder s) {
186 s.append((flags & RevWalk.TOPO_DELAY) != 0 ? 'o' : '-');
187 s.append((flags & RevWalk.TEMP_MARK) != 0 ? 't' : '-');
188 s.append((flags & RevWalk.REWRITE) != 0 ? 'r' : '-');
189 s.append((flags & RevWalk.UNINTERESTING) != 0 ? 'u' : '-');
190 s.append((flags & RevWalk.SEEN) != 0 ? 's' : '-');
191 s.append((flags & RevWalk.PARSED) != 0 ? 'p' : '-');