This let us avoid using instanceof. Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx> --- .../src/org/spearce/jgit/revwalk/RevBlob.java | 6 ++++++ .../src/org/spearce/jgit/revwalk/RevCommit.java | 5 +++++ .../src/org/spearce/jgit/revwalk/RevObject.java | 8 ++++++++ .../src/org/spearce/jgit/revwalk/RevTag.java | 5 +++++ .../src/org/spearce/jgit/revwalk/RevTree.java | 6 ++++++ 5 files changed, 30 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevBlob.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevBlob.java index f6d34f4..66cdc02 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevBlob.java +++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevBlob.java @@ -38,6 +38,7 @@ package org.spearce.jgit.revwalk; import org.spearce.jgit.lib.AnyObjectId; +import org.spearce.jgit.lib.Constants; /** A binary file, or a symbolic link. */ public class RevBlob extends RevObject { @@ -55,4 +56,9 @@ public class RevBlob extends RevObject { void parse(final RevWalk walk) { flags |= PARSED; } + + @Override + public int getType() { + return Constants.OBJ_BLOB; + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevCommit.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevCommit.java index 0aa7098..77f1d1a 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevCommit.java +++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevCommit.java @@ -135,6 +135,11 @@ public class RevCommit extends RevObject { buffer = raw; flags |= PARSED; } + + @Override + public int getType() { + return Constants.OBJ_COMMIT; + } static void carryFlags(RevCommit c, final int carry) { for (;;) { diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevObject.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevObject.java index 86c50b5..451205c 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevObject.java +++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevObject.java @@ -42,6 +42,7 @@ import java.io.IOException; import org.spearce.jgit.errors.IncorrectObjectTypeException; import org.spearce.jgit.errors.MissingObjectException; import org.spearce.jgit.lib.AnyObjectId; +import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.ObjectId; /** Base object type accessed during revision walking. */ @@ -56,6 +57,13 @@ public abstract class RevObject extends ObjectId { abstract void parse(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException; + + /** + * Get Git object type. See {@link Constants}. + * + * @return object type + */ + public abstract int getType(); /** * Get the name of this object. diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java index 668819c..bbb18ee 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java +++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java @@ -96,6 +96,11 @@ public class RevTag extends RevObject { flags |= PARSED; } + @Override + public int getType() { + return Constants.OBJ_TAG; + } + /** * Parse this tag buffer for display. * diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTree.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTree.java index 7ad9be0..e1cd4b5 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTree.java +++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTree.java @@ -38,6 +38,7 @@ package org.spearce.jgit.revwalk; import org.spearce.jgit.lib.AnyObjectId; +import org.spearce.jgit.lib.Constants; /** A reference to a tree of subtrees/files. */ public class RevTree extends RevObject { @@ -55,4 +56,9 @@ public class RevTree extends RevObject { void parse(final RevWalk walk) { flags |= PARSED; } + + @Override + public int getType() { + return Constants.OBJ_TREE; + } } -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html