Package org.simpleframework.xml.util
Class WeakCache.SegmentList
- java.lang.Object
-
- org.simpleframework.xml.util.WeakCache.SegmentList
-
- All Implemented Interfaces:
java.lang.Iterable<WeakCache.Segment>
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>listThe list of segment objects maintained by this object.private intsizeRepresents the number of segments this object maintains.
-
Constructor Summary
Constructors Constructor Description SegmentList(int size)Constructor for theSegmentListobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcreate(int size)Upon initialization the segment list is populated in such a way that synchronization is not needed.WeakCache.Segmentget(java.lang.Object key)This is used to acquire the segment using the given key.java.util.Iterator<WeakCache.Segment>iterator()private intsegment(java.lang.Object key)This method performs the translation of the key hash code to the segment index within the list.
-
-
-
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.
-
-
Method Detail
-
iterator
public java.util.Iterator<WeakCache.Segment> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<WeakCache.Segment>
-
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
-
-