1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.macro.cache

File CacheKey.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

4
17
6
1
104
48
9
0.53
2.83
6
1.5

Classes

Class Line # Actions
CacheKey 30 17 0% 9 13
0.518518551.9%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.internal.macro.cache;
21   
22    /**
23    * Key to recognize a given Cache. We need to have several caches since currently there's one cache per
24    * timeToLive/maxEntry combination. This is because currently we cannot set these configuration values at the cache
25    * entry level but only for the whole cache.
26    *
27    * @version $Id: bb068012f9a0f5b4fcbbda5dcfe0b2a65eb94010 $
28    * @since 3.3M1
29    */
 
30    public class CacheKey
31    {
32    /**
33    * @see #getTimeToLive()
34    */
35    private int timeToLive;
36   
37    /**
38    * @see #getMaxEntries()
39    */
40    private int maxEntries;
41   
42    /**
43    * @param timeToLive see {@link #getTimeToLive()}
44    * @param maxEntries see {@link #getMaxEntries()}
45    */
 
46  5 toggle public CacheKey(int timeToLive, int maxEntries)
47    {
48  5 this.timeToLive = timeToLive;
49  5 this.maxEntries = maxEntries;
50    }
51   
52    /**
53    * @return the number of seconds to cache the content
54    */
 
55  13 toggle public int getTimeToLive()
56    {
57  13 return this.timeToLive;
58    }
59   
60    /**
61    * @return the maximum number of entries in the cache (Least Recently Used entries are ejected)
62    */
 
63  13 toggle public int getMaxEntries()
64    {
65  13 return this.maxEntries;
66    }
67   
 
68  0 toggle @Override
69    public boolean equals(Object object)
70    {
71  0 boolean result;
72   
73    // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
74  0 if (this == object) {
75  0 result = true;
76    } else {
77  0 if ((object == null) || (object.getClass() != this.getClass())) {
78  0 result = false;
79    } else {
80    // object must be Syntax at this point
81  0 CacheKey cacheKey = (CacheKey) object;
82  0 result = (getTimeToLive() == cacheKey.getTimeToLive() && getMaxEntries() == cacheKey.getMaxEntries());
83    }
84    }
85  0 return result;
86    }
87   
 
88  8 toggle @Override
89    public int hashCode()
90    {
91    // Random number. See http://www.technofundo.com/tech/java/equalhash.html for the detail of this
92    // algorithm.
93  8 int hash = 9;
94  8 hash = 31 * hash + getTimeToLive();
95  8 hash = 31 * hash + getMaxEntries();
96  8 return hash;
97    }
98   
 
99  5 toggle @Override
100    public String toString()
101    {
102  5 return getTimeToLive() + "s-" + getMaxEntries();
103    }
104    }