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


Java Preferences.keys方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:23,代码来源:PreferenceUtils.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:TaskSchedulingManager.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Utils.java

示例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);
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:HistorySettings.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:Utils.java

示例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()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:RepositoryRegistry.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ProxyPreferencesImplTest.java

示例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));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:LazyInstallUnitWizardIterator.java

示例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;
}
 
开发者ID:apache,项目名称:cayenne-modeler,代码行数:27,代码来源:ModelerPreferences.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:HintsPanelLogic.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:FormattingSettingsFromNbPreferences.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:CustomScopeProvider.java

示例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) {
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:LocalRepositoryConfig.java

示例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 );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:TopComponentTracker.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ProxyPreferencesTest.java


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