summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-03-28 15:07:34 -0700
committerIvan Frade <ifrade@google.com>2024-05-08 10:57:47 -0700
commit0647785eb22c2547d2ea2a5afe17cdb7082a2952 (patch)
treee45734367ee1aa4acc29117d0b2a6aee42bddd9d /org.eclipse.jgit/src/org
parent13212d7ec32e52d51698b5bf97f34b4ffd2e0439 (diff)
downloadjgit-0647785eb22c2547d2ea2a5afe17cdb7082a2952.tar.gz
jgit-0647785eb22c2547d2ea2a5afe17cdb7082a2952.zip
PackIndex: Make iterator static (pass object count in ctor)
The iterator uses an implicit reference to the external class to call #getObjectCount(). This implicit reference prevents PackIndex to become an interface. The object count is immutable and known at index (and iterator) construction time. Pass the object count in the constructor of the iterator and make it static. Change-Id: I4949ff943de2a88380fb7f4c9b65b089734854b9
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java6
3 files changed, 18 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
index 8a64c3247a..a23bc4f0a5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
@@ -353,16 +353,22 @@ public abstract class PackIndex
}
}
- abstract class EntriesIterator implements Iterator<MutableEntry> {
+ static abstract class EntriesIterator implements Iterator<MutableEntry> {
protected final MutableEntry entry = initEntry();
+ private final long objectCount;
+
+ protected EntriesIterator(long objectCount) {
+ this.objectCount = objectCount;
+ }
+
protected long returnedNumber = 0;
protected abstract MutableEntry initEntry();
@Override
public boolean hasNext() {
- return returnedNumber < getObjectCount();
+ return returnedNumber < objectCount;
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java
index 21f7314f33..3496a2a20c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java
@@ -203,7 +203,7 @@ class PackIndexV1 extends PackIndex {
@Override
public Iterator<MutableEntry> iterator() {
- return new IndexV1Iterator();
+ return new IndexV1Iterator(objectCnt);
}
@Override
@@ -251,6 +251,10 @@ class PackIndexV1 extends PackIndex {
int levelTwo;
+ IndexV1Iterator(long objectCount) {
+ super(objectCount);
+ }
+
@Override
protected MutableEntry initEntry() {
return new MutableEntry() {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java
index 9a6f4a421a..12dfeb6695 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java
@@ -224,7 +224,7 @@ class PackIndexV2 extends PackIndex {
@Override
public Iterator<MutableEntry> iterator() {
- return new EntriesIteratorV2();
+ return new EntriesIteratorV2(objectCnt);
}
@Override
@@ -294,6 +294,10 @@ class PackIndexV2 extends PackIndex {
int levelTwo;
+ EntriesIteratorV2(long objectCount){
+ super(objectCount);
+ }
+
@Override
protected MutableEntry initEntry() {
return new MutableEntry() {