Java 8 AbstractPreferences - 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 AbstractPreferences class.

This code example shows how to use the following methods:addPreferenceChangeListener, node, putInt, removePreferenceChangeListener
 
    public void testGetKey() { 
        AbstractPreferences parent = (AbstractPreferences) Preferences
                .userNodeForPackage(Preferences.class);
 
        AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
 
        MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {
            public void preferenceChange(PreferenceChangeEvent pce) {
                if (pce != null && pce.getKey().equals("key_int")) {
                    result = true;
                } 
                super.preferenceChange(pce);
            } 
        }; 
        pref.addPreferenceChangeListener(pl);
        try { 
            pref.putInt("key_int", Integer.MAX_VALUE);
            assertEquals(1, pl.getChanged());
            assertTrue(pl.getResult());

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addNodeChangeListener, node, removeNodeChangeListener
 
    public void testGetChild() throws BackingStoreException { 
        AbstractPreferences parent = (AbstractPreferences) Preferences
                .userNodeForPackage(Preferences.class);
 
        AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
 
        MockNodeChangeListener nl = new MockNodeChangeListener() {
            public synchronized void childAdded(NodeChangeEvent e) {
                Preferences child = e.getChild();
                if (child == null) {
                    addResult = false;
                } else { 
                    if (child.name() == "mock1") {
                        addResult = true;
                    } 
                } 
                super.childAdded(e);
            } 
 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addNodeChangeListener, node, removeNodeChangeListener
 
    public void testGetChild() throws BackingStoreException { 
        AbstractPreferences parent = (AbstractPreferences) Preferences
                .userNodeForPackage(Preferences.class);
 
        AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
 
        MockNodeChangeListener nl = new MockNodeChangeListener() {
            public synchronized void childAdded(NodeChangeEvent e) {
                Preferences child = e.getChild();
                if (child == null) {
                    addResult = false;
                } else { 
                    if (child.name() == "mock1") {
                        addResult = true;
                    } 
                } 
                super.childAdded(e);
            } 
 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addPreferenceChangeListener, getInt, node, putInt
        } 
    } 
 
    public void testAddPreferenceChangeListener() throws Exception { 
        MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
        parent.addPreferenceChangeListener(mpcl);
        mpcl.assertChanged(false);
        pref.node("new node");
        mpcl.assertChanged(false);
        parent.node("new node");
        mpcl.assertChanged(false);
        parent.putInt("IntValue", 33);
        mpcl.assertChanged(true);
        assertEquals(33, parent.getInt("IntValue", 22));
        mpcl.assertChanged(false);
        assertEquals(22, parent.getInt("Missed Value", 22));
        mpcl.assertChanged(false);
    } 
 
    public void testRemovePreferenceChangeListener() throws Exception { 
        MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 AbstractPreferences Methods: