changeset 4322:bd1ffb167be0

7041136: Use Objects.equals in JDK platform classes Reviewed-by: alanb, mduigou
author darcy
date Mon, 02 May 2011 11:39:46 -0700
parents fa17f2b9a6d5
children d08d77ad2d7b
files src/share/classes/java/beans/DefaultPersistenceDelegate.java src/share/classes/java/beans/MetaData.java src/share/classes/java/net/HttpCookie.java
diffstat 3 files changed, 13 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/beans/DefaultPersistenceDelegate.java	Mon May 02 11:42:52 2011 -0700
+++ b/src/share/classes/java/beans/DefaultPersistenceDelegate.java	Mon May 02 11:39:46 2011 -0700
@@ -26,6 +26,7 @@
 
 import java.util.*;
 import java.lang.reflect.*;
+import java.util.Objects;
 import sun.reflect.misc.*;
 
 
@@ -181,10 +182,6 @@
         return method;
     }
 
-    private static boolean equals(Object o1, Object o2) {
-        return (o1 == null) ? (o2 == null) : o1.equals(o2);
-    }
-
     private void doProperty(Class type, PropertyDescriptor pd, Object oldInstance, Object newInstance, Encoder out) throws Exception {
         Method getter = pd.getReadMethod();
         Method setter = pd.getWriteMethod();
@@ -195,7 +192,7 @@
             Object oldValue = oldGetExp.getValue();
             Object newValue = newGetExp.getValue();
             out.writeExpression(oldGetExp);
-            if (!equals(newValue, out.get(oldValue))) {
+            if (!Objects.equals(newValue, out.get(oldValue))) {
                 // Search for a static constant with this value;
                 Object e = (Object[])pd.getValue("enumerationValues");
                 if (e instanceof Object[] && Array.getLength(e) % 3 == 0) {
@@ -233,7 +230,7 @@
                 Object oldValue = oldGetExp.getValue();
                 Object newValue = newGetExp.getValue();
                 out.writeExpression(oldGetExp);
-                if (!equals(newValue, out.get(oldValue))) {
+                if (!Objects.equals(newValue, out.get(oldValue))) {
                     out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue }));
                 }
             }
--- a/src/share/classes/java/beans/MetaData.java	Mon May 02 11:42:52 2011 -0700
+++ b/src/share/classes/java/beans/MetaData.java	Mon May 02 11:39:46 2011 -0700
@@ -56,6 +56,8 @@
 
 import sun.swing.PrintColorUIResource;
 
+import java.util.Objects;
+
 /*
  * Like the <code>Intropector</code>, the <code>MetaData</code> class
  * contains <em>meta</em> objects that describe the way
@@ -134,7 +136,7 @@
                 Object oldValue = oldGetExp.getValue();
                 Object newValue = newGetExp.getValue();
                 out.writeExpression(oldGetExp);
-                if (!MetaData.equals(newValue, out.get(oldValue))) {
+                if (!Objects.equals(newValue, out.get(oldValue))) {
                     // System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
                     // invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
                     DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
@@ -635,7 +637,7 @@
                 Object oldValue = oldGetExp.getValue();
                 Object newValue = newGetExp.getValue();
                 out.writeExpression(oldGetExp);
-                if (!MetaData.equals(newValue, out.get(oldValue))) {
+                if (!Objects.equals(newValue, out.get(oldValue))) {
                     invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
                 }
             }
@@ -675,7 +677,7 @@
                 Object oldValue = oldGetExp.getValue();
                 Object newValue = newGetExp.getValue();
                 out.writeExpression(oldGetExp);
-                if (!MetaData.equals(newValue, out.get(oldValue))) {
+                if (!Objects.equals(newValue, out.get(oldValue))) {
                     invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
                 } else if ((newValue == null) && !newMap.containsKey(oldKey)) {
                     // put oldValue(=null?) if oldKey is absent in newMap
@@ -899,17 +901,17 @@
         if (!(oldInstance instanceof java.awt.Window)) {
             Object oldBackground = c.isBackgroundSet() ? c.getBackground() : null;
             Object newBackground = c2.isBackgroundSet() ? c2.getBackground() : null;
-            if (!MetaData.equals(oldBackground, newBackground)) {
+            if (!Objects.equals(oldBackground, newBackground)) {
                 invokeStatement(oldInstance, "setBackground", new Object[] { oldBackground }, out);
             }
             Object oldForeground = c.isForegroundSet() ? c.getForeground() : null;
             Object newForeground = c2.isForegroundSet() ? c2.getForeground() : null;
-            if (!MetaData.equals(oldForeground, newForeground)) {
+            if (!Objects.equals(oldForeground, newForeground)) {
                 invokeStatement(oldInstance, "setForeground", new Object[] { oldForeground }, out);
             }
             Object oldFont = c.isFontSet() ? c.getFont() : null;
             Object newFont = c2.isFontSet() ? c2.getFont() : null;
-            if (!MetaData.equals(oldFont, newFont)) {
+            if (!Objects.equals(oldFont, newFont)) {
                 invokeStatement(oldInstance, "setFont", new Object[] { oldFont }, out);
             }
         }
@@ -1306,10 +1308,6 @@
         internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate());
     }
 
-    /*pp*/ static boolean equals(Object o1, Object o2) {
-        return (o1 == null) ? (o2 == null) : o1.equals(o2);
-    }
-
     public synchronized static PersistenceDelegate getPersistenceDelegate(Class type) {
         if (type == null) {
             return nullPersistenceDelegate;
--- a/src/share/classes/java/net/HttpCookie.java	Mon May 02 11:42:52 2011 -0700
+++ b/src/share/classes/java/net/HttpCookie.java	Mon May 02 11:39:46 2011 -0700
@@ -34,6 +34,7 @@
 
 import java.lang.NullPointerException;  // for javadoc
 import java.util.Locale;
+import java.util.Objects;
 
 /**
  * An HttpCookie object represents an http cookie, which carries state
@@ -817,7 +818,7 @@
         //   3. and have same path (case-sensitive).
         return equalsIgnoreCase(getName(), other.getName()) &&
                equalsIgnoreCase(getDomain(), other.getDomain()) &&
-               equals(getPath(), other.getPath());
+               Objects.equals(getPath(), other.getPath());
     }
 
 
@@ -1162,14 +1163,6 @@
         return false;
     }
 
-    private static boolean equals(String s, String t) {
-        if (s == t) return true;
-        if ((s != null) && (t != null)) {
-            return s.equals(t);
-        }
-        return false;
-    }
-
     private static boolean startsWithIgnoreCase(String s, String start) {
         if (s == null || start == null) return false;