KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > eviction > EvictionPolicyConfigBase


1 package org.jboss.cache.eviction;
2
3 import org.jboss.cache.config.ConfigurationComponent;
4 import org.jboss.cache.config.ConfigurationException;
5 import org.jboss.cache.config.Dynamic;
6
7 /**
8  * Base implementation of {@link EvictionPolicyConfig}. Adds properties
9  * for the most commonly used config elements.
10  *
11  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani</a>
12  */

13 public abstract class EvictionPolicyConfigBase
14    extends ConfigurationComponent
15    implements EvictionPolicyConfig
16 {
17    /** The serialVersionUID */
18    private static final long serialVersionUID = 4591691674370188932L;
19    
20    private String JavaDoc evictionPolicyClass;
21    @Dynamic
22    private int maxNodes = 0;
23
24    /**
25     * Can only be instantiated by a subclass.
26     *
27     */

28    protected EvictionPolicyConfigBase() {}
29
30    public String JavaDoc getEvictionPolicyClass()
31    {
32       return evictionPolicyClass;
33    }
34    
35    public void setEvictionPolicyClass(String JavaDoc evictionPolicyClass)
36    {
37       testImmutability("evictionPolicyClass");
38       this.evictionPolicyClass = evictionPolicyClass;
39    }
40
41    public int getMaxNodes()
42    {
43       return maxNodes;
44    }
45    
46    public void setMaxNodes(int maxNodes)
47    {
48       testImmutability("maxNodes");
49       this.maxNodes = maxNodes;
50    }
51    
52    public void validate() throws ConfigurationException
53    {
54       // no-op
55
}
56
57    @Override JavaDoc
58    public boolean equals(Object JavaDoc obj)
59    {
60       if (this == obj)
61          return true;
62       
63       if (obj instanceof EvictionPolicyConfigBase)
64       {
65          EvictionPolicyConfigBase other = (EvictionPolicyConfigBase) obj;
66          
67          return this.maxNodes == other.maxNodes
68                   && safeEquals(this.evictionPolicyClass, other.evictionPolicyClass);
69       }
70       
71       return false;
72    }
73
74    @Override JavaDoc
75    public int hashCode()
76    {
77       int result = 17;
78       result = 31 * result + maxNodes;
79       result = 31 * result + (evictionPolicyClass == null ? 0 : evictionPolicyClass.hashCode());
80       return result;
81    }
82    
83    public void reset()
84    {
85       setEvictionPolicyClass(null);
86       setMaxNodes(0);
87       setEvictionPolicyClassName();
88    }
89
90    /**
91     * This method allows implementers a chance to set the policy class name.
92     * This should be called when the implementation is constructed, but is also
93     * called in {@link #reset()}
94     */

95    abstract protected void setEvictionPolicyClassName();
96 }
97
Popular Tags