Coverage Report - org.jtheque.core.managers.cache.CacheConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
CacheConfiguration
0 %
0/30
0 %
0/2
1.062
 
 1  
 package org.jtheque.core.managers.cache;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque 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
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 /**
 20  
  * A cache configuration. It seems a configuration of an EHCache.
 21  
  *
 22  
  * @author Baptiste Wicht
 23  
  */
 24  
 final class CacheConfiguration {
 25  
     private final String name;
 26  
     private int maxElementsInMemory;
 27  
     private int maxElementsOnDisk;
 28  
     private boolean eternal;
 29  
     private boolean overflowToDisk;
 30  
     private boolean diskPersistent;
 31  
     private long timeToIdleSeconds;
 32  
     private long timeToLiveSeconds;
 33  
 
 34  
     private static final int DEFAULT_MAX_ELEMENTS_IN_MEMORY = 1000;
 35  
     private static final int DEFAULT_MAX_ELEMENTS_ON_DISK = 500;
 36  
 
 37  
     /**
 38  
      * Construct a new CacheConfiguration.
 39  
      *
 40  
      * @param name     The name of the cache.
 41  
      * @param defaults Indicate if we must use the defaults values or not.
 42  
      */
 43  
     CacheConfiguration(String name, boolean defaults) {
 44  0
         super();
 45  
 
 46  0
         this.name = name;
 47  
 
 48  0
         if (defaults) {
 49  0
             maxElementsInMemory = DEFAULT_MAX_ELEMENTS_IN_MEMORY;
 50  0
             maxElementsOnDisk = DEFAULT_MAX_ELEMENTS_ON_DISK;
 51  0
             eternal = false;
 52  0
             overflowToDisk = false;
 53  
         }
 54  0
     }
 55  
 
 56  
     /**
 57  
      * Return the maximum number of elements to keep in memory.
 58  
      *
 59  
      * @return The maximum number of elements to keep in memory.
 60  
      */
 61  
     public int getMaxElementsInMemory() {
 62  0
         return maxElementsInMemory;
 63  
     }
 64  
 
 65  
     /**
 66  
      * Set the maximum number of elements to keep in memory.
 67  
      *
 68  
      * @param maxElementsInMemory The maximum number elements to keep in memory.
 69  
      */
 70  
     public void setMaxElementsInMemory(int maxElementsInMemory) {
 71  0
         this.maxElementsInMemory = maxElementsInMemory;
 72  0
     }
 73  
 
 74  
     /**
 75  
      * Return the maximum number of elements to keep in disk.
 76  
      *
 77  
      * @return The maximum number of elements to keep in disk.
 78  
      */
 79  
     public int getMaxElementsOnDisk() {
 80  0
         return maxElementsOnDisk;
 81  
     }
 82  
 
 83  
     /**
 84  
      * Set the maximum number of elements to keep in disk.
 85  
      *
 86  
      * @param maxElementsOnDisk The maximum number elements to keep in disk.
 87  
      */
 88  
     public void setMaxElementsOnDisk(int maxElementsOnDisk) {
 89  0
         this.maxElementsOnDisk = maxElementsOnDisk;
 90  0
     }
 91  
 
 92  
     /**
 93  
      * Indicate if the cache is eternal or not.
 94  
      *
 95  
      * @return true if the cache is eternal else false.
 96  
      */
 97  
     public boolean isEternal() {
 98  0
         return eternal;
 99  
     }
 100  
 
 101  
     /**
 102  
      * Set if the cache is eternal or not.
 103  
      *
 104  
      * @param eternal A boolean flag indicating if the cache is eternal or not.
 105  
      */
 106  
     public void setEternal(boolean eternal) {
 107  0
         this.eternal = eternal;
 108  0
     }
 109  
 
 110  
     /**
 111  
      * Indicate if the cache must put the overflow to the disk or not.
 112  
      *
 113  
      * @return true if the cache put the overflow to the disk else false.
 114  
      */
 115  
     public boolean isOverflowToDisk() {
 116  0
         return overflowToDisk;
 117  
     }
 118  
 
 119  
     /**
 120  
      * Set if overflow must go to the disk or not.
 121  
      *
 122  
      * @param overflowToDisk A boolean flag indicating if the overflow must go to disk.
 123  
      */
 124  
     public void setOverflowToDisk(boolean overflowToDisk) {
 125  0
         this.overflowToDisk = overflowToDisk;
 126  0
     }
 127  
 
 128  
     /**
 129  
      * Return the time after which we must idle the elements.
 130  
      *
 131  
      * @return The time after which we must idle the elements.
 132  
      */
 133  
     public long getTimeToIdleSeconds() {
 134  0
         return timeToIdleSeconds;
 135  
     }
 136  
 
 137  
     /**
 138  
      * Set the time after which we must idle the elements.
 139  
      *
 140  
      * @param timeToIdleSeconds The image after which we must idle the elements.
 141  
      */
 142  
     public void setTimeToIdleSeconds(long timeToIdleSeconds) {
 143  0
         this.timeToIdleSeconds = timeToIdleSeconds;
 144  0
     }
 145  
 
 146  
     /**
 147  
      * Return the time to live of the elements.
 148  
      *
 149  
      * @return The time to live of elements.
 150  
      */
 151  
     public long getTimeToLiveSeconds() {
 152  0
         return timeToLiveSeconds;
 153  
     }
 154  
 
 155  
     /**
 156  
      * Set the time to live of the elements.
 157  
      *
 158  
      * @param timeToLiveSeconds The time to live of the elements.
 159  
      */
 160  
     public void setTimeToLiveSeconds(long timeToLiveSeconds) {
 161  0
         this.timeToLiveSeconds = timeToLiveSeconds;
 162  0
     }
 163  
 
 164  
     /**
 165  
      * Indicate if the disk is persistent or not.
 166  
      *
 167  
      * @return true if the disk store is persistent else false.
 168  
      */
 169  
     public boolean isDiskPersistent() {
 170  0
         return diskPersistent;
 171  
     }
 172  
 
 173  
     /**
 174  
      * Set if the disk store is persistent else false.
 175  
      *
 176  
      * @param diskPersistent A boolean flag indicating if the disk store has to be persistent or not.
 177  
      */
 178  
     public void setDiskPersistent(boolean diskPersistent) {
 179  0
         this.diskPersistent = diskPersistent;
 180  0
     }
 181  
 
 182  
     /**
 183  
      * Return the name of the cache.
 184  
      *
 185  
      * @return The name of the cache.
 186  
      */
 187  
     public String getName() {
 188  0
         return name;
 189  
     }
 190  
 }