當前位置: 首頁>>代碼示例>>Java>>正文


Java Preferences.nodeExists方法代碼示例

本文整理匯總了Java中java.util.prefs.Preferences.nodeExists方法的典型用法代碼示例。如果您正苦於以下問題:Java Preferences.nodeExists方法的具體用法?Java Preferences.nodeExists怎麽用?Java Preferences.nodeExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.prefs.Preferences的用法示例。


在下文中一共展示了Preferences.nodeExists方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addGroup

import java.util.prefs.Preferences; //導入方法依賴的package包/類
void addGroup(String displayName) {
    Preferences prefs = getPreferences();
    int groupIndex = getGroups().size();
    String groupName = DEFAULT_GROUP_NAME + groupIndex;
    try {
        do {
            groupIndex++;
            groupName = DEFAULT_GROUP_NAME + groupIndex;
        } while( prefs.nodeExists(groupName) );
    } catch( BackingStoreException ex ) {
        LOG.log(Level.INFO, null, ex);
    }
    prefs.put(SEL_GROUP, groupName);

    prefs.node(groupName).put(DISPLAY_NAME, displayName);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:GroupsManager.java

示例2: checkNotContains

import java.util.prefs.Preferences; //導入方法依賴的package包/類
private void checkNotContains(Preferences prefs, String[] tree, String prefsId) throws BackingStoreException {
    for(String s : tree) {
        int equalIdx = s.lastIndexOf('=');
        assertTrue(equalIdx != -1);
        String value = s.substring(equalIdx + 1);

        String key;
        String nodePath;
        int slashIdx = s.lastIndexOf('/', equalIdx);
        if (slashIdx != -1) {
            key = s.substring(slashIdx + 1, equalIdx);
            nodePath = s.substring(0, slashIdx);
        } else {
            key = s.substring(0, equalIdx);
            nodePath = "";
        }

        if (prefs.nodeExists(nodePath)) {
            Preferences node = prefs.node(nodePath);
            String realValue = node.get(key, null);
            if (realValue != null && realValue.equals(value)) {
                fail(prefsId + ", '" + nodePath + "' node contains key '" + key + "' = '" + realValue + "'");
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ProxyPreferencesImplTest.java

示例3: beforeSave

import java.util.prefs.Preferences; //導入方法依賴的package包/類
@Override
public void beforeSave(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
            // We loaded the settings from NbPreferences in beforeLoad,
            // they are in the map (maybe modified somehow) and they are
            // going to be saved to MimeLookup. So we can safely clean them up from NbPreferences.
            nbprefs.node("CodeStyle").removeNode(); //NOI18N
            nbprefs.flush();

            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Cleaning up NbPreferences/CodeStyle node for '" + mimePath.getPath() + "'"); //NOI18N
            }
        }
    } catch (BackingStoreException bse) {
        // ignore
        LOG.log(Level.FINE, null, bse);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:FormattingSettingsFromNbPreferences.java

示例4: resolvePlaceholder

import java.util.prefs.Preferences; //導入方法依賴的package包/類
/**
 * Resolve the given path and key against the given Preferences.
 * @param path the preferences path (placeholder part before '/')
 * @param key the preferences key (placeholder part after '/')
 * @param preferences the Preferences to resolve against
 * @return the value for the placeholder, or {@code null} if none found
 */
protected String resolvePlaceholder(String path, String key, Preferences preferences) {
	if (path != null) {
		 // Do not create the node if it does not exist...
		try {
			if (preferences.nodeExists(path)) {
				return preferences.node(path).get(key, null);
			}
			else {
				return null;
			}
		}
		catch (BackingStoreException ex) {
			throw new BeanDefinitionStoreException("Cannot access specified node path [" + path + "]", ex);
		}
	}
	else {
		return preferences.get(key, null);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:PreferencesPlaceholderConfigurer.java

示例5: getLast

import java.util.prefs.Preferences; //導入方法依賴的package包/類
public static ProjectConfig getLast() {
	Preferences prefs = Preferences.userRoot();

	try {
		if (prefs.nodeExists(userPrefFolder)
				&& (prefs = prefs.node(userPrefFolder)).nodeExists(userPrefKey)
				&& (prefs = prefs.node(userPrefKey)).nodeExists(pathsAKey) && prefs.nodeExists(pathsBKey) && prefs.nodeExists(pathsSharedKey)) {
			Function<String, Path> deserializer = str -> Paths.get(str);

			List<Path> pathsA = loadList(prefs.node(pathsAKey), deserializer);
			List<Path> pathsB = loadList(prefs.node(pathsBKey), deserializer);
			List<Path> classPathA = loadList(prefs.node(classPathAKey), deserializer);
			List<Path> classPathB = loadList(prefs.node(classPathBKey), deserializer);
			List<Path> pathsShared = loadList(prefs.node(pathsSharedKey), deserializer);
			boolean inputsBeforeClassPath = prefs.getBoolean(inputsBeforeClassPathKey, false);

			ProjectConfig ret = new ProjectConfig(pathsA, pathsB, classPathA, classPathB, pathsShared, inputsBeforeClassPath);

			ret.setUidSettings(prefs.get("uidHost", null),
					prefs.getInt("uidPort", 0),
					prefs.get("uidUser", null),
					prefs.get("uidPassword", null),
					prefs.get("uidProject", null),
					prefs.get("uidVersionA", null),
					prefs.get("uidVersionB", null));

			return ret;
		}
	} catch (BackingStoreException e) { }

	return new ProjectConfig();
}
 
開發者ID:sfPlayer1,項目名稱:Matcher,代碼行數:33,代碼來源:ProjectConfig.java

示例6: createProperties

import java.util.prefs.Preferences; //導入方法依賴的package包/類
/**
 * Creates and returns properties in the given namespace. It is
 * perfectly legal to call this method multiple times with the same
 * namespace as a parameter - it will always create new instance
 * of InstanceProperties. Returned properties should serve for persistence
 * of the single server instance.
 *
 * @param namespace string identifying the namespace of created InstanceProperties
 * @return new InstanceProperties logically placed in the given namespace
 */
public InstanceProperties createProperties(String namespace) {
    Preferences prefs = NbPreferences.forModule(InstancePropertiesManager.class);

    try {
        prefs = prefs.node(namespace);

        boolean next = true;
        String id = null;
        synchronized (this) {
            while (next) {
                id = Integer.toString(random.nextInt(Integer.MAX_VALUE));
                next = prefs.nodeExists(id);
            }
            prefs = prefs.node(id);
            prefs.flush();

            InstanceProperties created = new DefaultInstanceProperties(id, this, prefs);
            cache.put(prefs, created);

            return created;
        }
    } catch (BackingStoreException ex) {
        LOGGER.log(Level.INFO, null, ex);
        throw new IllegalStateException(ex);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:InstancePropertiesManager.java

示例7: 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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:FormattingSettingsFromNbPreferences.java

示例8: getInputMethodSelectionKeyStroke

import java.util.prefs.Preferences; //導入方法依賴的package包/類
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:16,代碼來源:InputContext.java

示例9: loadRoots

import java.util.prefs.Preferences; //導入方法依賴的package包/類
@NonNull
private Map<URL,T> loadRoots() {
    synchronized(lck) {
       if (cache == null) {
           Map<URL,T> result = new HashMap<URL, T>();
           final Preferences root = NbPreferences.forModule(QueriesCache.class);
           final String folder = clazz.getSimpleName();
           try {
               if (root.nodeExists(folder)) {
                   final Preferences node = root.node(folder);
                   Map<URL,List<URL>> bindings = new HashMap<URL, List<URL>>();
                   for (String key : node.keys()) {
                       final String value = node.get(key, null);
                       if (value != null) {
                           final URL binUrl = getURL(key);
                           List<URL> binding = bindings.get(binUrl);
                           if(binding == null) {
                               binding = new ArrayList<URL>();
                               bindings.put(binUrl,binding);
                           }
                           binding.add(new URL(value));
                       }
                   }
                   for (Map.Entry<URL,List<URL>> e : bindings.entrySet()) {
                       final T instance = clazz.newInstance();
                       instance.update(e.getValue());
                       result.put(e.getKey(), instance);
                   }
               }
           } catch (BackingStoreException bse) {
               Exceptions.printStackTrace(bse);
           } catch (MalformedURLException mue) {
               Exceptions.printStackTrace(mue);
           } catch (InstantiationException ie) {
               Exceptions.printStackTrace(ie);
           } catch (IllegalAccessException iae) {
               Exceptions.printStackTrace(iae);
           }
           cache = result;
       }
       return cache;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:44,代碼來源:QueriesCache.java


注:本文中的java.util.prefs.Preferences.nodeExists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。