1
2
3
4
5
6
7 package ca.uhn.cache.internal.impl;
8
9 import java.util.Map;
10
11 import ca.uhn.cache.CacheReasonEnum;
12 import ca.uhn.cache.internal.IChunk;
13 import ca.uhn.cache.internal.IUnusedChunkRule;
14
15 /***
16 * Default implementation of IUnusedChunkRule.
17 *
18 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
19 * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:54:03 $ by $Author: bryan_tripp $
20 */
21 public class DefaultUnusedChunkRule implements IUnusedChunkRule {
22
23 private Map myModifiers;
24
25 /***
26 * @param theModifiers keys are CacheReasonEnum, values are corresponding Longs representing
27 * vogueness modifiers for each reason (default is 0)
28 */
29 public DefaultUnusedChunkRule(Map theModifiers) {
30 myModifiers = theModifiers;
31 }
32
33 /***
34 * @see ca.uhn.cache.internal.IUnusedChunkRule#getVoguenessModifier(ca.uhn.cache.internal.IChunk)
35 */
36 public long getVoguenessModifier(IChunk theChunk) {
37 long modifier = 0;
38
39 CacheReasonEnum[] reasons = theChunk.getReasons();
40 for (int i = 0; i < reasons.length; i++) {
41 modifier += getModifier(reasons[i]);
42 }
43
44 return modifier;
45 }
46
47 /***
48 * @param theReason a reason the chunk is being cached
49 * @return the vogueness modifier
50 */
51 private long getModifier(CacheReasonEnum theReason) {
52 long result = 0;
53 Long modifier = (Long) myModifiers.get(theReason);
54 if (modifier != null) {
55 result = modifier.longValue();
56 }
57 return result;
58 }
59
60 }