From e6bb37d29759b43c845d54cda24cf149fb590004 Mon Sep 17 00:00:00 2001 From: Greg Bowyer Date: Thu, 2 May 2013 17:11:26 +0000 Subject: [PATCH] SOLR-4616: Make HitRatio into a float in mbeans git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1478450 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/search/SolrCacheBase.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java b/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java index 8870f9b805e..0ef707f4f42 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java +++ b/solr/core/src/java/org/apache/solr/search/SolrCacheBase.java @@ -18,6 +18,8 @@ package org.apache.solr.search; import java.io.Serializable; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URL; import java.util.Map; @@ -90,21 +92,13 @@ public abstract class SolrCacheBase { * Returns a "Hit Ratio" (ie: max of 1.00, not a percentage) suitable for * display purposes. */ - protected static String calcHitRatio(long lookups, long hits) { - if (lookups==0) return "0.00"; - if (lookups==hits) return "1.00"; - int hundredths = (int)(hits*100/lookups); // rounded down - if (hundredths < 10) return "0.0" + hundredths; - return "0." + hundredths; - - /*** code to produce a percent, if we want it... - int ones = (int)(hits*100 / lookups); - int tenths = (int)(hits*1000 / lookups) - ones*10; - return Integer.toString(ones) + '.' + tenths; - ***/ + protected static float calcHitRatio(long lookups, long hits) { + return (lookups == 0) ? 0.0f : + BigDecimal.valueOf((double) hits / (double) lookups) + .setScale(2, RoundingMode.HALF_EVEN) + .floatValue(); } - public String getVersion() { return SolrCore.version; }