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); }