当前位置: 首页>>代码示例>>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;未经允许,请勿转载。