本文整理匯總了Java中java.util.prefs.Preferences.keys方法的典型用法代碼示例。如果您正苦於以下問題:Java Preferences.keys方法的具體用法?Java Preferences.keys怎麽用?Java Preferences.keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.prefs.Preferences
的用法示例。
在下文中一共展示了Preferences.keys方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyPrefs
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public static void copyPrefs(Preferences source, Preferences destination) {
try {
// Copy the key/value pairs first
String[] prefKeys = source.keys();
for (int i = 0; i < prefKeys.length; i++) {
destination.put(prefKeys[i], source.get(prefKeys[i], ""));
}
// Now grab all the names of the children nodes
String[] childrenNames = source.childrenNames();
// Recursively copy the preference nodes
for (int i = 0; i < childrenNames.length; i++) {
copyPrefs(source.node(childrenNames[i]),
destination.node(childrenNames[i]));
}
}
catch (Exception e) {
LoggerFactory.getLogger(PreferenceUtils.class)
.error("Failed to copy preferences.", e);
}
}
示例2: loadTasks
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private void loadTasks() {
Preferences pref = NbPreferences.forModule(TaskSchedulingManager.class);
try {
for (String key : pref.keys()) {
if (key.startsWith(PREF_SCHEDULED)) {
String repositoryId = key.substring(PREF_SCHEDULED.length());
String tasks = pref.get(key, "");
for (String taskId : tasks.split(SEP)) {
if (!taskId.isEmpty()) {
getRepositoryTasks(repositoryId).add(taskId);
}
}
}
}
} catch (BackingStoreException ex) {
Logger.getLogger(TaskSchedulingManager.class.getName()).log(Level.INFO, null, ex);
}
}
示例3: put
import java.util.prefs.Preferences; //導入方法依賴的package包/類
/**
* Stores a List of Strings into Preferences node under the given key.
*
* @param prefs storage
* @param key key of the String array
* @param value List of Strings to write (order will be preserved)
*/
public static void put(Preferences prefs, String key, List<String> value) {
try {
String[] keys = prefs.keys();
for (int i = 0; i < keys.length; i++) {
String k = keys[i];
if (k != null && k.startsWith(key + ".")) {
prefs.remove(k);
}
}
int idx = 0;
for (String s : value) {
prefs.put(key + "." + idx++, s);
}
} catch (BackingStoreException ex) {
Logger.getLogger(Utils.class.getName()).log(Level.INFO, null, ex);
}
}
示例4: migrate
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private static void migrate() {
// migrate pre 7.2 settings
String prevPath = "org/netbeans/modules/localhistory"; // NOI18N
try {
if(!NbPreferences.root().nodeExists(prevPath)) {
return;
}
Preferences prev = NbPreferences.root().node(prevPath);
Preferences cur = NbPreferences.forModule(HistorySettings.class);
String[] keys = prev.keys();
for (String key : keys) {
String value = prev.get(key, null);
if(value != null && cur.get(key, null) == null) {
cur.put(key, value);
}
}
prev.removeNode();
} catch (BackingStoreException ex) {
Exceptions.printStackTrace(ex);
}
}
示例5: getStringList
import java.util.prefs.Preferences; //導入方法依賴的package包/類
/**
* Helper method to get an array of Strings from preferences.
*
* @param prefs storage
* @param key key of the String array
* @return List<String> stored List of String or an empty List if the key was not found (order is preserved)
*/
public static List<String> getStringList (Preferences prefs, String key) {
List<String> retval = new ArrayList<String>();
try {
String[] keys = prefs.keys();
for (int i = 0; i < keys.length; i++) {
String k = keys[i];
if (k != null && k.startsWith(key)) {
int idx = Integer.parseInt(k.substring(k.lastIndexOf('.') + 1));
retval.add(idx + "." + prefs.get(k, null));
}
}
List<String> rv = new ArrayList<String>(retval.size());
rv.addAll(retval);
for (String s : retval) {
int pos = s.indexOf('.');
int index = Integer.parseInt(s.substring(0, pos));
rv.set(index, s.substring(pos + 1));
}
return rv;
} catch (Exception ex) {
Logger.getLogger(Utils.class.getName()).log(Level.INFO, null, ex);
return new ArrayList<String>(0);
}
}
示例6: getRepoIds
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private String[] getRepoIds(Preferences preferences, String repoId) {
String[] keys = null;
try {
keys = preferences.keys();
} catch (BackingStoreException ex) {
BugtrackingManager.LOG.log(Level.SEVERE, null, ex);
}
if (keys == null || keys.length == 0) {
return new String[0];
}
List<String> ret = new ArrayList<String>();
for (String key : keys) {
if (key.startsWith(repoId)) {
ret.add(key.substring(repoId.length()));
}
}
return ret.toArray(new String[ret.size()]);
}
示例7: checkEquals
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private void checkEquals(String msg, Preferences expected, Preferences test) throws BackingStoreException {
assertEquals("Won't compare two Preferences with different absolutePath", expected.absolutePath(), test.absolutePath());
// check the keys and their values
for(String key : expected.keys()) {
String expectedValue = expected.get(key, null);
assertNotNull(msg + "; Expected:" + expected.absolutePath() + " has no '" + key + "'", expectedValue);
String value = test.get(key, null);
assertNotNull(msg + "; Test:" + test.absolutePath() + " has no '" + key + "'", value);
assertEquals(msg + "; Test:" + test.absolutePath() + "/" + key + " has wrong value", expectedValue, value);
}
// check the children
for(String child : expected.childrenNames()) {
assertTrue(msg + "; Expected:" + expected.absolutePath() + " has no '" + child + "' subnode", expected.nodeExists(child));
Preferences expectedChild = expected.node(child);
assertTrue(msg + "; Test:" + test.absolutePath() + " has no '" + child + "' subnode", test.nodeExists(child));
Preferences testChild = test.node(child);
checkEquals(msg, expectedChild, testChild);
}
}
示例8: storeUpdateElements
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public static void storeUpdateElements (OperationType operationType, Collection<UpdateElement> elements) {
Preferences p = getPreferences (operationType);
try {
if (p.keys ().length > 0) {
p.clear ();
}
} catch (BackingStoreException ex) {
Logger.getLogger (LazyInstallUnitWizardIterator.class.getName ()).log (Level.WARNING, ex.getLocalizedMessage (), ex);
}
if (elements == null) {
return ;
}
for (UpdateElement el : elements) {
p.put (el.getCodeName (), toString (el));
}
}
示例9: getLastProjFiles
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public static List<String> getLastProjFiles() {
Preferences filesPrefs = getLastProjFilesPref();
ArrayList<String> arrayLastProjFiles = new ArrayList<>();
String[] keys = null;
try {
keys = filesPrefs.keys();
}
catch (BackingStoreException e) {
logObj.warn("Error reading preferences file.", e);
}
if (keys != null) {
int len = keys.length;
ArrayList<Integer> keysInteger = new ArrayList<>();
for (int i = 0; i < len; i++) {
keysInteger.add(new Integer(i));
}
Collections.sort(keysInteger);
for (int i = 0; i < len; i++) {
arrayLastProjFiles.add(filesPrefs.get(keysInteger.get(i).toString(), ""));
}
}
return arrayLastProjFiles;
}
示例10: ModifiedPreferences
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public ModifiedPreferences( Preferences node ) {
super(null, ""); // NOI18N
try {
for (java.lang.String key : node.keys()) {
put(key, node.get(key, null));
}
}
catch (BackingStoreException ex) {
Exceptions.printStackTrace(ex);
}
}
示例11: afterLoad
import java.util.prefs.Preferences; //導入方法依賴的package包/類
@Override
public void afterLoad(Map<String, TypedValue> map, MimePath mimePath, String profile, boolean defaults) throws IOException {
if (defaults || mimePath.size() != 1 || !affectedMimeTypes.containsKey(mimePath.getPath())) {
return;
}
try {
Preferences nbprefs = getNbPreferences(mimePath.getPath());
if (nbprefs != null && nbprefs.nodeExists("CodeStyle/default")) { //NOI18N
Preferences codestyle = nbprefs.node("CodeStyle/default"); //NOI18N
for(String key : codestyle.keys()) {
if (!map.containsKey(key)) {
TypedValue typedValue = guessTypedValue(codestyle.get(key, null));
if (typedValue != null) {
map.put(key, typedValue);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Injecting '" + key + "' = '" + typedValue.getValue() //NOI18N
+ "' (" + typedValue.getJavaType() + ") for '" + mimePath.getPath() + "'"); //NOI18N
}
}
}
}
}
} catch (BackingStoreException bse) {
// ignore
LOG.log(Level.FINE, null, bse);
}
}
示例12: loadFileList
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private <T> List<T> loadFileList(String basekey, Class<T> type) throws BackingStoreException {
Preferences pref = NbPreferences.forModule(JavaScopeBuilder.class).node(PREF_SCOPE).node(basekey);
List<T> toRet = new LinkedList<T>();
for (String key : pref.keys()) {
final String url = pref.get(key, null);
if (url != null && !url.isEmpty()) {
try {
final FileObject f = URLMapper.findFileObject(new URL(url));
if (f != null && f.isValid()) {
if (type.isAssignableFrom(FileObject.class)) {
toRet.add((T) f);
} else {
toRet.add((T) new NonRecursiveFolder() {
@Override
public FileObject getFolder() {
return f;
}
});
}
}
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
}
}
}
return toRet;
}
示例13: deleteTaskPreferences
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public void deleteTaskPreferences (String taskId) {
Preferences prefs = getPreferences();
try {
String taskKey = getTaskKey(taskId);
for (String key : prefs.keys()) {
if (key.startsWith(taskKey)) {
prefs.remove(key);
}
}
} catch (BackingStoreException ex) {
}
}
示例14: load
import java.util.prefs.Preferences; //導入方法依賴的package包/類
/**
* Load window list from previous session.
*/
void load() {
Preferences prefs = getPreferences();
try {
for( String key : prefs.keys() ) {
boolean view = prefs.getBoolean( key, false );
if( view )
viewIds.add( key );
else
editorIds.add( key );
}
} catch( BackingStoreException ex ) {
Logger.getLogger( TopComponentTracker.class.getName() ).log( Level.INFO, null, ex );
}
}
示例15: dump
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private void dump(Preferences prefs, String prefsId) throws BackingStoreException {
for(String key : prefs.keys()) {
System.out.println(prefsId + ", " + prefs.absolutePath() + "/" + key + "=" + prefs.get(key, null));
}
for(String child : prefs.childrenNames()) {
dump(prefs.node(child), prefsId);
}
}