All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.media.util.Registry Maven / Gradle / Ivy

There is a newer version: 1.0.2-jitsi
Show newest version
package com.sun.media.util;

import java.io.*;
import java.util.*;

/**
 *
 * @author Lyubomir Marinov
 */
public class Registry
{
    private static final Map hash
        = new HashMap();

    public static boolean commit() throws IOException
    {
        // TODO Auto-generated method stub
        return false;
    }

    public static Object get(String key)
    {
        return (key == null) ? null : hash.get(key);
    }

    /**
     * Gets a boolean representation of the value associated with a
     * specific key if such an association exists and it is possible to parse
     * the value as a boolean; otherwise, returns a specific default
     * value.
     *
     * @param key the key whose associated value is to be returned in the form
     * of a boolean
     * @param defaultValue a boolean value to be returned if no value
     * is associated with the specified key
     * @return a boolean representation of the value associated with
     * the specified key if such an association exists and it is
     * possible to parse the value as a boolean; otherwise,
     * defaultValue
     */
    public static boolean getBoolean(String key, boolean defaultValue)
    {
        Object value = get(key);

        return
            (value == null)
                ? defaultValue
                : Boolean.parseBoolean(value.toString());
    }

    /**
     * Gets an int representation of the value associated with a
     * specific key if such an association exists and it is possible to parse
     * the value as an int; otherwise, returns a specific default
     * value.
     *
     * @param key the key whose associated value is to be returned in the form
     * of an int
     * @param defaultValue an int value to be returned if no value is
     * associated with the specified key
     * @return an int representation of the value associated with the
     * specified key if such an association exists and it is possible
     * to parse the value as an int; otherwise, defaultValue
     */
    public static int getInt(String key, int defaultValue)
    {
        Object value = get(key);

        if (value != null)
        {
            try
            {
                return Integer.parseInt(value.toString());
            }
            catch (NumberFormatException nfe)
            {
                // defaultValue
            }
        }
        return defaultValue;
    }

    public static boolean set(String key, Object value)
    {
        if ((key != null) && (value != null))
        {
            hash.put(key, value);
            return true;
        }
        else
            return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy