Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

public class Main {
    public static int asInt(Object node, String key) {
        return asInt(node, key, 0);
    }

    public static int asInt(Object node, String key, int def) {
        Object value;

        if ((node instanceof HashMap<?, ?>) && ((value = ((HashMap<?, ?>) node).get(key)) != null)) {
            if (value instanceof Number) {
                return ((Number) value).intValue();
            } else {
                try {
                    return Integer.valueOf(value.toString());
                } catch (NumberFormatException ex) {
                    return def;
                }
            }
        } else {
            return def;
        }
    }
}