diff options
author | Daniel Cohen Gindi <danielgindi@gmail.com> | 2016-08-09 15:33:26 +0300 |
---|---|---|
committer | Daniel Cohen Gindi <danielgindi@gmail.com> | 2016-08-09 15:34:11 +0300 |
commit | 02bf21df50f2d31f3f9c7276b24aba9a3dae163e (patch) | |
tree | 3068f14ea9448e23f0dc8ea9555ec7a9fc5d5efc /MPChartLib | |
parent | e841b697be0de4179fb23a4ed7e0e05e580ced9a (diff) | |
download | MPAndroidChart-02bf21df50f2d31f3f9c7276b24aba9a3dae163e.tar.gz |
Reverse string formatter caches
These *will* cause trouble.
We know of users who format the strings based on the entry's location,
view port scroll/scale, etc.
The cache will repeat irrelevant values, and gain no benefit for us.
Diffstat (limited to 'MPChartLib')
7 files changed, 27 insertions, 673 deletions
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java index f55fc817..ad3bb783 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java @@ -10,9 +10,9 @@ import java.text.DecimalFormat; public class DefaultAxisValueFormatter implements AxisValueFormatter { /** - * FormattedStringFormat for formatting and caching + * decimalformat for formatting */ - protected FormattedStringCache.PrimFloat mFormattedStringCache; + protected DecimalFormat mFormat; /** * the number of decimal digits this formatter uses @@ -35,15 +35,13 @@ public class DefaultAxisValueFormatter implements AxisValueFormatter { b.append("0"); } - mFormattedStringCache = new FormattedStringCache.PrimFloat(new DecimalFormat("###,###,###,##0" + b.toString())); + mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); } @Override public String getFormattedValue(float value, AxisBase axis) { - - // TODO: There should be a better way to do this. Floats are not the best keys... - return mFormattedStringCache.getFormattedValue(value); - + // avoid memory allocations here (for performance) + return mFormat.format(value); } @Override diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java index 8d169b14..5d23d25f 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java @@ -15,9 +15,9 @@ import java.text.DecimalFormat; public class DefaultValueFormatter implements ValueFormatter { /** - * FormattedStringCache for formatting and caching. + * DecimalFormat for formatting */ - protected FormattedStringCache.Generic<Integer, Float> mFormattedStringCache; + protected DecimalFormat mFormat; protected int mDecimalDigits; @@ -47,13 +47,16 @@ public class DefaultValueFormatter implements ValueFormatter { b.append("0"); } - mFormattedStringCache = new FormattedStringCache.Generic<>(new DecimalFormat("###,###,###,##0" + b.toString())); - + mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); } @Override public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { - return mFormattedStringCache.getFormattedValue(value, dataSetIndex); + + // put more logic here ... + // avoid memory allocations here (for performance reasons) + + return mFormat.format(value); } /** diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/FormattedStringCache.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/FormattedStringCache.java deleted file mode 100644 index c6b4ef3e..00000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/FormattedStringCache.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.github.mikephil.charting.formatter; - -import java.text.Format; -import java.util.ArrayList; -import java.util.HashMap; - -/** - * Created by Tony Patino on 6/29/16. - * - * COST : Frequently the V type, and the K type will often be passed as primitives (float / int / double) - * This will incur an auto-boxing penalty, and an instantiation on each call. - * - * BENEFIT : Formatting of Strings is one of the costliest operations remaining, and it is larger than the boxing penalty. - * Eliminating redundant formats helps more than boxing hurts. - * - * Possibly want to make some explicit primitive enabled caches, though they can be ugly. - * - */ -public class FormattedStringCache { - - protected Format mFormat; - - public Format getFormat(){ - return mFormat; - } - - public FormattedStringCache(Format format){ - this.mFormat = format; - } - - - /** - * Cache a Formatted String, derived from formatting value V in the Format passed to the constructor. - * Use the object K as a way to quickly look up the string in the cache. - * If value of V has changed since the last time the cache was accessed, re-format the string. - * - * NOTE: This version relies on auto-boxing of primitive values. As a result, it has worse memory performance - * than the Prim versions. - * - * @param <K> - * @param <V> - */ - public static class Generic<K,V> extends FormattedStringCache{ - - private HashMap<K, String> mCachedStringsHashMap = new HashMap<>(); - private HashMap<K, V> mCachedValuesHashMap = new HashMap<>(); - - public Generic(Format format){ - super(format); - } - - public String getFormattedValue(V value, K key){ - - // If we can't find the value at all, create an entry for it, and format the string. - if(!mCachedValuesHashMap.containsKey(key)){ - mCachedStringsHashMap.put(key, mFormat.format(value)); - mCachedValuesHashMap.put(key, value); - } - - // If the old value and the new one don't match, format the string and store it, because the string's value will be different now. - if(!value.equals(mCachedValuesHashMap.get(key))){ - mCachedStringsHashMap.put(key, mFormat.format(value)); - mCachedValuesHashMap.put(key, value); - } - - String result = mCachedStringsHashMap.get(key); - - return result; - } - } - - /** - * Cache a Formatted String, derived from formatting float value in the Format passed to the constructor. - * Use the integer as a way to quickly look up the string in the cache. - * If value of V has changed since the last time the cache was accessed, re-format the string. - * - */ - public static class PrimIntFloat extends FormattedStringCache{ - - public PrimIntFloat(Format format){ - super(format); - } - - private ArrayList<Float> cachedValues = new ArrayList<>(); - private ArrayList<String> cachedStrings = new ArrayList<>(); - - public String getFormattedValue(float value, int key) { - - boolean hasValueAtdataSetIndex = true; - if(cachedValues.size() <= key){ - int p = key; - while(p >= 0){ - if(p == 0){ - cachedValues.add(value); - cachedStrings.add(""); - }else{ - cachedValues.add(Float.NaN); - cachedStrings.add(""); - } - p--; - } - hasValueAtdataSetIndex = false; - } - - if(hasValueAtdataSetIndex) { - Float cachedValue = cachedValues.get(key); - hasValueAtdataSetIndex = !(cachedValue == null || cachedValue != value); - } - - if(!hasValueAtdataSetIndex){ - cachedValues.set(key, value); - cachedStrings.set(key, mFormat.format(value)); - } - - return cachedStrings.get(key); - } - - } - - /** - * Cache a Formatted String, derived from formatting float value in the Format passed to the constructor. - */ - public static class PrimFloat extends FormattedStringCache{ - - public PrimFloat(Format format){ - super(format); - } - - - private ArrayList<Float> cachedValues = new ArrayList<>(); - private ArrayList<String> cachedStrings = new ArrayList<>(); - - public String getFormattedValue(float value) { - - boolean alreadyHasValue = false; - int vCount = cachedValues.size(); - int sIndex = -1; - for(int i = 0 ; i < vCount ; i++){ - if(cachedValues.get(i) == value){ - sIndex = i; - alreadyHasValue = true; - break; - } - } - if(!alreadyHasValue) { - cachedValues.add(value); - cachedStrings.add(mFormat.format(value)); - sIndex = cachedValues.size() - 1; - } - - return cachedStrings.get(sIndex); - } - - } - - /** - * Cache a Formatted String, derived from formatting double value in the Format passed to the constructor. - */ - public static class PrimDouble extends FormattedStringCache{ - - public PrimDouble(Format format){ - super(format); - } - - - private ArrayList<Double> cachedValues = new ArrayList<>(); - private ArrayList<String> cachedStrings = new ArrayList<>(); - - public String getFormattedValue(double value) { - - boolean alreadyHasValue = false; - int vCount = cachedValues.size(); - int sIndex = -1; - for(int i = 0 ; i < vCount ; i++){ - if(cachedValues.get(i) == value){ - sIndex = i; - alreadyHasValue = true; - break; - } - } - if(!alreadyHasValue) { - cachedValues.add(value); - cachedStrings.add(mFormat.format(value)); - sIndex = cachedValues.size() - 1; - } - - return cachedStrings.get(sIndex); - } - - } - - - -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java index 4e6e77a6..ef8dc407 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java @@ -23,16 +23,11 @@ public class LargeValueFormatter implements ValueFormatter, AxisValueFormatter { "", "k", "m", "b", "t" }; private static final int MAX_LENGTH = 5; + private DecimalFormat mFormat; private String mText = ""; - - /** - * FormattedStringCache for formatting and caching. - */ - protected FormattedStringCache.PrimDouble mFormattedStringCache; - public LargeValueFormatter() { - mFormattedStringCache = new FormattedStringCache.PrimDouble(new DecimalFormat("###E00")); + mFormat = new DecimalFormat("###E00"); } /** @@ -82,8 +77,7 @@ public class LargeValueFormatter implements ValueFormatter, AxisValueFormatter { */ private String makePretty(double number) { - // TODO : Should be better way to do this. Double isn't the best key... - String r = mFormattedStringCache.getFormattedValue(number); + String r = mFormat.format(number); int numericValue1 = Character.getNumericValue(r.charAt(r.length() - 1)); int numericValue2 = Character.getNumericValue(r.charAt(r.length() - 2)); diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java index 1ad1ba1c..209da1fa 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java @@ -15,12 +15,10 @@ import java.text.DecimalFormat; */ public class PercentFormatter implements ValueFormatter, AxisValueFormatter { - protected FormattedStringCache.Generic<Integer, Float> mFormattedStringCache; - protected FormattedStringCache.PrimFloat mFormattedStringCacheAxis; + protected DecimalFormat mFormat; public PercentFormatter() { - mFormattedStringCache = new FormattedStringCache.Generic<>(new DecimalFormat("###,###,##0.0")); - mFormattedStringCacheAxis = new FormattedStringCache.PrimFloat(new DecimalFormat("###,###,##0.0")); + mFormat = new DecimalFormat("###,###,##0.0"); } /** @@ -29,21 +27,19 @@ public class PercentFormatter implements ValueFormatter, AxisValueFormatter { * @param format */ public PercentFormatter(DecimalFormat format) { - mFormattedStringCache = new FormattedStringCache.Generic<>(format); - mFormattedStringCacheAxis = new FormattedStringCache.PrimFloat(format); + this.mFormat = format; } // ValueFormatter @Override public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { - return mFormattedStringCache.getFormattedValue(value, dataSetIndex) + " %"; + return mFormat.format(value) + " %"; } // AxisValueFormatter @Override public String getFormattedValue(float value, AxisBase axis) { - // TODO: Find a better way to do this. Float isn't the best key... - return mFormattedStringCacheAxis.getFormattedValue(value) + " %"; + return mFormat.format(value) + " %"; } @Override diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java index bc020d56..b13dd8d9 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java @@ -18,8 +18,6 @@ public class StackedValueFormatter implements ValueFormatter { * if true, all stack values of the stacked bar entry are drawn, else only top */ private boolean mDrawWholeStack; - private FormattedStringCache.Generic mFormattedStringCacheWholeStack; - private FormattedStringCache.Generic mFormattedStringCache; /** * a string that should be appended behind the value @@ -46,17 +44,12 @@ public class StackedValueFormatter implements ValueFormatter { b.append("0"); } - this.mFormattedStringCache = new FormattedStringCache.Generic(new DecimalFormat("###,###,###,##0" + b.toString())); - this.mFormattedStringCacheWholeStack = new FormattedStringCache.Generic(new DecimalFormat("###,###,###,##0" + b.toString())); + this.mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); } @Override public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { - FormattedStringCache.Generic chosenCache = mFormattedStringCache; - int chosenIndex = dataSetIndex; - float chosenValue = value; - if (!mDrawWholeStack && entry instanceof BarEntry) { BarEntry barEntry = (BarEntry) entry; @@ -66,19 +59,16 @@ public class StackedValueFormatter implements ValueFormatter { // find out if we are on top of the stack if (vals[vals.length - 1] == value) { - chosenCache = mFormattedStringCacheWholeStack; - chosenValue = barEntry.getY(); + + // return the "sum" across all stack values + return mFormat.format(barEntry.getY()) + mAppendix; } else { - chosenCache = null; + return ""; // return empty } } } - if(chosenCache == null){ - return ""; - } - // return the "proposed" value - return chosenCache.getFormattedValue(chosenValue, chosenIndex) + mAppendix; + return mFormat.format(value) + mAppendix; } } diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/FormattedStringCacheTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/FormattedStringCacheTest.java deleted file mode 100644 index bd33008e..00000000 --- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/FormattedStringCacheTest.java +++ /dev/null @@ -1,433 +0,0 @@ -package com.github.mikephil.charting.test; - -import com.github.mikephil.charting.formatter.FormattedStringCache; - -import junit.framework.Assert; - -import org.junit.Test; - -import java.text.DecimalFormat; - -/** - * Created by Tony Patino on 6/30/16. - */ -public class FormattedStringCacheTest { - - @Test - public void testPrimFloat(){ - int digits = 2; - - StringBuffer b = new StringBuffer(); - for (int i = 0; i < digits; i++) { - if (i == 0) - b.append("."); - b.append("0"); - } - - FormattedStringCache.PrimFloat cache = new FormattedStringCache.PrimFloat(new DecimalFormat("###,###,###,##0" + b.toString())); - - String s = null; - - s = cache.getFormattedValue(1.0f); - - Assert.assertEquals("1.00", s); - - s = cache.getFormattedValue(1.0f); - - Assert.assertEquals("1.00", s); - - - s = cache.getFormattedValue(1.3f); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3f); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.0f); - - Assert.assertEquals("1.00", s); - - for(int i = 0 ; i < 100 ; i++){ - float f = 0.75f + i; - s = cache.getFormattedValue(f); - Assert.assertEquals(i+".75", s); - } - - - s = cache.getFormattedValue(1.5323234f); - Assert.assertEquals("1.53", s); - - - s = cache.getFormattedValue(1.31f); - Assert.assertEquals("1.31", s); - - s = cache.getFormattedValue(1.3111111f); - Assert.assertEquals("1.31", s); - - } - - @Test - public void testPrimDouble(){ - int digits = 2; - - StringBuffer b = new StringBuffer(); - for (int i = 0; i < digits; i++) { - if (i == 0) - b.append("."); - b.append("0"); - } - - FormattedStringCache.PrimDouble cache = new FormattedStringCache.PrimDouble(new DecimalFormat("###,###,###,##0" + b.toString())); - - String s = null; - - s = cache.getFormattedValue(1.0d); - - Assert.assertEquals("1.00", s); - - s = cache.getFormattedValue(1.0d); - - Assert.assertEquals("1.00", s); - - - s = cache.getFormattedValue(1.3d); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3d); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.0d); - - Assert.assertEquals("1.00", s); - - for(int i = 0 ; i < 100 ; i++){ - double f = 0.75f + i; - s = cache.getFormattedValue(f); - Assert.assertEquals(i+".75", s); - } - - - s = cache.getFormattedValue(1.5323234d); - Assert.assertEquals("1.53", s); - - - s = cache.getFormattedValue(1.31d); - Assert.assertEquals("1.31", s); - - s = cache.getFormattedValue(1.3111111d); - Assert.assertEquals("1.31", s); - - } - - @Test - public void testPrimIntFloat(){ - - int digits = 2; - - StringBuffer b = new StringBuffer(); - for (int i = 0; i < digits; i++) { - if (i == 0) - b.append("."); - b.append("0"); - } - - FormattedStringCache.PrimIntFloat cache = new FormattedStringCache.PrimIntFloat(new DecimalFormat("###,###,###,##0" + b.toString())); - - String s = null; - - s = cache.getFormattedValue(1.0f, 0); - - Assert.assertEquals("1.00", s); - - s = cache.getFormattedValue(1.0f, 0); - - Assert.assertEquals("1.00", s); - - - s = cache.getFormattedValue(1.3f ,1); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3f, 1); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3f, 0); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.0f, 1); - - Assert.assertEquals("1.00", s); - - for(int i = 0 ; i < 100 ; i++){ - float f = 0.75f + i; - s = cache.getFormattedValue(f, i); - Assert.assertEquals(i+".75", s); - } - - - s = cache.getFormattedValue(1.5323234f, 200); - Assert.assertEquals("1.53", s); - - - s = cache.getFormattedValue(1.31f, 300); - Assert.assertEquals("1.31", s); - - s = cache.getFormattedValue(1.3111111f, 300); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 400); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 500); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 5000); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.31f, 0); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.31f, 1); - Assert.assertEquals("1.31", s); - } - - @Test - public void testGenericKV(){ - - this.genericIntFloat(); - this.genericDoubleFloat(); - this.genericObjectFloat(); - } - - private void genericObjectFloat() { - - - int digits = 2; - - StringBuffer b = new StringBuffer(); - for (int i = 0; i < digits; i++) { - if (i == 0) - b.append("."); - b.append("0"); - } - - FormattedStringCache.Generic<Object, Float> cache = new FormattedStringCache.Generic<>(new DecimalFormat("###,###,###,##0" + b.toString())); - - String s = null; - - - Object obj0 = new Object(); - Object obj1 = new Object(); - Object obj2 = new Object(); - - s = cache.getFormattedValue(10f, obj0); - - Assert.assertEquals("10.00", s); - - - s = cache.getFormattedValue(10f, obj0); - - Assert.assertEquals("10.00", s); - - - s = cache.getFormattedValue(11f, obj1); - - Assert.assertEquals("11.00", s); - - s = cache.getFormattedValue(10f, obj2); - - Assert.assertEquals("10.00", s); - - - s = cache.getFormattedValue(11f, obj0); - - Assert.assertEquals("11.00", s); - - - } - - private void genericDoubleFloat() { - - - - int digits = 2; - - StringBuffer b = new StringBuffer(); - for (int i = 0; i < digits; i++) { - if (i == 0) - b.append("."); - b.append("0"); - } - - FormattedStringCache.Generic<Double, Float> cache = new FormattedStringCache.Generic<>(new DecimalFormat("###,###,###,##0" + b.toString())); - - String s = null; - - s = cache.getFormattedValue(1.0f, 0d); - - Assert.assertEquals("1.00", s); - - s = cache.getFormattedValue(1.0f, 0d); - - Assert.assertEquals("1.00", s); - - - s = cache.getFormattedValue(1.3f ,1d); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3f, 1d); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3f, 0d); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.0f, 1d); - - Assert.assertEquals("1.00", s); - - for(int i = 0 ; i < 100 ; i++){ - float f = 0.75f + i; - s = cache.getFormattedValue(f, (double)i); - Assert.assertEquals(i+".75", s); - } - - - s = cache.getFormattedValue(1.5323234f, 200d); - Assert.assertEquals("1.53", s); - - - s = cache.getFormattedValue(1.31f, 300d); - Assert.assertEquals("1.31", s); - - s = cache.getFormattedValue(1.3111111f, 300d); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 400d); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 500d); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 5000d); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.31f, 0d); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.31f, 1d); - Assert.assertEquals("1.31", s); - - } - - private void genericIntFloat() { - - - int digits = 2; - - StringBuffer b = new StringBuffer(); - for (int i = 0; i < digits; i++) { - if (i == 0) - b.append("."); - b.append("0"); - } - - FormattedStringCache.Generic<Integer, Float> cache = new FormattedStringCache.Generic<>(new DecimalFormat("###,###,###,##0" + b.toString())); - - String s = null; - - s = cache.getFormattedValue(1.0f, 0); - - Assert.assertEquals("1.00", s); - - s = cache.getFormattedValue(1.0f, 0); - - Assert.assertEquals("1.00", s); - - - s = cache.getFormattedValue(1.3f ,1); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3f, 1); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.3f, 0); - - Assert.assertEquals("1.30", s); - - - s = cache.getFormattedValue(1.0f, 1); - - Assert.assertEquals("1.00", s); - - for(int i = 0 ; i < 100 ; i++){ - float f = 0.75f + i; - s = cache.getFormattedValue(f, i); - Assert.assertEquals(i+".75", s); - } - - - s = cache.getFormattedValue(1.5323234f, 200); - Assert.assertEquals("1.53", s); - - - s = cache.getFormattedValue(1.31f, 300); - Assert.assertEquals("1.31", s); - - s = cache.getFormattedValue(1.3111111f, 300); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 400); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 500); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.3111111f, 5000); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.31f, 0); - Assert.assertEquals("1.31", s); - - - s = cache.getFormattedValue(1.31f, 1); - Assert.assertEquals("1.31", s); - } - -} |