7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
Summary: Remove rawtype usages and other code cleanup
Reviewed-by: chegar, briangoetz
--- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java Tue May 15 16:46:10 2012 +0400
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java Tue May 15 11:51:51 2012 -0700
@@ -135,18 +135,21 @@
// AbstractPreferences implementation
+ @Override
protected void putSpi(String key, String value)
{
file.addKeyToNode(path, key, value);
}
// AbstractPreferences implementation
+ @Override
protected String getSpi(String key)
{
return file.getKeyFromNode(path, key);
}
// AbstractPreferences implementation
+ @Override
protected void removeSpi(String key)
{
Objects.requireNonNull(key, "Specified key cannot be null");
@@ -155,6 +158,7 @@
// AbstractPreferences implementation
+ @Override
protected void removeNodeSpi()
throws BackingStoreException
{
@@ -174,6 +178,7 @@
// AbstractPreferences implementation
+ @Override
protected String[] childrenNamesSpi()
throws BackingStoreException
{
@@ -183,6 +188,7 @@
}
// AbstractPreferences implementation
+ @Override
protected String[] keysSpi()
throws BackingStoreException
{
@@ -192,6 +198,7 @@
}
// AbstractPreferences implementation
+ @Override
protected AbstractPreferences childSpi(String name)
{
// Add to parent's child list here and disallow sync
@@ -203,6 +210,7 @@
}
// AbstractPreferences override
+ @Override
public void flush()
throws BackingStoreException
{
@@ -217,6 +225,7 @@
}
// AbstractPreferences implementation
+ @Override
protected void flushSpi()
throws BackingStoreException
{
@@ -224,6 +233,7 @@
}
// AbstractPreferences override
+ @Override
public void sync()
throws BackingStoreException
{
@@ -244,6 +254,7 @@
}
// AbstractPreferences implementation
+ @Override
protected void syncSpi()
throws BackingStoreException
{
--- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java Tue May 15 16:46:10 2012 +0400
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java Tue May 15 11:51:51 2012 -0700
@@ -26,10 +26,12 @@
package java.util.prefs;
class MacOSXPreferencesFactory implements PreferencesFactory {
+ @Override
public Preferences userRoot() {
return MacOSXPreferences.getUserRoot();
}
+ @Override
public Preferences systemRoot() {
return MacOSXPreferences.getSystemRoot();
}
--- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java Tue May 15 16:46:10 2012 +0400
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java Tue May 15 11:51:51 2012 -0700
@@ -101,9 +101,10 @@
}
// Maps string -> weak reference to MacOSXPreferencesFile
- private static HashMap cachedFiles = null;
+ private static HashMap<String, WeakReference<MacOSXPreferencesFile>>
+ cachedFiles;
// Files that may have unflushed changes
- private static HashSet changedFiles = null;
+ private static HashSet<MacOSXPreferencesFile> changedFiles;
// Timer and pending sync and flush tasks (which are both scheduled
@@ -136,13 +137,14 @@
{
MacOSXPreferencesFile result = null;
- if (cachedFiles == null) cachedFiles = new HashMap();
+ if (cachedFiles == null)
+ cachedFiles = new HashMap<>();
String hashkey =
newName + String.valueOf(isUser);
- WeakReference hashvalue = (WeakReference)cachedFiles.get(hashkey);
+ WeakReference<MacOSXPreferencesFile> hashvalue = cachedFiles.get(hashkey);
if (hashvalue != null) {
- result = (MacOSXPreferencesFile)hashvalue.get();
+ result = hashvalue.get();
}
if (result == null) {
// Java user node == CF current user, any host
@@ -150,7 +152,7 @@
result = new MacOSXPreferencesFile(newName,
isUser ? cfCurrentUser : cfAnyUser,
isUser ? cfAnyHost : cfCurrentHost);
- cachedFiles.put(hashkey, new WeakReference(result));
+ cachedFiles.put(hashkey, new WeakReference<MacOSXPreferencesFile>(result));
}
// Don't schedule this file for flushing until some nodes or
@@ -171,10 +173,11 @@
boolean ok = true;
if (cachedFiles != null && !cachedFiles.isEmpty()) {
- Iterator iter = cachedFiles.values().iterator();
+ Iterator<WeakReference<MacOSXPreferencesFile>> iter =
+ cachedFiles.values().iterator();
while (iter.hasNext()) {
- WeakReference ref = (WeakReference)iter.next();
- MacOSXPreferencesFile f = (MacOSXPreferencesFile)ref.get();
+ WeakReference<MacOSXPreferencesFile> ref = iter.next();
+ MacOSXPreferencesFile f = ref.get();
if (f != null) {
if (!f.synchronize()) ok = false;
} else {
@@ -202,10 +205,11 @@
static synchronized boolean syncUser() {
boolean ok = true;
if (cachedFiles != null && !cachedFiles.isEmpty()) {
- Iterator<WeakReference> iter = cachedFiles.values().iterator();
+ Iterator<WeakReference<MacOSXPreferencesFile>> iter =
+ cachedFiles.values().iterator();
while (iter.hasNext()) {
- WeakReference ref = iter.next();
- MacOSXPreferencesFile f = (MacOSXPreferencesFile)ref.get();
+ WeakReference<MacOSXPreferencesFile> ref = iter.next();
+ MacOSXPreferencesFile f = ref.get();
if (f != null && f.user == cfCurrentUser) {
if (!f.synchronize()) {
ok = false;
@@ -240,12 +244,10 @@
boolean ok = true;
if (changedFiles != null && !changedFiles.isEmpty()) {
- Iterator iter = changedFiles.iterator();
- while (iter.hasNext()) {
- MacOSXPreferencesFile f = (MacOSXPreferencesFile)iter.next();
- if (!f.synchronize()) ok = false;
+ for (MacOSXPreferencesFile f : changedFiles) {
+ if (!f.synchronize())
+ ok = false;
}
-
changedFiles.clear();
}
@@ -263,7 +265,8 @@
private void markChanged()
{
// Add this file to the changed file list
- if (changedFiles == null) changedFiles = new HashSet();
+ if (changedFiles == null)
+ changedFiles = new HashSet<>();
changedFiles.add(this);
// Schedule a new flush and a shutdown hook, if necessary
@@ -309,7 +312,9 @@
if (syncInterval > 0) {
timer().schedule(new TimerTask() {
- public void run() { MacOSXPreferencesFile.syncWorld();}
+ @Override
+ public void run() {
+ MacOSXPreferencesFile.syncWorld();}
}, syncInterval * 1000, syncInterval * 1000);
} else {
// syncInterval property not set. No sync timer ever.
@@ -323,6 +328,7 @@
if (timer == null) {
timer = new Timer(true); // daemon
Thread flushThread = new Thread() {
+ @Override
public void run() {
flushWorld();
}