当前位置: 首页>>代码示例>>Java>>正文


Java Preferences.sync方法代码示例

本文整理汇总了Java中java.util.prefs.Preferences.sync方法的典型用法代码示例。如果您正苦于以下问题:Java Preferences.sync方法的具体用法?Java Preferences.sync怎么用?Java Preferences.sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.prefs.Preferences的用法示例。


在下文中一共展示了Preferences.sync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWriting

import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testWriting() throws Exception {
    {
    Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    assertEquals("Wrong value for 'simple-value-setting-A'", "value-A", prefs.get("simple-value-setting-A", null));
    
    prefs.put("simple-value-setting-A", "New-Written-Value");
    assertEquals("Wrong value for 'simple-value-setting-A'", "New-Written-Value", prefs.get("simple-value-setting-A", null));

    prefs.sync();
    }

    {
    // read the settings right from the file
    StorageImpl<String, TypedValue> storage = new StorageImpl<String, TypedValue>(new PreferencesStorage(), null);
    Map<String, TypedValue> map = storage.load(MimePath.EMPTY, null, false);
    assertEquals("Wrong value for 'simple-value-setting-A'", "New-Written-Value", map.get("simple-value-setting-A").getValue());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:PreferencesTest.java

示例2: testNotPersistentPreferences

import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testNotPersistentPreferences() throws Exception {
    Preferences pref = Preferences.userNodeForPackage(getClass());
    assertNotNull(pref);
    pref.put(getName(), "value");
    assertEquals("value", pref.get(getName(), null));
    pref.sync();
    assertEquals(null, pref.get(getName(), null));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:NbTestCasePreferencesTest.java

示例3: serialize

import java.util.prefs.Preferences; //导入方法依赖的package包/类
static void serialize() {
    try {
        Preferences p = NbPreferences.forModule(SimpleFileOwnerQueryImplementation.class).node("externalOwners");
        for (URI uri : externalOwners.keySet()) {
            URI ownerURI = externalOwners.get(uri);
            if (ownerURI != UNOWNED_URI) {
            p.put(uri.toString(), ownerURI.toString());
        }
        }
        p.sync(); // #184310
    } catch (Exception ex) {
        LOG.log(Level.WARNING, null, ex);
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:SimpleFileOwnerQueryImplementation.java

示例4: testSimpleSync

import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testSimpleSync() throws BackingStoreException {
    Preferences orig = Preferences.userRoot().node(getName());
    assertNull("Original contains value", orig.get("key-1", null));

    Preferences test = ProxyPreferencesImpl.getProxyPreferences(this, orig);
    assertNull("Test should not contains pair", orig.get("key-1", null));

    test.put("key-1", "xyz");
    assertEquals("Test doesn't contain new pair", "xyz", test.get("key-1", null));

    test.sync();
    assertNull("Test didn't rollback pair", test.get("key-1", null));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ProxyPreferencesImplTest.java

示例5: testSyncTree1

import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testSyncTree1() throws BackingStoreException {
    String [] origTree = new String [] {
        "CodeStyle/profile=GLOBAL",
    };
    String [] newTree = new String [] {
        "CodeStyle/text/x-java/tab-size=2",
        "CodeStyle/text/x-java/override-global-settings=true",
        "CodeStyle/text/x-java/expand-tabs=true",
        "CodeStyle/profile=PROJECT",
    };

    Preferences orig = Preferences.userRoot().node(getName());
    write(orig, origTree);
    checkContains(orig, origTree, "Orig");
    checkNotContains(orig, newTree, "Orig");
    
    Preferences test = ProxyPreferencesImpl.getProxyPreferences(this, orig);
    checkEquals("Test should be the same as Orig", orig, test);
    
    write(test, newTree);
    checkContains(test, newTree, "Test");

    test.sync();
    checkContains(orig, origTree, "Orig");
    checkNotContains(orig, newTree, "Orig");
    checkContains(test, origTree, "Test");
    checkNotContains(test, newTree, "Test");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ProxyPreferencesImplTest.java

示例6: checkPreferencesAction

import java.util.prefs.Preferences; //导入方法依赖的package包/类
private void checkPreferencesAction(Action a, Preferences prefsNode) throws Exception {
    prefsNode.putBoolean("myKey", true);
    prefsNode.sync();
    class L implements PreferenceChangeListener {
        boolean notified;

        public synchronized void preferenceChange(PreferenceChangeEvent evt) {
            notified = true;
            notifyAll();
        }

        public synchronized void waitFor() throws Exception {
            while (!notified) {
                wait();
            }
            notified = false;
        }
    }
    L listener = new L();

    // Verify value
    assertTrue("Expected true as preference value", prefsNode.getBoolean("myKey", false));

    TestCase.assertTrue("Expected to be instance of Presenter.Menu", a instanceof Presenter.Menu);
    JMenuItem item = ((Presenter.Menu) a).getMenuPresenter();
    TestCase.assertTrue("Expected to be selected", item.isSelected());
    prefsNode.addPreferenceChangeListener(listener);
    prefsNode.putBoolean("myKey", false);
    prefsNode.sync();
    listener.waitFor();
    TestCase.assertFalse("Expected to not be selected", item.isSelected());
    a.actionPerformed(null); // new ActionEvent(null, 0, ""));
    listener.waitFor();
    TestCase.assertTrue("Expected to be selected", item.isSelected());
    prefsNode.putBoolean("myKey", false);
    prefsNode.sync();
    listener.waitFor();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:AlwaysEnabledActionTest.java

示例7: testSimpleSync

import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testSimpleSync() throws BackingStoreException {
    Preferences orig = Preferences.userRoot().node(getName());
    assertNull("Original contains value", orig.get("key-1", null));

    Preferences test = ProxyPreferences.getProxyPreferences(this, orig);
    assertNull("Test should not contains pair", orig.get("key-1", null));

    test.put("key-1", "xyz");
    assertEquals("Test doesn't contain new pair", "xyz", test.get("key-1", null));

    test.sync();
    assertNull("Test didn't rollback pair", test.get("key-1", null));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ProxyPreferencesTest.java

示例8: testSyncTree1

import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testSyncTree1() throws BackingStoreException {
    String [] origTree = new String [] {
        "CodeStyle/profile=GLOBAL",
    };
    String [] newTree = new String [] {
        "CodeStyle/text/x-java/tab-size=2",
        "CodeStyle/text/x-java/override-global-settings=true",
        "CodeStyle/text/x-java/expand-tabs=true",
        "CodeStyle/profile=PROJECT",
    };

    Preferences orig = Preferences.userRoot().node(getName());
    write(orig, origTree);
    checkContains(orig, origTree, "Orig");
    checkNotContains(orig, newTree, "Orig");
    
    Preferences test = ProxyPreferences.getProxyPreferences(this, orig);
    checkEquals("Test should be the same as Orig", orig, test);
    
    write(test, newTree);
    checkContains(test, newTree, "Test");

    test.sync();
    checkContains(orig, origTree, "Orig");
    checkNotContains(orig, newTree, "Orig");
    checkContains(test, origTree, "Test");
    checkNotContains(test, newTree, "Test");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ProxyPreferencesTest.java

示例9: testSync

import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testSync() throws IOException, BackingStoreException {
    lookup.setDelegates(Lookups.fixed(new TestAuxiliaryConfigurationImpl()));
    
    AuxiliaryConfiguration ac = p.getLookup().lookup(AuxiliaryConfiguration.class);
    
    assertNotNull(ac);
            
    AuxiliaryConfigBasedPreferencesProvider toSync = new AuxiliaryConfigBasedPreferencesProvider(p, ac, null, true);
    Preferences pref = toSync.findModule("test");
    
    pref.put("test", "test");
    
    pref.node("subnode1/subnode2").put("somekey", "somevalue");
    pref.flush();
    
    AuxiliaryConfigBasedPreferencesProvider orig = new AuxiliaryConfigBasedPreferencesProvider(p, ac, null, true);
    
    Preferences origNode = orig.findModule("test").node("subnode1/subnode2");
    
    pref.node("subnode1/subnode2").put("somekey", "somevalue2");
    pref.flush();
    
    origNode.sync();
    
    assertEquals("somevalue2", origNode.get("somekey", null));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AuxiliaryConfigBasedPreferencesProviderTest.java


注:本文中的java.util.prefs.Preferences.sync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。