Class WeakCache.SegmentList

  • All Implemented Interfaces:
    java.lang.Iterable<WeakCache.Segment>
    Enclosing class:
    WeakCache<T>

    private class WeakCache.SegmentList
    extends java.lang.Object
    implements java.lang.Iterable<WeakCache.Segment>
    This is used to maintain a list of segments. All segments that are stored by this object can be acquired using a given key. The keys hash is used to select the segment, this ensures that all read and write operations with the same key result in the same segment object within this list.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<WeakCache.Segment> list
      The list of segment objects maintained by this object.
      private int size
      Represents the number of segments this object maintains.
    • Constructor Summary

      Constructors 
      Constructor Description
      SegmentList​(int size)
      Constructor for the SegmentList object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void create​(int size)
      Upon initialization the segment list is populated in such a way that synchronization is not needed.
      WeakCache.Segment get​(java.lang.Object key)
      This is used to acquire the segment using the given key.
      java.util.Iterator<WeakCache.Segment> iterator()  
      private int segment​(java.lang.Object key)
      This method performs the translation of the key hash code to the segment index within the list.
      • 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

      • list

        private java.util.List<WeakCache.Segment> list
        The list of segment objects maintained by this object.
      • size

        private int size
        Represents the number of segments this object maintains.
    • Constructor Detail

      • SegmentList

        public SegmentList​(int size)
        Constructor for the SegmentList object. This is used to create a list of weak hash maps that can be acquired using the hash code of a given key.
        Parameters:
        size - this is the number of hash maps to maintain
    • Method Detail

      • get

        public WeakCache.Segment get​(java.lang.Object key)
        This is used to acquire the segment using the given key. The keys hash is used to determine the index within the list to acquire the segment, which is a synchronized weak hash map storing the key value pairs for a given hash.
        Parameters:
        key - this is the key used to determine the segment
        Returns:
        the segment that is stored at the resolved hash
      • create

        private void create​(int size)
        Upon initialization the segment list is populated in such a way that synchronization is not needed. Each segment is created and stored in an increasing index within the list.
        Parameters:
        size - this is the number of segments to be used
      • segment

        private int segment​(java.lang.Object key)
        This method performs the translation of the key hash code to the segment index within the list. Translation is done by acquiring the modulus of the hash and the list size.
        Parameters:
        key - this is the key used to resolve the index
        Returns:
        the index of the segment within the list