From 3d09fdee27b8548e2aad06cf3ab7f7a09f263073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Vl=C4=8Dek?= Date: Tue, 6 Sep 2011 16:23:54 +0200 Subject: [PATCH] adding method allowing default value --- .../xcontent/support/XContentMapValues.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java index 24877b2fc7a..9a03ce04244 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java @@ -42,6 +42,13 @@ public class XContentMapValues { return node.toString(); } + public static float nodeFloatValue(Object node, float defaultValue) { + if (node == null) { + return defaultValue; + } + return nodeFloatValue(node); + } + public static float nodeFloatValue(Object node) { if (node instanceof Number) { return ((Number) node).floatValue(); @@ -49,6 +56,13 @@ public class XContentMapValues { return Float.parseFloat(node.toString()); } + public static double nodeDoubleValue(Object node, double defaultValue) { + if (node == null) { + return defaultValue; + } + return nodeDoubleValue(node); + } + public static double nodeDoubleValue(Object node) { if (node instanceof Number) { return ((Number) node).doubleValue(); @@ -73,6 +87,13 @@ public class XContentMapValues { return Integer.parseInt(node.toString()); } + public static short nodeShortValue(Object node, short defaultValue) { + if (node == null) { + return defaultValue; + } + return nodeShortValue(node); + } + public static short nodeShortValue(Object node) { if (node instanceof Number) { return ((Number) node).shortValue(); @@ -80,6 +101,13 @@ public class XContentMapValues { return Short.parseShort(node.toString()); } + public static byte nodeByteValue(Object node, byte defaultValue) { + if (node == null) { + return defaultValue; + } + return nodeByteValue(node); + } + public static byte nodeByteValue(Object node) { if (node instanceof Number) { return ((Number) node).byteValue(); @@ -87,6 +115,13 @@ public class XContentMapValues { return Byte.parseByte(node.toString()); } + public static long nodeLongValue(Object node, long defaultValue) { + if (node == null) { + return defaultValue; + } + return nodeLongValue(node); + } + public static long nodeLongValue(Object node) { if (node instanceof Number) { return ((Number) node).longValue(); @@ -94,9 +129,9 @@ public class XContentMapValues { return Long.parseLong(node.toString()); } - public static boolean nodeBooleanValue(Object node, boolean defaulValue) { + public static boolean nodeBooleanValue(Object node, boolean defaultValue) { if (node == null) { - return defaulValue; + return defaultValue; } return nodeBooleanValue(node); }