1 7 package org.nemesis.forum.webapp.admin.bean; 8 9 import java.text.DecimalFormat ; 10 11 import org.nemesis.forum.util.cache.Cache; 12 13 14 public class CacheBean{ 15 16 Cache cache; 17 int id; 18 String name; 19 20 DecimalFormat formatter = new DecimalFormat ("#0.00"); 21 DecimalFormat formatter2 = new DecimalFormat ("#0"); 22 23 public CacheBean( int _id, String _name,Cache _cache) { 24 this.cache=_cache; 25 26 this.id=_id; 27 this.name=_name; 28 29 } 30 31 public String getMoFormattedSize(){ 32 double totalMem = (double)cache.getMaxSize()/(1024*1024); 33 return formatter.format(totalMem)+" MB"; 34 } 35 public String getKoSize(){ 36 double totalMem = (double)cache.getMaxSize()/1024; 37 return formatter2.format(totalMem); 38 } 39 public String getPercentFree(){ 40 double memUsed = (double)cache.getSize()/(1024*1024); 41 double totalMem = (double)cache.getMaxSize()/(1024*1024); 42 double freeMem = 100 - 100*memUsed/totalMem; 43 44 return formatter.format(freeMem)+" %"; 45 } 46 47 public String getEffectiveness(){ 48 double hitPercent; 49 if (cache.getCacheHits() + cache.getCacheMisses() == 0) { hitPercent = 0.0; } 50 else { hitPercent = 100*(double)cache.getCacheHits()/(cache.getCacheHits()+cache.getCacheMisses()); } 51 return formatter.format(hitPercent)+" %"; 52 } 53 54 57 public String getHits() { 58 return ""+cache.getCacheHits(); 59 } 60 61 64 public int getId() { 65 return id; 66 } 67 68 71 public String getMisses() { 72 return cache.getCacheMisses()+""; 73 } 74 75 78 public String getName() { 79 return name; 80 } 81 82 85 public int getNumber() { 86 return cache.getNumElements(); 87 } 88 89 90 91 } | Popular Tags |