BitmapWalkListener: Use plain interface with noop instance

In this new interface default methods are useful only to instantiate
noop instances. We rather reuse the same noop instance and save the
"default" to add backward compatible methods to existing interfaces.

Make the methods regular interface methods and provide a noop
instance.

Change-Id: Ie84ff17c8e9f16837245751739ee8c99463e76ee
This commit is contained in:
Ivan Frade 2023-11-16 15:12:47 -08:00
parent 4d82d0aa1f
commit e612c25228
1 changed files with 29 additions and 15 deletions

View File

@ -54,14 +54,13 @@ public final class BitmapWalker {
*/
public interface BitmapWalkListener {
/**
* The commit is already in the walk bitmap
* The commit was already visited or is reachable from a visited commit
*
* @param oid
* objectId of the commit already in bitmap
* objectId of the commit already visited directly or
* indirectly
*/
default void onCommitInBitmap(ObjectId oid) {
// Nothing to do
}
void onCommitSeen(ObjectId oid);
/**
* The commit has a bitmap in the bitmap index
@ -69,9 +68,7 @@ default void onCommitInBitmap(ObjectId oid) {
* @param oid
* objectId of the commit with a bitmap in the bitmap index
*/
default void onCommitWithBitmap(ObjectId oid) {
// Nothing to do
}
void onCommitWithBitmap(ObjectId oid);
/**
* The commit doesn't have bitmap
@ -80,13 +77,30 @@ default void onCommitWithBitmap(ObjectId oid) {
* objectId of the commit without a bitmap in the bitmap
* index
*/
default void onCommitWithoutBitmap(ObjectId oid) {
// Nothing to do
}
void onCommitWithoutBitmap(ObjectId oid);
}
private static final BitmapWalkListener NO_LISTENER = new BitmapWalkListener() {
// Default methods
/**
* Empty listener
*
* @since 6.8
*/
public static final BitmapWalkListener NOOP_LISTENER = new BitmapWalkListener() {
@Override
public void onCommitSeen(ObjectId oid) {
// Nothing to do
}
@Override
public void onCommitWithBitmap(ObjectId oid) {
// Nothing to do
}
@Override
public void onCommitWithoutBitmap(ObjectId oid) {
// Nothing to do
}
};
private final BitmapWalkListener listener;
@ -100,7 +114,7 @@ default void onCommitWithoutBitmap(ObjectId oid) {
*/
public BitmapWalker(
ObjectWalk walker, BitmapIndex bitmapIndex, ProgressMonitor pm) {
this(walker, bitmapIndex, pm, NO_LISTENER);
this(walker, bitmapIndex, pm, NOOP_LISTENER);
}
/**
@ -114,7 +128,7 @@ public BitmapWalker(
* progress monitor to report progress on.
* @param listener
* listener of event happening during the walk. Use
* {@link #NO_LISTENER} for a no-op listener.
* {@link BitmapWalker#NOOP_LISTENER} for a no-op listener.
*
* @since 6.8
*/