⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractpreferences.java

📁 java源代码 请看看啊 提点宝贵的意见
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            removeSpi(key);            enqueuePreferenceChangeEvent(key, null);        }    }    /**     * Implements the <tt>clear</tt> method as per the specification in     * {@link Preferences#clear()}.     *     * <p>This implementation obtains this preference node's lock,     * invokes {@link #keys()} to obtain an array of keys, and     * iterates over the array invoking {@link #remove(String)} on each key.     *     * @throws BackingStoreException if this operation cannot be completed     *         due to a failure in the backing store, or inability to      *         communicate with it.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     */    public void clear() throws BackingStoreException {        synchronized(lock) {            String[] keys = keys();            for (int i=0; i<keys.length; i++)                remove(keys[i]);        }    }    /**     * Implements the <tt>putInt</tt> method as per the specification in     * {@link Preferences#putInt(String,int)}.     *     * <p>This implementation translates <tt>value</tt> to a string with     * {@link Integer#toString(int)} and invokes {@link #put(String,String)}     * on the result.     *     * @param key key with which the string form of value is to be associated.     * @param value value whose string form is to be associated with key.     * @throws NullPointerException if key is <tt>null</tt>.     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds     *         <tt>MAX_KEY_LENGTH</tt>.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     */    public void putInt(String key, int value) {        put(key, Integer.toString(value));    }    /**     * Implements the <tt>getInt</tt> method as per the specification in     * {@link Preferences#getInt(String,int)}.     *     * <p>This implementation invokes {@link #get(String,String) <tt>get(key,     * null)</tt>}.  If the return value is non-null, the implementation     * attempts to translate it to an <tt>int</tt> with     * {@link Integer#parseInt(String)}.  If the attempt succeeds, the return     * value is returned by this method.  Otherwise, <tt>def</tt> is returned.     *     * @param key key whose associated value is to be returned as an int.     * @param def the value to be returned in the event that this     *        preference node has no value associated with <tt>key</tt>     *        or the associated value cannot be interpreted as an int.     * @return the int value represented by the string associated with     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the     *         associated value does not exist or cannot be interpreted as     *         an int.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.     */    public int getInt(String key, int def) {        int result = def;        try {            String value = get(key, null);            if (value != null)                result = Integer.parseInt(value);        } catch (NumberFormatException e) {            // Ignoring exception causes specified default to be returned        }        return result;    }    /**     * Implements the <tt>putLong</tt> method as per the specification in     * {@link Preferences#putLong(String,long)}.     *     * <p>This implementation translates <tt>value</tt> to a string with     * {@link Long#toString(long)} and invokes {@link #put(String,String)}     * on the result.     *     * @param key key with which the string form of value is to be associated.     * @param value value whose string form is to be associated with key.     * @throws NullPointerException if key is <tt>null</tt>.     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds     *         <tt>MAX_KEY_LENGTH</tt>.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     */    public void putLong(String key, long value) {        put(key, Long.toString(value));    }    /**     * Implements the <tt>getLong</tt> method as per the specification in     * {@link Preferences#getLong(String,long)}.     *     * <p>This implementation invokes {@link #get(String,String) <tt>get(key,     * null)</tt>}.  If the return value is non-null, the implementation     * attempts to translate it to a <tt>long</tt> with     * {@link Long#parseLong(String)}.  If the attempt succeeds, the return     * value is returned by this method.  Otherwise, <tt>def</tt> is returned.     *     * @param key key whose associated value is to be returned as a long.     * @param def the value to be returned in the event that this     *        preference node has no value associated with <tt>key</tt>     *        or the associated value cannot be interpreted as a long.     * @return the long value represented by the string associated with     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the     *         associated value does not exist or cannot be interpreted as     *         a long.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.     */    public long getLong(String key, long def) {        long result = def;        try {            String value = get(key, null);            if (value != null)                result = Long.parseLong(value);        } catch (NumberFormatException e) {            // Ignoring exception causes specified default to be returned        }        return result;    }    /**     * Implements the <tt>putBoolean</tt> method as per the specification in     * {@link Preferences#putBoolean(String,boolean)}.     *     * <p>This implementation translates <tt>value</tt> to a string with     * {@link String#valueOf(boolean)} and invokes {@link #put(String,String)}     * on the result.     *     * @param key key with which the string form of value is to be associated.     * @param value value whose string form is to be associated with key.     * @throws NullPointerException if key is <tt>null</tt>.     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds     *         <tt>MAX_KEY_LENGTH</tt>.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     */    public void putBoolean(String key, boolean value) {        put(key, String.valueOf(value));    }    /**     * Implements the <tt>getBoolean</tt> method as per the specification in     * {@link Preferences#getBoolean(String,boolean)}.     *     * <p>This implementation invokes {@link #get(String,String) <tt>get(key,     * null)</tt>}.  If the return value is non-null, it is compared with     * <tt>"true"</tt> using {@link String#equalsIgnoreCase(String)}.  If the     * comparison returns <tt>true</tt>, this invocation returns     * <tt>true</tt>.  Otherwise, the original return value is compared with     * <tt>"false"</tt>, again using {@link String#equalsIgnoreCase(String)}.     * If the comparison returns <tt>true</tt>, this invocation returns     * <tt>false</tt>.  Otherwise, this invocation returns <tt>def</tt>.     *     * @param key key whose associated value is to be returned as a boolean.     * @param def the value to be returned in the event that this     *        preference node has no value associated with <tt>key</tt>     *        or the associated value cannot be interpreted as a boolean.     * @return the boolean value represented by the string associated with     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the     *         associated value does not exist or cannot be interpreted as     *         a boolean.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.     */    public boolean getBoolean(String key, boolean def) {        boolean result = def;        String value = get(key, null);        if (value != null) {            if (value.equalsIgnoreCase("true"))                result = true;            else if (value.equalsIgnoreCase("false"))                result = false;        }        return result;    }    /**     * Implements the <tt>putFloat</tt> method as per the specification in     * {@link Preferences#putFloat(String,float)}.     *     * <p>This implementation translates <tt>value</tt> to a string with     * {@link Float#toString(float)} and invokes {@link #put(String,String)}     * on the result.     *     * @param key key with which the string form of value is to be associated.     * @param value value whose string form is to be associated with key.     * @throws NullPointerException if key is <tt>null</tt>.     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds     *         <tt>MAX_KEY_LENGTH</tt>.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     */    public void putFloat(String key, float value) {        put(key, Float.toString(value));    }    /**     * Implements the <tt>getFloat</tt> method as per the specification in     * {@link Preferences#getFloat(String,float)}.     *     * <p>This implementation invokes {@link #get(String,String) <tt>get(key,     * null)</tt>}.  If the return value is non-null, the implementation     * attempts to translate it to an <tt>float</tt> with     * {@link Float#parseFloat(String)}.  If the attempt succeeds, the return     * value is returned by this method.  Otherwise, <tt>def</tt> is returned.     *     * @param key key whose associated value is to be returned as a float.     * @param def the value to be returned in the event that this     *        preference node has no value associated with <tt>key</tt>     *        or the associated value cannot be interpreted as a float.     * @return the float value represented by the string associated with     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the     *         associated value does not exist or cannot be interpreted as     *         a float.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.     */    public float getFloat(String key, float def) {        float result = def;        try {            String value = get(key, null);            if (value != null)                result = Float.parseFloat(value);        } catch (NumberFormatException e) {            // Ignoring exception causes specified default to be returned        }        return result;    }    /**     * Implements the <tt>putDouble</tt> method as per the specification in     * {@link Preferences#putDouble(String,double)}.     *     * <p>This implementation translates <tt>value</tt> to a string with     * {@link Double#toString(double)} and invokes {@link #put(String,String)}     * on the result.     *     * @param key key with which the string form of value is to be associated.     * @param value value whose string form is to be associated with key.     * @throws NullPointerException if key is <tt>null</tt>.     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds     *         <tt>MAX_KEY_LENGTH</tt>.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     */    public void putDouble(String key, double value) {        put(key, Double.toString(value));    }    /**     * Implements the <tt>getDouble</tt> method as per the specification in     * {@link Preferences#getDouble(String,double)}.     *     * <p>This implementation invokes {@link #get(String,String) <tt>get(key,     * null)</tt>}.  If the return value is non-null, the implementation     * attempts to translate it to an <tt>double</tt> with     * {@link Double#parseDouble(String)}.  If the attempt succeeds, the return     * value is returned by this method.  Otherwise, <tt>def</tt> is returned.     *     * @param key key whose associated value is to be returned as a double.     * @param def the value to be returned in the event that this     *        preference node has no value associated with <tt>key</tt>     *        or the associated value cannot be interpreted as a double.     * @return the double value represented by the string associated with     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the     *         associated value does not exist or cannot be interpreted as     *         a double.     * @throws IllegalStateException if this node (or an ancestor) has been     *         removed with the {@link #removeNode()} method.     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.     */    public double getDouble(String key, double def) {        double result = def;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -