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

public Class RefMap

extends AbstractMap<String, Ref>
Class Inheritance
Imports
java.util.AbstractMap, .AbstractSet, .Iterator, .Map, .NoSuchElementException, .Set, java.util.function.BinaryOperator, java.util.stream.Collector, .Collectors, org.eclipse.jgit.lib.AnyObjectId, .ObjectId, .Ref, .RefComparator

Specialized Map to present a RefDatabase namespace.

Although not declared as a java.util.SortedMap, iterators from this map's projections always return references in org.eclipse.jgit.lib.RefComparator ordering. The map's internal representation is a sorted array of org.eclipse.jgit.lib.Ref objects, which means lookup and replacement is O(log N), while insertion and removal can be as expensive as O(N + log N) while the list expands or contracts. Since this is not a general map implementation, all entries must be keyed by the reference name.

This class is really intended as a helper for RefDatabase, which needs to perform a merge-join of three sorted org.eclipse.jgit.util.RefLists in order to present the unified namespace of the packed-refs file, the loose refs/ directory tree, and the resolved form of any symbolic references.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private Set<Map.Entry<String, Ref>>
pack-priv RefList<Ref>
loose

Immutable collection of the loose references at construction time.

pack-priv RefList<Ref>
packed

Immutable collection of the packed references at construction time.

pack-priv final String
prefix

Prefix denoting the reference subspace this map contains.

pack-priv RefList<Ref>
resolved

Immutable collection of resolved symbolic references.

pack-priv int
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
RefMap()

Construct an empty map with a small initial capacity.

public
RefMap(String
prefix used to slice the lists down. Only references whose names start with this prefix will appear to reside in the map. Must not be null, use "" (the empty string) to select all list items.
prefix
,
RefList<? extends Ref>
items from the packed reference list, this is the last list searched.
packed
,
RefList<? extends Ref>
items from the loose reference list, this list overrides packed if a name appears in both.
loose
,
RefList<? extends Ref>
resolved symbolic references. This list overrides the prior list loose, if an item appears in both. Items in this list must also appear in loose.
resolved
)

Construct a map to merge 3 collections together.

Method Summary

Modifier and TypeMethod and Description
public boolean
containsKey(Object
key whose presence in this map is to be tested
name
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public Set<Map.Entry<String, Ref>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public Ref
get(Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public boolean
isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public Ref
put(String
key with which the specified value is to be associated
keyName
,
Ref
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

public Ref
remove(Object
key whose mapping is to be removed from the map
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

pack-priv String
public static Collector<Ref, ?, RefMap>

Returns:

Collector for Ref
toRefMap
(BinaryOperator<Ref>
merge function
mergeFunction
)

Create a Collector for Ref.

private String
public String
toString()

Overrides java.util.AbstractMap.toString.

Returns a string representation of this map.

Inherited from java.util.AbstractMap:
clearclonecontainsValueequalshashCodekeySetputAllsizevalues

Field Detail

entrySetback to summary
private Set<Map.Entry<String, Ref>> entrySet
looseback to summary
pack-priv RefList<Ref> loose

Immutable collection of the loose references at construction time.

If an entry appears here and in packed, this entry must take precedence, as its more current. Symbolic references in this collection are typically unresolved, so they only tell us who their target is, but not the current value of the target.

packedback to summary
pack-priv RefList<Ref> packed

Immutable collection of the packed references at construction time.

prefixback to summary
pack-priv final String prefix

Prefix denoting the reference subspace this map contains.

All reference names in this map must start with this prefix. If the prefix is not the empty string, it must end with a '/'.

resolvedback to summary
pack-priv RefList<Ref> resolved

Immutable collection of resolved symbolic references.

This collection contains only the symbolic references we were able to resolve at map construction time. Other loose references must be read from loose. Every entry in this list must be matched by an entry in loose, otherwise it might be omitted by the map.

sizeback to summary
pack-priv int size
sizeIsValidback to summary
pack-priv boolean sizeIsValid

Constructor Detail

RefMapback to summary
public RefMap()

Construct an empty map with a small initial capacity.

RefMapback to summary
public RefMap(String prefix, RefList<? extends Ref> packed, RefList<? extends Ref> loose, RefList<? extends Ref> resolved)

Construct a map to merge 3 collections together.

Parameters
prefix:String

prefix used to slice the lists down. Only references whose names start with this prefix will appear to reside in the map. Must not be null, use "" (the empty string) to select all list items.

packed:RefList<? extends Ref>

items from the packed reference list, this is the last list searched.

loose:RefList<? extends Ref>

items from the loose reference list, this list overrides packed if a name appears in both.

resolved:RefList<? extends Ref>

resolved symbolic references. This list overrides the prior list loose, if an item appears in both. Items in this list must also appear in loose.

Annotations
@SuppressWarnings:unchecked

Method Detail

containsKeyback to summary
public boolean containsKey(Object name)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Doc from java.util.AbstractMap.containsKey.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Parameters
name:Object

Doc from java.util.Map.containsKey.

key whose presence in this map is to be tested

Returns:boolean

Doc from java.util.Map.containsKey.

true if this map contains a mapping for the specified key

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<String, Ref>> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<String, Ref>>

a set view of the mappings contained in this map

Annotations
@Override
getback to summary
public Ref get(Object key)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Doc from java.util.AbstractMap.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
key:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:Ref

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Doc from java.util.AbstractMap.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

Doc from java.util.Map.isEmpty.

true if this map contains no key-value mappings

Annotations
@Override
putback to summary
public Ref put(String keyName, Ref value)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Doc from java.util.AbstractMap.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
keyName:String

Doc from java.util.Map.put.

key with which the specified value is to be associated

value:Ref

Doc from java.util.Map.put.

value to be associated with the specified key

Returns:Ref

Doc from java.util.Map.put.

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

Annotations
@Override
removeback to summary
public Ref remove(Object key)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Doc from java.util.AbstractMap.remove.

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters
key:Object

Doc from java.util.Map.remove.

key whose mapping is to be removed from the map

Returns:Ref

Doc from java.util.Map.remove.

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
toMapKeyback to summary
pack-priv String toMapKey(Ref ref)
toRefMapback to summary
public static Collector<Ref, ?, RefMap> toRefMap(BinaryOperator<Ref> mergeFunction)

Create a Collector for Ref.

Parameters
mergeFunction:BinaryOperator<Ref>

merge function

Returns:Collector<Ref, ?, RefMap>

Collector for Ref

Since
5.4
toRefNameback to summary
private String toRefName(String name)
toStringback to summary
public String toString()

Overrides java.util.AbstractMap.toString.

Doc from java.util.AbstractMap.toString.

Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this map

Annotations
@Override
org.eclipse.jgit.util back to summary

private Class RefMap.Ent

extends Object
implements Map.Entry<String, Ref>
Class Inheritance
All Implemented Interfaces
java.util.Map.Entry

Field Summary

Modifier and TypeField and Description
private Ref

Constructor Summary

AccessConstructor and Description
pack-priv
Ent(Ref ref)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
object to be compared for equality with this map entry
obj
)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Compares the specified object with this entry for equality.

public String
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

public Ref
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry.

public Ref
setValue(Ref
new value to be stored in this entry
value
)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

refback to summary
private Ref ref

Constructor Detail

Entback to summary
pack-priv Ent(Ref ref)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Doc from java.util.Map.Entry.equals.

Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if

    (e1.getKey()==null ?
     e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
    (e1.getValue()==null ?
     e2.getValue()==null : e1.getValue().equals(e2.getValue()))
This ensures that the equals method works properly across different implementations of the Map.Entry interface.
Parameters
obj:Object

object to be compared for equality with this map entry

Returns:boolean

true if the specified object is equal to this map entry

Annotations
@Override
getKeyback to summary
public String getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

Returns:String

the key corresponding to this entry

Annotations
@Override
getValueback to summary
public Ref getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Returns:Ref

the value corresponding to this entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Doc from java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:

    (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
    (e.getValue()==null ? 0 : e.getValue().hashCode())
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
Returns:int

the hash code value for this map entry

Annotations
@Override
setValueback to summary
public Ref setValue(Ref value)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
value:Ref

new value to be stored in this entry

Returns:Ref

old value corresponding to the entry

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jgit.util back to summary

private Class RefMap.SetIterator

extends Object
implements Iterator<Map.Entry<String, Ref>>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int
private Map.Entry<String, Ref>
private int
private int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Map.Entry<String, Ref>
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public Map.Entry<String, Ref>
peek()

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

private Ref
private RefMap.Ent
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

looseIdxback to summary
private int looseIdx
nextback to summary
private Map.Entry<String, Ref> next
packedIdxback to summary
private int packedIdx
resolvedIdxback to summary
private int resolvedIdx

Constructor Detail

SetIteratorback to summary
pack-priv SetIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Map.Entry<String, Ref> next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Map.Entry<String, Ref>

the next element in the iteration

Annotations
@Override
peekback to summary
public Map.Entry<String, Ref> peek()
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
resolveLooseback to summary
private Ref resolveLoose(Ref l)
toEntryback to summary
private RefMap.Ent toEntry(Ref p)