Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Map;

public class Main {
    /**
     * Returns the value for key in dictionary as an int or 0 if no value is
     * defined for the key.
     * 
     * @param dict
     *            Dictionary that contains the key, value pairs.
     * @param key
     *            Key whose value should be returned.
     * @return Returns the integer value for key in dict.
     */
    public static int getInt(Map<String, Object> dict, String key) {
        return getInt(dict, key, 0);
    }

    /**
     * Returns the value for key in dictionary as an int or the given default
     * value if no value is defined for the key.
     * 
     * @param dict
     *            Dictionary that contains the key, value pairs.
     * @param key
     *            Key whose value should be returned.
     * @param defaultValue
     *            Default value to return if the key is undefined.
     * @return Returns the integer value for key in dict.
     */
    public static int getInt(Map<String, Object> dict, String key, int defaultValue) {
        Object value = dict.get(key);

        if (value == null) {
            return defaultValue;
        } else {
            // Handles commas by casting them to an int
            return (int) Float.parseFloat(value.toString());
        }
    }
}