Switch jgit library to the EDL (3-clause BSD)
[jgit.git] / org.spearce.jgit / src / org / spearce / jgit / revwalk / RevObject.java
blob86c50b5223f176170de9c338b70be0f08b3ff6f4
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.ObjectId;
47 /** Base object type accessed during revision walking. */
48 public abstract class RevObject extends ObjectId {
49 static final int PARSED = 1;
51 int flags;
53 RevObject(final AnyObjectId name) {
54 super(name);
57 abstract void parse(RevWalk walk) throws MissingObjectException,
58 IncorrectObjectTypeException, IOException;
60 /**
61 * Get the name of this object.
63 * @return unique hash of this object.
65 public ObjectId getId() {
66 return this;
69 @Override
70 public boolean equals(final ObjectId o) {
71 return this == o;
74 @Override
75 public boolean equals(final Object o) {
76 return this == o;
79 /**
80 * Test to see if the flag has been set on this object.
82 * @param flag
83 * the flag to test.
84 * @return true if the flag has been added to this object; false if not.
86 public boolean has(final RevFlag flag) {
87 return (flags & flag.mask) != 0;
90 /**
91 * Test to see if any flag in the set has been set on this object.
93 * @param set
94 * the flags to test.
95 * @return true if any flag in the set has been added to this object; false
96 * if not.
98 public boolean hasAny(final RevFlagSet set) {
99 return (flags & set.mask) != 0;
103 * Test to see if all flags in the set have been set on this object.
105 * @param set
106 * the flags to test.
107 * @return true if all flags of the set have been added to this object;
108 * false if some or none have been added.
110 public boolean hasAll(final RevFlagSet set) {
111 return (flags & set.mask) == set.mask;
115 * Add a flag to this object.
116 * <p>
117 * If the flag is already set on this object then the method has no effect.
119 * @param flag
120 * the flag to mark on this object, for later testing.
122 public void add(final RevFlag flag) {
123 flags |= flag.mask;
127 * Add a set of flags to this object.
129 * @param set
130 * the set of flags to mark on this object, for later testing.
132 public void add(final RevFlagSet set) {
133 flags |= set.mask;
137 * Remove a flag from this object.
138 * <p>
139 * If the flag is not set on this object then the method has no effect.
141 * @param flag
142 * the flag to remove from this object.
144 public void remove(final RevFlag flag) {
145 flags &= ~flag.mask;
149 * Remove a set of flags from this object.
151 * @param set
152 * the flag to remove from this object.
154 public void remove(final RevFlagSet set) {
155 flags &= ~set.mask;
158 /** Release as much memory as possible from this object. */
159 public void dispose() {
160 // Nothing needs to be done for most objects.