@@ -159,6 +159,15 @@ public class DirCacheIterator extends AbstractTreeIterator { | |||
return 0; | |||
} | |||
@Override | |||
public void reset() { | |||
if (!first()) { | |||
ptr = treeStart; | |||
if (!eof()) | |||
parseEntry(); | |||
} | |||
} | |||
@Override | |||
public boolean first() { | |||
return ptr == treeStart; |
@@ -496,6 +496,22 @@ public abstract class AbstractTreeIterator { | |||
return createSubtreeIterator(reader); | |||
} | |||
/** | |||
* Position this iterator on the first entry. | |||
* | |||
* The default implementation of this method uses {@code back(1)} until | |||
* {@code first()} is true. This is most likely not the most efficient | |||
* method of repositioning the iterator to its first entry, so subclasses | |||
* are strongly encouraged to override the method. | |||
* | |||
* @throws CorruptObjectException | |||
* the tree is invalid. | |||
*/ | |||
public void reset() throws CorruptObjectException { | |||
while (!first()) | |||
back(1); | |||
} | |||
/** | |||
* Is this tree iterator positioned on its first entry? | |||
* <p> |
@@ -243,6 +243,12 @@ public class CanonicalTreeParser extends AbstractTreeIterator { | |||
return nextPtr - Constants.OBJECT_ID_LENGTH; | |||
} | |||
@Override | |||
public void reset() { | |||
if (!first()) | |||
reset(raw); | |||
} | |||
@Override | |||
public boolean first() { | |||
return currPtr == 0; |
@@ -107,6 +107,11 @@ public class EmptyTreeIterator extends AbstractTreeIterator { | |||
return 0; | |||
} | |||
@Override | |||
public void reset() { | |||
// Do nothing. | |||
} | |||
@Override | |||
public boolean first() { | |||
return true; |
@@ -332,6 +332,15 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { | |||
return 0; | |||
} | |||
@Override | |||
public void reset() { | |||
if (!first()) { | |||
ptr = 0; | |||
if (!eof()) | |||
parseEntry(); | |||
} | |||
} | |||
@Override | |||
public boolean first() { | |||
return ptr == 0; |