From 83249a1e50b8ea706fde5e3074856fbf5f9eb1ac Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 26 Sep 2019 16:02:39 +0300 Subject: [PATCH] Make ValueFormat.toFormat safe to call with any noOfDecimals value noOfDecimals is now capped between [0,16]. gitlab #391 Change-Id: Id24752a908b65c261f02964ec18cdb8e759ea0d0 --- .../src/org/simantics/utils/format/ValueFormat.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java b/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java index 9734d3c56..1cc1c94a7 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java @@ -35,10 +35,10 @@ public enum ValueFormat { public Format toFormat( int noOfDecimals ) { switch ( this ) { - case Currency: return noOfDecimals>decimalFormats.length||noOfDecimals<0 ? decimalFormats[decimalFormats.length-1] : decimalFormats[noOfDecimals]; + case Currency: return noOfDecimals>decimalFormats.length||noOfDecimals<0 ? decimalFormats[decimalFormats.length-1] : decimalFormats[Math.min(noOfDecimals, 16)]; case Scientific: return format; case Engineering: return format; - case Default: return noOfDecimals>defaultFormats.length||noOfDecimals<0 ? defaultFormats[defaultFormats.length-1] : defaultFormats[noOfDecimals]; + case Default: return noOfDecimals>defaultFormats.length||noOfDecimals<0 ? defaultFormats[defaultFormats.length-1] : defaultFormats[Math.min(noOfDecimals, 16)]; default: return format; } } -- 2.47.1