From 233d1dac0b3fd8835abf4fcddde8f126762c5188 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 27 Sep 2011 19:29:05 +0200 Subject: [PATCH] Simplify length extraction. --- .../java/net/pterodactylus/sone/template/ParserFilter.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 42e4035..c5f7f6b 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -87,19 +87,7 @@ public class ParserFilter implements Filter { @Override public Object format(TemplateContext templateContext, Object data, Map parameters) { String text = String.valueOf(data); - int length = -1; - try { - length = Integer.parseInt(parameters.get("length")); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - if ((length == -1) && (parameters.get("length") != null)) { - try { - length = Integer.parseInt(String.valueOf(templateContext.get(parameters.get("length")))); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - } + int length = Numbers.safeParseInteger(parameters.get("length"), Numbers.safeParseInteger(templateContext.get(parameters.get("length")), -1)); String soneKey = parameters.get("sone"); if (soneKey == null) { soneKey = "sone"; -- 2.7.4