src/share/classes/java/util/prefs/AbstractPreferences.java

Print this page




 288             } catch (Exception e) {
 289                 // Ignoring exception causes default to be returned
 290             }
 291             return (result==null ? def : result);
 292         }
 293     }
 294 
 295     /**
 296      * Implements the <tt>remove(String)</tt> method as per the specification
 297      * in {@link Preferences#remove(String)}.
 298      *
 299      * <p>This implementation obtains this preference node's lock,
 300      * checks that the node has not been removed, invokes
 301      * {@link #removeSpi(String)} and if there are any preference
 302      * change listeners, enqueues a notification event for processing by the
 303      * event dispatch thread.
 304      *
 305      * @param key key whose mapping is to be removed from the preference node.
 306      * @throws IllegalStateException if this node (or an ancestor) has been
 307      *         removed with the {@link #removeNode()} method.

 308      */
 309     public void remove(String key) {

 310         synchronized(lock) {
 311             if (removed)
 312                 throw new IllegalStateException("Node has been removed.");
 313 
 314             removeSpi(key);
 315             enqueuePreferenceChangeEvent(key, null);
 316         }
 317     }
 318 
 319     /**
 320      * Implements the <tt>clear</tt> method as per the specification in
 321      * {@link Preferences#clear()}.
 322      *
 323      * <p>This implementation obtains this preference node's lock,
 324      * invokes {@link #keys()} to obtain an array of keys, and
 325      * iterates over the array invoking {@link #remove(String)} on each key.
 326      *
 327      * @throws BackingStoreException if this operation cannot be completed
 328      *         due to a failure in the backing store, or inability to
 329      *         communicate with it.




 288             } catch (Exception e) {
 289                 // Ignoring exception causes default to be returned
 290             }
 291             return (result==null ? def : result);
 292         }
 293     }
 294 
 295     /**
 296      * Implements the <tt>remove(String)</tt> method as per the specification
 297      * in {@link Preferences#remove(String)}.
 298      *
 299      * <p>This implementation obtains this preference node's lock,
 300      * checks that the node has not been removed, invokes
 301      * {@link #removeSpi(String)} and if there are any preference
 302      * change listeners, enqueues a notification event for processing by the
 303      * event dispatch thread.
 304      *
 305      * @param key key whose mapping is to be removed from the preference node.
 306      * @throws IllegalStateException if this node (or an ancestor) has been
 307      *         removed with the {@link #removeNode()} method.
 308      * @throws NullPointerException {@inheritDoc}.
 309      */
 310     public void remove(String key) {
 311         Objects.requireNonNull(key, "Specified key cannot be null");
 312         synchronized(lock) {
 313             if (removed)
 314                 throw new IllegalStateException("Node has been removed.");
 315 
 316             removeSpi(key);
 317             enqueuePreferenceChangeEvent(key, null);
 318         }
 319     }
 320 
 321     /**
 322      * Implements the <tt>clear</tt> method as per the specification in
 323      * {@link Preferences#clear()}.
 324      *
 325      * <p>This implementation obtains this preference node's lock,
 326      * invokes {@link #keys()} to obtain an array of keys, and
 327      * iterates over the array invoking {@link #remove(String)} on each key.
 328      *
 329      * @throws BackingStoreException if this operation cannot be completed
 330      *         due to a failure in the backing store, or inability to
 331      *         communicate with it.