Class WeakCache.SegmentList

java.lang.Object
org.simpleframework.xml.util.WeakCache.SegmentList
All Implemented Interfaces:
Iterable<WeakCache<T>.Segment>
Enclosing class:
WeakCache<T>

private class WeakCache.SegmentList extends Object implements Iterable<WeakCache<T>.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 Details

    • list

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

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

    • 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 Details

    • iterator

      public Iterator<WeakCache<T>.Segment> iterator()
      Specified by:
      iterator in interface Iterable<WeakCache<T>.Segment>
    • get

      public WeakCache<T>.Segment get(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(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