Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.HashMap; public class Main { public static long asLong(Object node, String key) { return asLong(node, key, 0); } public static long asLong(Object node, String key, long def) { Object value; if ((node instanceof HashMap<?, ?>) && ((value = ((HashMap<?, ?>) node).get(key)) != null)) { if (value instanceof Number) { return ((Number) value).longValue(); } else { try { return Long.valueOf(value.toString()); } catch (NumberFormatException ex) { return def; } } } else { return def; } } }