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 a float array 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 float array value for key in dict.
     */
    public static float[] getFloatArray(Map<String, Object> dict, String key, float[] defaultValue) {
        return getFloatArray(dict, key, defaultValue, ",");
    }

    /**
     * Returns the value for key in dictionary as a float array 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 float array value for key in dict.
     */
    public static float[] getFloatArray(Map<String, Object> dict, String key, float[] defaultValue,
            String separator) {
        Object value = dict.get(key);

        if (value == null) {
            return defaultValue;
        } else {
            String[] floatChars = value.toString().split(separator);
            float[] result = new float[floatChars.length];

            for (int i = 0; i < floatChars.length; i++) {
                result[i] = Float.parseFloat(floatChars[i]);
            }

            return result;
        }
    }
}