This is an automated email from the ASF dual-hosted git repository. mawiesne pushed a commit to branch OPENNLP-1668-Avoid-multiple-DecimalFormat-instances-in-AbstractModel in repository https://gitbox.apache.org/repos/asf/opennlp.git
commit d3a1ec9bf8d318f36fa735dd09a715f24232868e Author: Martin Wiesner <[email protected]> AuthorDate: Fri Dec 13 08:40:49 2024 +0100 OPENNLP-1668 Avoid multiple DecimalFormat instances in AbstractModel --- .../src/main/java/opennlp/tools/ml/model/AbstractModel.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java index 9d434e51..b3f26c46 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java @@ -30,6 +30,8 @@ import opennlp.tools.ml.ArrayMath; */ public abstract class AbstractModel implements MaxentModel { + private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.0000"); + /** Mapping between predicates/contexts and an integer representing them. */ protected Map<String, Context> pmap; /** The names of the outcomes. */ @@ -119,11 +121,10 @@ public abstract class AbstractModel implements MaxentModel { "must not have been produced by this model."; } else { - DecimalFormat df = new DecimalFormat("0.0000"); StringBuilder sb = new StringBuilder(ocs.length * 2); - sb.append(outcomeNames[0]).append("[").append(df.format(ocs[0])).append("]"); + sb.append(outcomeNames[0]).append("[").append(DECIMAL_FORMAT.format(ocs[0])).append("]"); for (int i = 1; i < ocs.length; i++) { - sb.append(" ").append(outcomeNames[i]).append("[").append(df.format(ocs[i])).append("]"); + sb.append(" ").append(outcomeNames[i]).append("[").append(DECIMAL_FORMAT.format(ocs[i])).append("]"); } return sb.toString(); }
