Java Preference Get getFloat(String key, Float def)

Here you can find the source of getFloat(String key, Float def)

Description

Get the value of the specified Float preference.

License

Open Source License

Parameter

Parameter Description
key a parameter
def a parameter

Return

the value of the specified key, or default if not found in the preferences chain.

Declaration

public static Float getFloat(String key, Float def) 

Method Source Code

//package com.java2s;
/*//from w  ww  .  j ava 2s . c  o m
 * Phon - An open source tool for research in phonology.
 * Copyright (C) 2005 - 2015, Gregory Hedlund <ghedlund@mun.ca> and Yvan Rose <yrose@mun.ca>
 * Dept of Linguistics, Memorial University <https://phon.ca>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.prefs.Preferences;

public class Main {
    /**
     * Application prefs root node
     */
    public final static String PREF_ROOT = "/ca/phon/util";

    /**
     * Get the value of the specified {@link Float} preference. If found
     * using {@link System#getProperty(String, String)}, the value is
     * decoded using {@link Float#parseFloat(String)}.
     * 
     * @param key
     * @param def
     * @return the value of the specified <code>key</code>, or
     *  <code>default</code> if not found in the preferences
     *  chain.
     */
    public static Float getFloat(String key, Float def) {
        String propVal = System.getProperty(key);
        Float retVal = null;
        if (propVal != null) {
            try {
                retVal = Float.parseFloat(propVal);
            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
            }
        }
        if (retVal == null) {
            // continue to search in preferences chain
            retVal = getUserPreferences().getFloat(key, def);
        }
        return retVal;
    }

    /**
     * Returns the root user preferences node.
     * 
     * @return  a {@link Preferences} instance
     */
    public static Preferences getUserPreferences() {
        Preferences retVal = Preferences.userRoot().node(PREF_ROOT);
        return retVal;
    }
}

Related

  1. getAltNode(final String name)
  2. getBoolean(final String key, final boolean defaultValue)
  3. getCLOB(Preferences prefs, String key, String def)
  4. getClobStorage(Preferences prefs, String key)
  5. getDefault()
  6. getInt(final Class preferencesClass, final String preferenceName)
  7. getList(String path)
  8. getNode(String path)
  9. getPreference(String key, Boolean defaultValue)