本文整理匯總了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());
}
}
示例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));
}
示例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);
}
}
示例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));
}
示例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");
}
示例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();
}
示例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));
}
示例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");
}
示例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));
}