org.eclipse.jgit.treewalk
Class WorkingTreeIterator

java.lang.Object
  extended by org.eclipse.jgit.treewalk.AbstractTreeIterator
      extended by org.eclipse.jgit.treewalk.WorkingTreeIterator
Direct Known Subclasses:
FileTreeIterator

public abstract class WorkingTreeIterator
extends AbstractTreeIterator

Walks a working directory tree as part of a TreeWalk.

Most applications will want to use the standard implementation of this iterator, FileTreeIterator, as that does all IO through the standard java.io package. Plugins for a Java based IDE may however wish to create their own implementations of this class to allow traversal of the IDE's project space, as well as benefit from any caching the IDE may have.

See Also:
FileTreeIterator

Nested Class Summary
protected static class WorkingTreeIterator.Entry
          A single entry within a working directory tree.
 
Field Summary
protected static WorkingTreeIterator.Entry[] EOF
          An empty entry array, suitable for init(Entry[]).
 
Fields inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
DEFAULT_PATH_SIZE, mode, path, pathLen, pathOffset, zeroid
 
Constructor Summary
protected WorkingTreeIterator()
          Create a new iterator with no parent.
protected WorkingTreeIterator(java.lang.String prefix)
          Create a new iterator with no parent and a prefix.
protected WorkingTreeIterator(WorkingTreeIterator p)
          Create an iterator for a subtree of an existing iterator.
 
Method Summary
 void back(int delta)
          Move to prior entry, populating this iterator with the entry data.
protected  WorkingTreeIterator.Entry current()
          Obtain the current entry from this iterator.
 boolean eof()
          Is this tree iterator at its EOF point (no more entries)?
 boolean first()
          Is this tree iterator positioned on its first entry?
 long getEntryLastModified()
          Get the last modified time of this entry.
 long getEntryLength()
          Get the byte length of this entry.
 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.
protected  void init(WorkingTreeIterator.Entry[] list)
          Constructor helper.
 void next(int delta)
          Move to next entry, populating this iterator with the entry data.
 
Methods inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
createEmptyTreeIterator, createSubtreeIterator, createSubtreeIterator, ensurePathCapacity, getEntryFileMode, getEntryObjectId, getEntryObjectId, getEntryPathString, getEntryRawMode, getName, getNameLength, growPath, idEqual, pathCompare, skip, stopWalk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOF

protected static final WorkingTreeIterator.Entry[] EOF
An empty entry array, suitable for init(Entry[]).

Constructor Detail

WorkingTreeIterator

protected WorkingTreeIterator()
Create a new iterator with no parent.


WorkingTreeIterator

protected WorkingTreeIterator(java.lang.String prefix)
Create a new iterator with no parent and a prefix.

The prefix path supplied is inserted in front of all paths generated by this iterator. It is intended to be used when an iterator is being created for a subsection of an overall repository and needs to be combined with other iterators that are created to run over the entire repository namespace.

Parameters:
prefix - position of this iterator in the repository tree. The value may be null or the empty string to indicate the prefix is the root of the repository. A trailing slash ('/') is automatically appended if the prefix does not end in '/'.

WorkingTreeIterator

protected WorkingTreeIterator(WorkingTreeIterator p)
Create an iterator for a subtree of an existing iterator.

Parameters:
p - parent tree iterator.
Method Detail

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.

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:

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:

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.

getEntryLength

public long getEntryLength()
Get the byte length of this entry.

Returns:
size of this file, in bytes.

getEntryLastModified

public long getEntryLastModified()
Get the last modified time of this entry.

Returns:
last modified time of this file, in milliseconds since the epoch (Jan 1, 1970 UTC).

init

protected void init(WorkingTreeIterator.Entry[] list)
Constructor helper.

Parameters:
list - files in the subtree of the work tree this iterator operates on

current

protected WorkingTreeIterator.Entry current()
Obtain the current entry from this iterator.

Returns:
the currently selected entry.