org.eclipse.jgit.treewalk

## Class EmptyTreeIterator

- java.lang.Object
- - org.eclipse.jgit.treewalk.AbstractTreeIterator
  - - org.eclipse.jgit.treewalk.EmptyTreeIterator

    public class EmptyTreeIterator
    extends AbstractTreeIterator

Iterator over an empty tree (a directory with no files).

### Field Summary

### Fields inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator

`DEFAULT_PATH_SIZE, mode, path, pathLen, pathOffset, zeroid`

### Constructor Summary

Constructors
Constructor and Description
`EmptyTreeIterator()` Create a new iterator with no parent.
`EmptyTreeIterator(AbstractTreeIterator p, byte[] childPath, int childPathOffset)` Create an iterator for a subtree of an existing iterator.

### Method Summary

Methods
`void` `back(int delta)` Move to prior entry, populating this iterator with the entry data.
`AbstractTreeIterator` `createSubtreeIterator(ObjectReader reader)` Create a new iterator for the current entry's subtree.
`boolean` `eof()` Is this tree iterator at its EOF point (no more entries)?
`boolean` `first()` Is this tree iterator positioned on its first entry?
`ObjectId` `getEntryObjectId()` Get the object id of the current entry.
`boolean` `hasId()`
`byte[]` `idBuffer()` Get the byte array buffer object IDs must be copied out of.
`int` `idOffset()` Get the position within `AbstractTreeIterator.idBuffer()` of this entry's ObjectId.
`void` `next(int delta)` Move to next entry, populating this iterator with the entry data.
`void` `reset()` Position this iterator on the first entry.
`void` `stopWalk()` Indicates to the iterator that no more entries will be read.

### Methods inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator

`createEmptyTreeIterator, createSubtreeIterator, ensurePathCapacity, getEntryFileMode, getEntryObjectId, getEntryPathBuffer, getEntryPathHashCode, getEntryPathLength, getEntryPathString, getEntryRawMode, getName, getNameLength, getNameOffset, growPath, idEqual, pathCompare, pathCompare, skip, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### EmptyTreeIterator

    public EmptyTreeIterator()

Create a new iterator with no parent.

#### EmptyTreeIterator

    public EmptyTreeIterator(AbstractTreeIterator p,
                     byte[] childPath,
                     int childPathOffset)

Create an iterator for a subtree of an existing iterator.

The caller is responsible for setting up the path of the child iterator.

Parameters:
  `p` - parent tree iterator.
  `childPath` - path array to be used by the child iterator. This path must contain the path from the top of the walk to the first child and must end with a '/'.
  `childPathOffset` - position within `childPath` where the child can insert its data. The value at `childPath[childPathOffset-1]` must be '/'.

### Method Detail

#### createSubtreeIterator

    public AbstractTreeIterator createSubtreeIterator(ObjectReader reader)
                                               throws IncorrectObjectTypeException,
                                                      IOException

Description copied from class: `AbstractTreeIterator`
Create a new iterator for the current entry's subtree.

The parent reference of the iterator must be `this`, otherwise the caller would not be able to exit out of the subtree iterator correctly and return to continue walking `this`.

Specified by:
  `createSubtreeIterator` in class `AbstractTreeIterator`
Parameters:
  `reader` - reader to load the tree data from.
Returns:
  a new parser that walks over the current subtree.
Throws:
  `IncorrectObjectTypeException` - the current entry is not actually a tree and cannot be parsed as though it were a tree.
  `IOException` - a loose object or pack file could not be read.

#### hasId

    public boolean hasId()

Specified by:
  `hasId` in class `AbstractTreeIterator`
Returns:
  true if the entry has a valid ObjectId.

#### getEntryObjectId

    public ObjectId getEntryObjectId()

Description copied from class: `AbstractTreeIterator`
Get the object id of the current entry.

Overrides:
  `getEntryObjectId` in class `AbstractTreeIterator`
Returns:
  an object id for the current entry.

#### idBuffer

    public byte[] idBuffer()

Description copied from class: `AbstractTreeIterator`
Get the byte array buffer object IDs must be copied out of.

The id buffer contains the bytes necessary to construct an ObjectId for the current entry of this iterator. The buffer can be the same buffer for all entries, or it can be a unique buffer per-entry. Implementations are encouraged to expose their private buffer whenever possible to reduce garbage generation and copying costs.

Specified by:
  `idBuffer` in class `AbstractTreeIterator`
Returns:
  byte array the implementation stores object IDs within.
See Also:
  `AbstractTreeIterator.getEntryObjectId()`

#### idOffset

    public int idOffset()

Description copied from class: `AbstractTreeIterator`
Get the position within `AbstractTreeIterator.idBuffer()` of this entry's ObjectId.

Specified by:
  `idOffset` in class `AbstractTreeIterator`
Returns:
  offset into the array returned by `AbstractTreeIterator.idBuffer()` where the ObjectId must be copied out of.

#### reset

    public void reset()

Description copied from class: `AbstractTreeIterator`
Position this iterator on the first entry. The default implementation of this method uses `back(1)` until `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.

Overrides:
  `reset` in class `AbstractTreeIterator`

#### first

    public boolean first()

Description copied from class: `AbstractTreeIterator`
Is this tree iterator positioned on its first entry?

An iterator is positioned on the first entry if `back(1)` would be an invalid request as there is no entry before the current one.

An empty iterator (one with no entries) will be `first() && eof()`.

Specified by:
  `first` in class `AbstractTreeIterator`
Returns:
  true if the iterator is positioned on the first entry.

#### eof

    public boolean eof()

Description copied from class: `AbstractTreeIterator`
Is this tree iterator at its EOF point (no more entries)?

An iterator is at EOF if there is no current entry.

Specified by:
  `eof` in class `AbstractTreeIterator`
Returns:
  true if we have walked all entries and have none left.

#### next

    public void next(int delta)
              throws CorruptObjectException

Description copied from class: `AbstractTreeIterator`
Move to next entry, populating this iterator with the entry data.

The delta indicates how many moves forward should occur. The most common delta is 1 to move to the next entry.

Implementations must populate the following members:

- `AbstractTreeIterator.mode`
- `AbstractTreeIterator.path` (from `AbstractTreeIterator.pathOffset` to `AbstractTreeIterator.pathLen`)
- `AbstractTreeIterator.pathLen`

as well as any implementation dependent information necessary to accurately return data from `AbstractTreeIterator.idBuffer()` and `AbstractTreeIterator.idOffset()` when demanded.

Specified by:
  `next` in class `AbstractTreeIterator`
Parameters:
  `delta` - number of entries to move the iterator by. Must be a positive, non-zero integer.
Throws:
  `CorruptObjectException` - the tree is invalid.

#### back

    public void back(int delta)
              throws CorruptObjectException

Description copied from class: `AbstractTreeIterator`
Move to prior entry, populating this iterator with the entry data.

The delta indicates how many moves backward should occur.The most common delta is 1 to move to the prior entry.

Implementations must populate the following members:

- `AbstractTreeIterator.mode`
- `AbstractTreeIterator.path` (from `AbstractTreeIterator.pathOffset` to `AbstractTreeIterator.pathLen`)
- `AbstractTreeIterator.pathLen`

as well as any implementation dependent information necessary to accurately return data from `AbstractTreeIterator.idBuffer()` and `AbstractTreeIterator.idOffset()` when demanded.

Specified by:
  `back` in class `AbstractTreeIterator`
Parameters:
  `delta` - number of entries to move the iterator by. Must be a positive, non-zero integer.
Throws:
  `CorruptObjectException` - the tree is invalid.

#### stopWalk

    public void stopWalk()

Description copied from class: `AbstractTreeIterator`
Indicates to the iterator that no more entries will be read.

This is only invoked by TreeWalk when the iteration is aborted early due to a `StopWalkException` being thrown from within a TreeFilter.

Overrides:
  `stopWalk` in class `AbstractTreeIterator`