Here you can find the source of getFloat(String key, Float def)
Parameter | Description |
---|---|
key | a parameter |
def | a parameter |
key
, or default
if not found in the preferences chain.
public static Float getFloat(String key, Float def)
//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; } }