Top Description Fields Constructors Methods
org.eclipse.jgit.notes

public Class NoteMap

extends Object
implements Iterable<Note>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
java.io.IOException, java.util.Iterator, org.eclipse.jgit.errors.CorruptObjectException, .IncorrectObjectTypeException, .LargeObjectException, .MissingObjectException, org.eclipse.jgit.lib.AbbreviatedObjectId, .AnyObjectId, .Constants, .MutableObjectId, .ObjectId, .ObjectInserter, .ObjectReader, org.eclipse.jgit.revwalk.RevCommit, .RevTree

Index of notes from a note branch. This class is not thread-safe, and relies on an org.eclipse.jgit.lib.ObjectReader that it borrows/shares with the caller. The reader can be used during any call, and is not released by this class. The caller should arrange for releasing the shared ObjectReader at the proper times.

Field Summary

Modifier and TypeField and Description
private final ObjectReader
reader

Borrowed reader to access the repository.

private InMemoryNoteBucket
root

All of the notes that have been loaded.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if a note exists; false if there is no note.
contains
(AnyObjectId
the object to look for.
id
)

Determine if a note exists for the specified ObjectId.

public ObjectId

Returns:

the note's blob ObjectId, or null if no note exists.
get
(AnyObjectId
the object to look for.
id
)

Lookup a note for a specific ObjectId.

public byte[]

Returns:

if a note is defined for id, the note content. If no note is defined, null.
getCachedBytes
(AnyObjectId
object to lookup the note of.
id
,
int
maximum number of bytes to return. If the note data size is larger than this limit, LargeObjectException will be thrown.
sizeLimit
)

Open and return the content of an object's note.

public Note

Returns:

the note for the given object id, or null if no note exists.
getNote
(AnyObjectId
the object to look for.
id
)

Lookup a note for a specific ObjectId.

pack-priv InMemoryNoteBucket

Returns:

the root note bucket
getRoot
()

Get the root note bucket

public Iterator<Note>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

private void
load(ObjectId rootTree)

public static NoteMap

Returns:

an empty note map.
newEmptyMap
()

Construct a new empty note map.

pack-priv static NoteMap

Returns:

the note map built from the note bucket
newMap
(InMemoryNoteBucket
the root bucket of this note map
root
,
ObjectReader
reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.
reader
)

Construct a new note map from an existing note bucket.

public static NoteMap

Returns:

the note map read from the commit.
read
(ObjectReader
reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.
reader
,
RevCommit
the revision of the note branch to read.
commit
)

Load a collection of notes from a branch.

public static NoteMap

Returns:

the note map read from the tree.
read
(ObjectReader
reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.
reader
,
RevTree
the note tree to read.
tree
)

Load a collection of notes from a tree.

public static NoteMap

Returns:

the note map read from the tree.
readTree
(ObjectReader
reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.
reader
,
ObjectId
the note tree to read.
treeId
)

Load a collection of notes from a tree.

public void
remove(AnyObjectId
the object to remove the note from.
noteOn
)

Remove a note from an object.

public void
set(AnyObjectId
the object to attach the note to. This same ObjectId can later be used as an argument to get(AnyObjectId) or getCachedBytes(AnyObjectId, int) to read back the noteData.
noteOn
,
ObjectId
data to associate with the note. This must be the ObjectId of a blob that already exists in the repository. If null the note will be deleted, if present.
noteData
)

Attach (or remove) a note on an object.

public void
set(AnyObjectId
the object to attach the note to. This same ObjectId can later be used as an argument to get(AnyObjectId) or getCachedBytes(AnyObjectId, int) to read back the noteData.
noteOn
,
String
text to store in the note. The text will be UTF-8 encoded when stored in the repository. If null the note will be deleted, if the empty string a note with the empty string will be stored.
noteData
,
ObjectInserter
inserter to write the encoded noteData out as a blob. The caller must ensure the inserter is flushed before the updated note map is made available for reading.
ins
)

Attach a note to an object.

public static String

Returns:

a more user friendly note name
shortenRefName
(String noteRefName)

Shorten the note ref name by trimming off the org.eclipse.jgit.lib.Constants#R_NOTES prefix if it exists.

public ObjectId

Returns:

the top level tree.
writeTree
(ObjectInserter
inserter to use when writing trees to the object database. Caller is responsible for flushing the inserter before trying to read the objects, or exposing them through a reference.
inserter
)

Write this note map as a tree.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

readerback to summary
private final ObjectReader reader

Borrowed reader to access the repository.

rootback to summary
private InMemoryNoteBucket root

All of the notes that have been loaded.

Constructor Detail

NoteMapback to summary
private NoteMap(ObjectReader reader)

Method Detail

containsback to summary
public boolean contains(AnyObjectId id) throws IOException

Determine if a note exists for the specified ObjectId.

Parameters
id:AnyObjectId

the object to look for.

Returns:boolean

true if a note exists; false if there is no note.

Exceptions
IOException:
a portion of the note space is not accessible.
getback to summary
public ObjectId get(AnyObjectId id) throws IOException

Lookup a note for a specific ObjectId.

Parameters
id:AnyObjectId

the object to look for.

Returns:ObjectId

the note's blob ObjectId, or null if no note exists.

Exceptions
IOException:
a portion of the note space is not accessible.
getCachedBytesback to summary
public byte[] getCachedBytes(AnyObjectId id, int sizeLimit) throws LargeObjectException, MissingObjectException, IOException

Open and return the content of an object's note. This method assumes the note is fairly small and can be accessed efficiently. Larger notes should be accessed by streaming:

ObjectId dataId = thisMap.get(id);
if (dataId != null)
	reader.open(dataId).openStream();
Parameters
id:AnyObjectId

object to lookup the note of.

sizeLimit:int

maximum number of bytes to return. If the note data size is larger than this limit, LargeObjectException will be thrown.

Returns:byte[]

if a note is defined for id, the note content. If no note is defined, null.

Exceptions
LargeObjectException:
the note data is larger than sizeLimit.
MissingObjectException:
the note's blob does not exist in the repository.
IOException:
the note's blob cannot be read from the repository
getNoteback to summary
public Note getNote(AnyObjectId id) throws IOException

Lookup a note for a specific ObjectId.

Parameters
id:AnyObjectId

the object to look for.

Returns:Note

the note for the given object id, or null if no note exists.

Exceptions
IOException:
a portion of the note space is not accessible.
getRootback to summary
pack-priv InMemoryNoteBucket getRoot()

Get the root note bucket

Returns:InMemoryNoteBucket

the root note bucket

iteratorback to summary
public Iterator<Note> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<Note>

an Iterator.

Annotations
@Override
loadback to summary
private void load(ObjectId rootTree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
newEmptyMapback to summary
public static NoteMap newEmptyMap()

Construct a new empty note map.

Returns:NoteMap

an empty note map.

newMapback to summary
pack-priv static NoteMap newMap(InMemoryNoteBucket root, ObjectReader reader)

Construct a new note map from an existing note bucket.

Parameters
root:InMemoryNoteBucket

the root bucket of this note map

reader:ObjectReader

reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.

Returns:NoteMap

the note map built from the note bucket

readback to summary
public static NoteMap read(ObjectReader reader, RevCommit commit) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException

Load a collection of notes from a branch.

Parameters
reader:ObjectReader

reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.

commit:RevCommit

the revision of the note branch to read.

Returns:NoteMap

the note map read from the commit.

Exceptions
MissingObjectException:
a reference tree object doesn't exist.
IncorrectObjectTypeException:
a tree object wasn't actually a tree.
CorruptObjectException:
a tree object is corrupt and cannot be read.
IOException:
the repository cannot be accessed through the reader.
readback to summary
public static NoteMap read(ObjectReader reader, RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException

Load a collection of notes from a tree.

Parameters
reader:ObjectReader

reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.

tree:RevTree

the note tree to read.

Returns:NoteMap

the note map read from the tree.

Exceptions
MissingObjectException:
a reference tree object doesn't exist.
IncorrectObjectTypeException:
a tree object wasn't actually a tree.
CorruptObjectException:
a tree object is corrupt and cannot be read.
IOException:
the repository cannot be accessed through the reader.
readTreeback to summary
public static NoteMap readTree(ObjectReader reader, ObjectId treeId) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException

Load a collection of notes from a tree.

Parameters
reader:ObjectReader

reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.

treeId:ObjectId

the note tree to read.

Returns:NoteMap

the note map read from the tree.

Exceptions
MissingObjectException:
a reference tree object doesn't exist.
IncorrectObjectTypeException:
a tree object wasn't actually a tree.
CorruptObjectException:
a tree object is corrupt and cannot be read.
IOException:
the repository cannot be accessed through the reader.
removeback to summary
public void remove(AnyObjectId noteOn) throws IOException

Remove a note from an object. If no note exists, no action is performed. This method only updates the map in memory.

Parameters
noteOn:AnyObjectId

the object to remove the note from.

Exceptions
IOException:
a portion of the note space is not accessible.
setback to summary
public void set(AnyObjectId noteOn, ObjectId noteData) throws IOException

Attach (or remove) a note on an object. If no note exists, a new note is stored. If a note already exists for the given object, it is replaced (or removed). This method only updates the map in memory. If the caller wants to attach a UTF-8 encoded string message to an object, set(AnyObjectId, String, ObjectInserter) is a convenient way to encode and update a note in one step.

Parameters
noteOn:AnyObjectId

the object to attach the note to. This same ObjectId can later be used as an argument to get(AnyObjectId) or getCachedBytes(AnyObjectId, int) to read back the noteData.

noteData:ObjectId

data to associate with the note. This must be the ObjectId of a blob that already exists in the repository. If null the note will be deleted, if present.

Exceptions
IOException:
a portion of the note space is not accessible.
setback to summary
public void set(AnyObjectId noteOn, String noteData, ObjectInserter ins) throws IOException

Attach a note to an object. If no note exists, a new note is stored. If a note already exists for the given object, it is replaced (or removed).

Parameters
noteOn:AnyObjectId

the object to attach the note to. This same ObjectId can later be used as an argument to get(AnyObjectId) or getCachedBytes(AnyObjectId, int) to read back the noteData.

noteData:String

text to store in the note. The text will be UTF-8 encoded when stored in the repository. If null the note will be deleted, if the empty string a note with the empty string will be stored.

ins:ObjectInserter

inserter to write the encoded noteData out as a blob. The caller must ensure the inserter is flushed before the updated note map is made available for reading.

Exceptions
IOException:
the note data could not be stored in the repository.
shortenRefNameback to summary
public static String shortenRefName(String noteRefName)

Shorten the note ref name by trimming off the org.eclipse.jgit.lib.Constants#R_NOTES prefix if it exists.

Parameters
noteRefName:String

a java.lang.String object.

Returns:String

a more user friendly note name

writeTreeback to summary
public ObjectId writeTree(ObjectInserter inserter) throws IOException

Write this note map as a tree.

Parameters
inserter:ObjectInserter

inserter to use when writing trees to the object database. Caller is responsible for flushing the inserter before trying to read the objects, or exposing them through a reference.

Returns:ObjectId

the top level tree.

Exceptions
IOException:
a tree could not be written.