Top Description Inners Fields Constructors Methods
org.eclipse.jgit.lib

public Class ObjectIdOwnerMap<V extends ObjectIdOwnerMap.Entry>

extends Object
implements Iterable<V extends ObjectIdOwnerMap.Entry>, ObjectIdSet
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.lib.ObjectIdSet, java.lang.Iterable
Type Parameters
<V>
type of subclass of ObjectId that will be stored in the map.
Imports
java.util.Arrays, .Iterator, .NoSuchElementException

Fast, efficient map for org.eclipse.jgit.lib.ObjectId subclasses in only one map.

To use this map type, applications must have their entry value type extend from org.eclipse.jgit.lib.ObjectIdOwnerMap.Entry, which itself extends from ObjectId.

Object instances may only be stored in ONE ObjectIdOwnerMap. This restriction exists because the map stores internal map state within each object instance. If an instance is be placed in another ObjectIdOwnerMap it could corrupt one or both map's internal state.

If an object instance must be in more than one map, applications may use ObjectIdOwnerMap for one of the maps, and org.eclipse.jgit.lib.ObjectIdSubclassMap for the other map(s). It is encouraged to use ObjectIdOwnerMap for the map that is accessed most often, as this implementation runs faster than the more general ObjectIdSubclassMap implementation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
ObjectIdOwnerMap.Entry

Type of entry stored in the ObjectIdOwnerMap.

Field Summary

Modifier and TypeField and Description
pack-priv int
bits

Number of low bits used to form the index into directory.

pack-priv V[][]
directory

Top level directory of the segments.

private int
grow

The map doubles in capacity when size reaches this target.

private static final int
INITIAL_DIRECTORY

Size of the initial directory, will grow as necessary.

private int
mask

Low bit mask to index into directory, 2^bits-1.

private static final int
SEGMENT_BITS

Number of bits in a segment's index.

private static final int
pack-priv int
size

Total number of objects in this map.

Constructor Summary

AccessConstructor and Description
public
ObjectIdOwnerMap()

Create an empty map.

Method Summary

Modifier and TypeMethod and Description
public <
type of values
Q extends V
>
void
add(Q
the object to store.
newValue
)

Store an object for future lookup.

public <
type of values
Q extends V
>
V

Returns:

newValue if stored, or the prior value already stored and that would have been returned had the caller used get(newValue) first.
addIfAbsent
(Q
the object to store.
newValue
)

Store an object for future lookup.

public void
clear()

Remove all entries from this map.

private static final int
computeGrowAt(int bits)

public boolean
contains(AnyObjectId
the objectId to find
toFind
)

Implements org.eclipse.jgit.lib.ObjectIdSet.contains.

Returns true if the objectId is contained within the collection.

private static final boolean
equals(AnyObjectId firstObjectId, AnyObjectId secondObjectId)

public V

Returns:

the instance mapped to toFind, or null if no mapping exists.
get
(AnyObjectId
the object identifier to find.
toFind
)

Lookup an existing mapping.

private void
grow()

public boolean

Returns:

true if size() is 0.
isEmpty
()

Whether this map is empty

public Iterator<V>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

private final V[]
public int

Returns:

number of objects in this map.
size
()

Get number of objects in this map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bitsback to summary
pack-priv int bits

Number of low bits used to form the index into directory.

directoryback to summary
pack-priv V[][] directory

Top level directory of the segments.

The low bits of the SHA-1 are used to select the segment from this directory. Each segment is constant sized at 2^SEGMENT_BITS.

growback to summary
private int grow

The map doubles in capacity when size reaches this target.

INITIAL_DIRECTORYback to summary
private static final int INITIAL_DIRECTORY

Size of the initial directory, will grow as necessary.

maskback to summary
private int mask

Low bit mask to index into directory, 2^bits-1.

SEGMENT_BITSback to summary
private static final int SEGMENT_BITS

Number of bits in a segment's index. Segments are 2^11 in size.

SEGMENT_SHIFTback to summary
private static final int SEGMENT_SHIFT
sizeback to summary
pack-priv int size

Total number of objects in this map.

Constructor Detail

ObjectIdOwnerMapback to summary
public ObjectIdOwnerMap()

Create an empty map.

Annotations
@SuppressWarnings:unchecked

Method Detail

addback to summary
public <Q extends V> void add(Q newValue)

Store an object for future lookup.

An existing mapping for must not be in this map. Callers must first call get(AnyObjectId) to verify there is no current mapping prior to adding a new mapping, or use addIfAbsent(Entry).

Parameters
<Q>
type of values
newValue:Q

the object to store.

addIfAbsentback to summary
public <Q extends V> V addIfAbsent(Q newValue)

Store an object for future lookup.

Stores newValue, but only if there is not already an object for the same object name. Callers can tell if the value is new by checking the return value with reference equality:

V obj = ...;
boolean wasNew = map.addIfAbsent(obj) == obj;
Parameters
<Q>
type of values
newValue:Q

the object to store.

Returns:V

newValue if stored, or the prior value already stored and that would have been returned had the caller used get(newValue) first.

Annotations
@SuppressWarnings:unchecked
clearback to summary
public void clear()

Remove all entries from this map.

computeGrowAtback to summary
private static final int computeGrowAt(int bits)
containsback to summary
public boolean contains(AnyObjectId toFind)

Implements org.eclipse.jgit.lib.ObjectIdSet.contains.

Doc from org.eclipse.jgit.lib.ObjectIdSet.contains.

Returns true if the objectId is contained within the collection.

Returns true if this map contains the specified object.

Parameters
toFind:AnyObjectId

the objectId to find

Returns:boolean

whether the collection contains the objectId.

Annotations
@Override
equalsback to summary
private static final boolean equals(AnyObjectId firstObjectId, AnyObjectId secondObjectId)
getback to summary
public V get(AnyObjectId toFind)

Lookup an existing mapping.

Parameters
toFind:AnyObjectId

the object identifier to find.

Returns:V

the instance mapped to toFind, or null if no mapping exists.

Annotations
@SuppressWarnings:unchecked
growback to summary
private void grow()
Annotations
@SuppressWarnings:unchecked
isEmptyback to summary
public boolean isEmpty()

Whether this map is empty

Returns:boolean

true if size() is 0.

iteratorback to summary
public Iterator<V> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<V>

an Iterator.

Annotations
@Override
newSegmentback to summary
private final V[] newSegment()
Annotations
@SuppressWarnings:unchecked
sizeback to summary
public int size()

Get number of objects in this map.

Returns:int

number of objects in this map.

org.eclipse.jgit.lib back to summary

public abstract Class ObjectIdOwnerMap.Entry

extends ObjectId
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.revwalk.RevObject, org.eclipse.jgit.transport.PackedObjectInfo, org.eclipse.jgit.transport.PackParser.DeltaChain, org.eclipse.jgit.internal.fsck.FsckPackParser.ObjFromPack, org.eclipse.jgit.internal.storage.commitgraph.GraphCommits.CommitWithPosition, org.eclipse.jgit.internal.storage.file.BasePackBitmapIndex.StoredBitmap, org.eclipse.jgit.internal.storage.file.BitmapIndexImpl.MutableEntry, org.eclipse.jgit.internal.storage.file.CachedObjectDirectory.UnpackedObjectId, org.eclipse.jgit.internal.storage.file.LazyObjectIdSetFile.Entry, org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder.PositionEntry, org.eclipse.jgit.internal.storage.pack.BaseSearch.TreeWithData, org.eclipse.jgit.internal.storage.reftable.ReftableWriter.RefList

Type of entry stored in the ObjectIdOwnerMap.

Field Summary

Modifier and TypeField and Description
pack-priv transient ObjectIdOwnerMap.Entry

Constructor Summary

AccessConstructor and Description
public
Entry(AnyObjectId
the id the entry represents.
id
)

Initialize this entry with a specific ObjectId.

Method Summary

Inherited from org.eclipse.jgit.lib.ObjectId:
equalsfromRawfromRawfromRawfromRawfromRawfromStringfromStringisIdtoObjectIdtoStringzeroId

Field Detail

nextback to summary
pack-priv transient ObjectIdOwnerMap.Entry next

Constructor Detail

Entryback to summary
public Entry(AnyObjectId id)

Initialize this entry with a specific ObjectId.

Parameters
id:AnyObjectId

the id the entry represents.