Java 8 Preferences - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Preferences class.

This code example shows how to use the following methods:get, put
        set("autoShow", value);
    } 
 
 
    private void set(String name, String value) {
        String old = applicationPreferences.get(name, "");
        applicationPreferences.put(name, value);
        savePreferences(); 
        propSupport.firePropertyChange(name, old, value);
    } 
 
    private void set(String name, int value) {
        int old = applicationPreferences.getInt(name, 0);
        applicationPreferences.putInt(name, value);
        savePreferences(); 
        propSupport.firePropertyChange(name, old, value);
    } 
 
    private void set(String name, boolean value) {
        boolean old = applicationPreferences.getBoolean(name, false);
6
CodeRank
This code example shows how to use the following methods:getBoolean, getInt, putDouble
      assert false; 
    } 
    PreferencesExt prefs = store.getPreferences();
 
    Preferences node = prefs.node("/myApp");
    int ival  = node.getInt("extraOne", 0);
    assert ival == 1 : "testStandardChain fail 1 " + ival;
 
    ival  = node.getInt("extraTwo", 0);
    assert ival == 2 : "testStandardChain fail 2 " + ival;
 
    ival  = node.getInt("num_rows", 0);
    assert ival == 128 : "testStandardChain fail 3 " + ival;
 
    ival  = node.getInt("missing", 0);
    assert ival == 0 : "testStandardChain fail 4 " + ival;
 
    boolean bval  = node.getBoolean("TestBoolean", false);
    assert bval: "testStandardChain fail 5 " + bval;
 

6
CodeRank
This code example shows how to use the following methods:getInt
     * 
     * @param prefs object representing persistent Preferences. 
     */ 
    public void restoreFrom(Preferences prefs)
    { 
        setTopActivity(prefs.getInt(KEY_TOP_ACTIVITY, DEFAULT_TOP_ACTIVITY));
        setTopHighlights(prefs.getInt(KEY_TOP_HIGHLIGHTS, DEFAULT_TOP_HIGHLIGHTS));
 
        setActivityWeight(prefs.getInt(KEY_ACTIVITY_WEIGHT, DEFAULT_ACTIVITY_WEIGHT));
        setInlinksWeight(prefs.getInt(KEY_INLINKS_WEIGHT, DEFAULT_INLINKS_WEIGHT));
        setClickthroughsWeight(prefs.getInt(KEY_CLICKTHROUGHS_WEIGHT, DEFAULT_CLICKTHROUGHS_WEIGHT));
        setFeedViewsWeight(prefs.getInt(KEY_FEED_VIEWS_WEIGHT, DEFAULT_FEED_VIEWS_WEIGHT));
    } 
 
    /** 
     * Write all the preferences from this Object to persistent preferences. On Windows, this is the 
     * registry. 
     * 
     * @param prefs object representing persistent Preferences. 
     */ 
6
CodeRank
This code example shows how to use the following methods:put, putBoolean, putByteArray, putDouble, putFloat
      barr[1] = 2;
      barr[2] = 3;
      prefs.putByteArray("testBA", barr);
 
      Preferences subnode = prefs.node("SemperUbi");
      subnode.putDouble("testD", 3.14158);
      subnode.putFloat("testF", 1.23457F);
      subnode.putLong("testL", 12345678901L);
      subnode.putInt("testI", 123456780);
      subnode.put("testS", "youdBeLivebyNow");
      subnode.putBoolean("testB", false);
 
      byte[] barr2 = new byte[3];
      barr2[0] = 2;
      barr2[1] = 3;
      barr2[2] = 4;
      subnode.putByteArray("testBA", barr2);
 
      store.save();
    } catch (Exception e) {

6
CodeRank
This code example shows how to use the following methods:getBoolean, getInt, getLong, putBoolean, sync
     * flag. 
     * @return Returns <code>true</code> only if an update is available. 
     */ 
    private static boolean isUpdateAvailable( boolean reset ) {
        try { 
            if ( m_prefs.getBoolean( IS_UPDATE_AVAILABLE_KEY, false ) ) {
                if ( reset ) {
                    m_prefs.putBoolean( IS_UPDATE_AVAILABLE_KEY, false );
                    syncPrefs(); 
                } 
                return true; 
            } 
        } 
        catch ( IllegalStateException e ) {
            // ignore? 
        } 
        return false; 
    } 
 
    /** 

6
CodeRank
This code example shows how to use the following methods:flush
            changed = true;
        } 
        if (changed) {
            JOptionPane.showMessageDialog(this, "Please restart NodeBox for the changes to take effect.");
            try { 
                preferences.flush();
            } catch (BackingStoreException e) {
                throw new RuntimeException(e);
            } 
        } 
        dispose(); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getDouble
    private final static String EllipticYTag = "SpotY";
    private final static String EllipticCloneXTag = "SpotCloneX";
    private final static String EllipticCloneYTag = "SpotCloneY";
 
    // Default width for new EllipticCurves. 
    private static double EllipticX = Prefs.getDouble(EllipticXTag, 30);
    // Default height for new EllipticCurves. 
    private static double EllipticY = Prefs.getDouble(EllipticYTag, 30);
 
    // Default clone point offsets for new EllipticCurves. 
    private static double EllipticCloneX =
        Prefs.getDouble(EllipticCloneXTag, EllipticX);
    private static double EllipticCloneY =
        Prefs.getDouble(EllipticCloneYTag, 0);
 
    // If the width is directly manipulated (user interaction, restore), then 
    // stop updating it automatically when control points change. 
    private boolean isManualWidthSet;
 
    public EllipticCurve() { 
6
CodeRank
This code example shows how to use the following methods:get
	public static void put(String key, String value) {
		pref.put(key, value);
	} 
	 
	public static String getDatabaseURL() {
		return pref.get(DATABASE_URL, "localhost");
	} 
 
	public static String getConnectionURL() {
		return "jdbc:derby://" + getDatabaseURL() + ":" + getDatabasePort() + "/" + getDatabaseName();  
	} 
	 
	public static void setDatabaseURL(String url) {
		pref.put(DATABASE_URL, url);
	} 
	 
	public static String getDatabasePort() {
		return pref.get(DATABASE_PORT, "1527");
	} 
	 

6
CodeRank
This code example shows how to use the following methods:get, remove
            System.err.println(e.getMessage());
        } 
    } 
 
    public void restoreFromPrefs(String context) {
        name = Prefs.get(NewFileNameKey + context, "");
 
        String path = Prefs.get(DirectoryKey + context, null);
        if (path != null) {
            directory = new File(path);
        } 
        else { 
            directory = null;
        } 
        String text = Prefs.get(ExportKey + context, null);
        if (text != null) {
            try { 
                InputStream in = new ByteArrayInputStream(
                    text.getBytes("UTF-8")
                ); 

6
CodeRank
This code example shows how to use the following methods:get, getBoolean
     * 
     * @param prefs map. 
     */ 
    public void restore(Preferences prefs)
    { 
        setEnabled(prefs.getBoolean(PROP_TWITTER_ENABLED, false));
        setScreenName(prefs.get(PROP_TWITTER_SCREEN_NAME, null));
        setAccessToken(prefs.get(PROP_TWITTER_ACCESS_TOKEN, null));
        setTokenSecret(prefs.get(PROP_TWITTER_TOKEN_SECRET, null));
        setProfilePics(prefs.getBoolean(PROP_PROFILE_PICS, true));
        setPasteLink(prefs.getBoolean(PROP_PASTE_LINK, true));
    } 
 
    /** 
     * Resets actions that depend on URLs after the preferences change. 
     */ 
    private static void resetURLDependentActions() 
    { 
        FollowAction.getInstance().setUserURL(null); 
        ReplyAction.getInstance().setUserURL(null); 
6
CodeRank

Related Java 8 Preferences Questions & Answers:

See Code Examples for Java 8 Preferences Methods: