Class ObjectIdSubclassMap<V extends ObjectId>

  • Type Parameters:
    V - type of subclass of ObjectId that will be stored in the map.
    All Implemented Interfaces:
    java.lang.Iterable<V>, ObjectIdSet

    public class ObjectIdSubclassMap<V extends ObjectId>
    extends java.lang.Object
    implements java.lang.Iterable<V>, ObjectIdSet
    Fast, efficient map specifically for ObjectId subclasses.

    This map provides an efficient translation from any ObjectId instance to a cached subclass of ObjectId that has the same value.

    If object instances are stored in only one map, ObjectIdOwnerMap is a more efficient implementation.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int grow  
      private static int INITIAL_TABLE_SIZE  
      private int mask  
      (package private) int size  
      (package private) V[] table  
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectIdSubclassMap()
      Create an empty map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <Q extends V>
      void
      add​(Q newValue)
      Store an object for future lookup.
      <Q extends V>
      V
      addIfAbsent​(Q newValue)
      Store an object for future lookup.
      void clear()
      Remove all entries from this map.
      boolean contains​(AnyObjectId toFind)
      Returns true if the objectId is contained within the collection.
      private V[] createArray​(int sz)  
      V get​(AnyObjectId toFind)
      Lookup an existing mapping.
      private void grow()  
      private void initTable​(int sz)  
      private void insert​(V newValue)  
      boolean isEmpty()
      Whether size() is 0.
      java.util.Iterator<V> iterator()
      int size()
      Get number of objects in map
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • size

        int size
      • grow

        private int grow
      • mask

        private int mask
    • Constructor Detail

      • ObjectIdSubclassMap

        public ObjectIdSubclassMap()
        Create an empty map.
    • Method Detail

      • clear

        public void clear()
        Remove all entries from this map.
      • get

        public V get​(AnyObjectId toFind)
        Lookup an existing mapping.
        Parameters:
        toFind - the object identifier to find.
        Returns:
        the instance mapped to toFind, or null if no mapping exists.
      • contains

        public boolean contains​(AnyObjectId toFind)
        Returns true if the objectId is contained within the collection.

        Returns true if this map contains the specified object.

        Specified by:
        contains in interface ObjectIdSet
        Parameters:
        toFind - the objectId to find
        Returns:
        whether the collection contains the objectId.
      • add

        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(ObjectId).

        Parameters:
        newValue - the object to store.
      • addIfAbsent

        public <Q extends VV 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:
        newValue - the object to store.
        Returns:
        newValue if stored, or the prior value already stored and that would have been returned had the caller used get(newValue) first.
      • size

        public int size()
        Get number of objects in map
        Returns:
        number of objects in map
      • isEmpty

        public boolean isEmpty()
        Whether size() is 0.
        Returns:
        true if size() is 0.
      • iterator

        public java.util.Iterator<V> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<V extends ObjectId>
      • insert

        private void insert​(V newValue)
      • grow

        private void grow()
      • initTable

        private void initTable​(int sz)
      • createArray

        private final V[] createArray​(int sz)