提交 ffab6390 编写于 作者: D darcy

7041136: Use Objects.equals in JDK platform classes

Reviewed-by: alanb, mduigou
上级 0924c27d
...@@ -26,6 +26,7 @@ package java.beans; ...@@ -26,6 +26,7 @@ package java.beans;
import java.util.*; import java.util.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.Objects;
import sun.reflect.misc.*; import sun.reflect.misc.*;
...@@ -181,10 +182,6 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { ...@@ -181,10 +182,6 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
return method; 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 { private void doProperty(Class type, PropertyDescriptor pd, Object oldInstance, Object newInstance, Encoder out) throws Exception {
Method getter = pd.getReadMethod(); Method getter = pd.getReadMethod();
Method setter = pd.getWriteMethod(); Method setter = pd.getWriteMethod();
...@@ -195,7 +192,7 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { ...@@ -195,7 +192,7 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
Object oldValue = oldGetExp.getValue(); Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue(); Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp); out.writeExpression(oldGetExp);
if (!equals(newValue, out.get(oldValue))) { if (!Objects.equals(newValue, out.get(oldValue))) {
// Search for a static constant with this value; // Search for a static constant with this value;
Object e = (Object[])pd.getValue("enumerationValues"); Object e = (Object[])pd.getValue("enumerationValues");
if (e instanceof Object[] && Array.getLength(e) % 3 == 0) { if (e instanceof Object[] && Array.getLength(e) % 3 == 0) {
...@@ -233,7 +230,7 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { ...@@ -233,7 +230,7 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
Object oldValue = oldGetExp.getValue(); Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue(); Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp); 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 })); out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue }));
} }
} }
......
...@@ -56,6 +56,8 @@ import javax.swing.plaf.ColorUIResource; ...@@ -56,6 +56,8 @@ import javax.swing.plaf.ColorUIResource;
import sun.swing.PrintColorUIResource; import sun.swing.PrintColorUIResource;
import java.util.Objects;
/* /*
* Like the <code>Intropector</code>, the <code>MetaData</code> class * Like the <code>Intropector</code>, the <code>MetaData</code> class
* contains <em>meta</em> objects that describe the way * contains <em>meta</em> objects that describe the way
...@@ -134,7 +136,7 @@ class ArrayPersistenceDelegate extends PersistenceDelegate { ...@@ -134,7 +136,7 @@ class ArrayPersistenceDelegate extends PersistenceDelegate {
Object oldValue = oldGetExp.getValue(); Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue(); Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp); out.writeExpression(oldGetExp);
if (!MetaData.equals(newValue, out.get(oldValue))) { if (!Objects.equals(newValue, out.get(oldValue))) {
// System.out.println("Not equal: " + newGetExp + " != " + actualGetExp); // System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
// invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out); // invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out); DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
...@@ -635,7 +637,7 @@ class java_util_List_PersistenceDelegate extends DefaultPersistenceDelegate { ...@@ -635,7 +637,7 @@ class java_util_List_PersistenceDelegate extends DefaultPersistenceDelegate {
Object oldValue = oldGetExp.getValue(); Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue(); Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp); 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); invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
} }
} }
...@@ -675,7 +677,7 @@ class java_util_Map_PersistenceDelegate extends DefaultPersistenceDelegate { ...@@ -675,7 +677,7 @@ class java_util_Map_PersistenceDelegate extends DefaultPersistenceDelegate {
Object oldValue = oldGetExp.getValue(); Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue(); Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp); 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); invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
} else if ((newValue == null) && !newMap.containsKey(oldKey)) { } else if ((newValue == null) && !newMap.containsKey(oldKey)) {
// put oldValue(=null?) if oldKey is absent in newMap // put oldValue(=null?) if oldKey is absent in newMap
...@@ -899,17 +901,17 @@ class java_awt_Component_PersistenceDelegate extends DefaultPersistenceDelegate ...@@ -899,17 +901,17 @@ class java_awt_Component_PersistenceDelegate extends DefaultPersistenceDelegate
if (!(oldInstance instanceof java.awt.Window)) { if (!(oldInstance instanceof java.awt.Window)) {
Object oldBackground = c.isBackgroundSet() ? c.getBackground() : null; Object oldBackground = c.isBackgroundSet() ? c.getBackground() : null;
Object newBackground = c2.isBackgroundSet() ? c2.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); invokeStatement(oldInstance, "setBackground", new Object[] { oldBackground }, out);
} }
Object oldForeground = c.isForegroundSet() ? c.getForeground() : null; Object oldForeground = c.isForegroundSet() ? c.getForeground() : null;
Object newForeground = c2.isForegroundSet() ? c2.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); invokeStatement(oldInstance, "setForeground", new Object[] { oldForeground }, out);
} }
Object oldFont = c.isFontSet() ? c.getFont() : null; Object oldFont = c.isFontSet() ? c.getFont() : null;
Object newFont = c2.isFontSet() ? c2.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); invokeStatement(oldInstance, "setFont", new Object[] { oldFont }, out);
} }
} }
...@@ -1306,10 +1308,6 @@ class MetaData { ...@@ -1306,10 +1308,6 @@ class MetaData {
internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate()); 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) { public synchronized static PersistenceDelegate getPersistenceDelegate(Class type) {
if (type == null) { if (type == null) {
return nullPersistenceDelegate; return nullPersistenceDelegate;
......
...@@ -34,6 +34,7 @@ import java.util.Date; ...@@ -34,6 +34,7 @@ import java.util.Date;
import java.lang.NullPointerException; // for javadoc import java.lang.NullPointerException; // for javadoc
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
/** /**
* An HttpCookie object represents an http cookie, which carries state * An HttpCookie object represents an http cookie, which carries state
...@@ -817,7 +818,7 @@ public final class HttpCookie implements Cloneable { ...@@ -817,7 +818,7 @@ public final class HttpCookie implements Cloneable {
// 3. and have same path (case-sensitive). // 3. and have same path (case-sensitive).
return equalsIgnoreCase(getName(), other.getName()) && return equalsIgnoreCase(getName(), other.getName()) &&
equalsIgnoreCase(getDomain(), other.getDomain()) && equalsIgnoreCase(getDomain(), other.getDomain()) &&
equals(getPath(), other.getPath()); Objects.equals(getPath(), other.getPath());
} }
...@@ -1162,14 +1163,6 @@ public final class HttpCookie implements Cloneable { ...@@ -1162,14 +1163,6 @@ public final class HttpCookie implements Cloneable {
return false; 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) { private static boolean startsWithIgnoreCase(String s, String start) {
if (s == null || start == null) return false; if (s == null || start == null) return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册