Class RefMap

  • All Implemented Interfaces:
    java.util.Map<java.lang.String,​Ref>

    public class RefMap
    extends java.util.AbstractMap<java.lang.String,​Ref>
    Specialized Map to present a RefDatabase namespace.

    Although not declared as a SortedMap, iterators from this map's projections always return references in RefComparator ordering. The map's internal representation is a sorted array of 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 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 Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  RefMap.Ent  
      private class  RefMap.SetIterator  
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Set<java.util.Map.Entry<java.lang.String,​Ref>> entrySet  
      (package private) RefList<Ref> loose
      Immutable collection of the loose references at construction time.
      (package private) RefList<Ref> packed
      Immutable collection of the packed references at construction time.
      (package private) java.lang.String prefix
      Prefix denoting the reference subspace this map contains.
      (package private) RefList<Ref> resolved
      Immutable collection of resolved symbolic references.
      (package private) int size  
      (package private) boolean sizeIsValid  
    • Constructor Summary

      Constructors 
      Constructor Description
      RefMap()
      Construct an empty map with a small initial capacity.
      RefMap​(java.lang.String prefix, RefList<? extends Ref> packed, RefList<? extends Ref> loose, RefList<? extends Ref> resolved)
      Construct a map to merge 3 collections together.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsKey​(java.lang.Object name)
      java.util.Set<java.util.Map.Entry<java.lang.String,​Ref>> entrySet()
      Ref get​(java.lang.Object key)
      boolean isEmpty()
      Ref put​(java.lang.String keyName, Ref value)
      Ref remove​(java.lang.Object key)
      (package private) java.lang.String toMapKey​(Ref ref)  
      static java.util.stream.Collector<Ref,​?,​RefMap> toRefMap​(java.util.function.BinaryOperator<Ref> mergeFunction)
      Create a Collector for Ref.
      private java.lang.String toRefName​(java.lang.String name)  
      java.lang.String toString()
      • Methods inherited from class java.util.AbstractMap

        clear, clone, containsValue, equals, hashCode, keySet, putAll, size, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • prefix

        final java.lang.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 '/'.

      • packed

        RefList<Ref> packed
        Immutable collection of the packed references at construction time.
      • loose

        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.

      • resolved

        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.

      • size

        int size
      • sizeIsValid

        boolean sizeIsValid
      • entrySet

        private java.util.Set<java.util.Map.Entry<java.lang.String,​Ref>> entrySet
    • Constructor Detail

      • RefMap

        public RefMap()
        Construct an empty map with a small initial capacity.
      • RefMap

        public RefMap​(java.lang.String prefix,
                      RefList<? extends Ref> packed,
                      RefList<? extends Ref> loose,
                      RefList<? extends Ref> resolved)
        Construct a map to merge 3 collections together.
        Parameters:
        prefix - 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 - items from the packed reference list, this is the last list searched.
        loose - items from the loose reference list, this list overrides packed if a name appears in both.
        resolved - 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.
    • Method Detail

      • containsKey

        public boolean containsKey​(java.lang.Object name)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​Ref>
        Overrides:
        containsKey in class java.util.AbstractMap<java.lang.String,​Ref>
      • get

        public Ref get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,​Ref>
        Overrides:
        get in class java.util.AbstractMap<java.lang.String,​Ref>
      • put

        public Ref put​(java.lang.String keyName,
                       Ref value)
        Specified by:
        put in interface java.util.Map<java.lang.String,​Ref>
        Overrides:
        put in class java.util.AbstractMap<java.lang.String,​Ref>
      • remove

        public Ref remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,​Ref>
        Overrides:
        remove in class java.util.AbstractMap<java.lang.String,​Ref>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,​Ref>
        Overrides:
        isEmpty in class java.util.AbstractMap<java.lang.String,​Ref>
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​Ref>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,​Ref>
        Specified by:
        entrySet in class java.util.AbstractMap<java.lang.String,​Ref>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap<java.lang.String,​Ref>
      • toRefMap

        public static java.util.stream.Collector<Ref,​?,​RefMap> toRefMap​(java.util.function.BinaryOperator<Ref> mergeFunction)
        Create a Collector for Ref.
        Parameters:
        mergeFunction -
        Returns:
        Collector for Ref
        Since:
        5.4
      • toRefName

        private java.lang.String toRefName​(java.lang.String name)
      • toMapKey

        java.lang.String toMapKey​(Ref ref)